// Copyright 2022 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "src/objects/js-raw-json.h" #include "src/execution/isolate.h" #include "src/heap/factory.h" #include "src/json/json-parser.h" #include "src/objects/js-raw-json-inl.h" #include "src/objects/string-inl.h" namespace v8 { namespace internal { // https://tc39.es/proposal-json-parse-with-source/#sec-json.rawjson MaybeHandle JSRawJson::Create(Isolate* isolate, Handle text) { DCHECK(v8_flags.harmony_json_parse_with_source); Handle json_string; ASSIGN_RETURN_ON_EXCEPTION(isolate, json_string, Object::ToString(isolate, text), JSRawJson); if (String::IsOneByteRepresentationUnderneath(*json_string)) { if (!JsonParser::CheckRawJson(isolate, json_string)) { DCHECK(isolate->has_pending_exception()); return MaybeHandle(); } } else { if (!JsonParser::CheckRawJson(isolate, json_string)) { DCHECK(isolate->has_pending_exception()); return MaybeHandle(); } } Handle result = isolate->factory()->NewJSObjectFromMap(isolate->js_raw_json_map()); result->InObjectPropertyAtPut(JSRawJson::kRawJsonIndex, *json_string); JSObject::SetIntegrityLevel(result, FROZEN, kThrowOnError).Check(); return Handle::cast(result); } } // namespace internal } // namespace v8