v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
builtins-json.cc
Go to the documentation of this file.
1// Copyright 2016 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
12
13namespace v8 {
14namespace internal {
15
16// ES6 section 24.3.1 JSON.parse.
17BUILTIN(JsonParse) {
18 HandleScope scope(isolate);
19 Handle<Object> source = args.atOrUndefined(isolate, 1);
20 Handle<Object> reviver = args.atOrUndefined(isolate, 2);
23 Object::ToString(isolate, source));
24 string = String::Flatten(isolate, string);
27 ? JsonParser<uint8_t>::Parse(isolate, string, reviver)
28 : JsonParser<uint16_t>::Parse(isolate, string, reviver));
29}
30
31// ES6 section 24.3.2 JSON.stringify.
33 HandleScope scope(isolate);
34 Handle<JSAny> object = Cast<JSAny>(args.atOrUndefined(isolate, 1));
35 Handle<JSAny> replacer = Cast<JSAny>(args.atOrUndefined(isolate, 2));
36 Handle<Object> indent = args.atOrUndefined(isolate, 3);
38 JsonStringify(isolate, object, replacer, indent));
39}
40
41// https://tc39.es/proposal-json-parse-with-source/#sec-json.rawjson
42BUILTIN(JsonRawJson) {
43 HandleScope scope(isolate);
44 Handle<Object> text = args.atOrUndefined(isolate, 1);
45 RETURN_RESULT_OR_FAILURE(isolate, JSRawJson::Create(isolate, text));
46}
47
48// https://tc39.es/proposal-json-parse-with-source/#sec-json.israwjson
49BUILTIN(JsonIsRawJson) {
50 HandleScope scope(isolate);
51 DirectHandle<Object> text = args.atOrUndefined(isolate, 1);
52 return isolate->heap()->ToBoolean(IsJSRawJson(*text));
53}
54
55} // namespace internal
56} // namespace v8
#define BUILTIN(name)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSRawJson > Create(Isolate *isolate, Handle< Object > text)
static V8_WARN_UNUSED_RESULT HandleType< String >::MaybeType ToString(Isolate *isolate, HandleType< T > input)
static V8_INLINE HandleType< String > Flatten(Isolate *isolate, HandleType< T > string, AllocationType allocation=AllocationType::kYoung)
static bool IsOneByteRepresentationUnderneath(Tagged< String > string)
Definition string-inl.h:373
#define ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, dst, call)
Definition isolate.h:284
#define RETURN_RESULT_OR_FAILURE(isolate, call)
Definition isolate.h:264
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
MaybeDirectHandle< Object > JsonStringify(Isolate *isolate, Handle< JSAny > object, Handle< JSAny > replacer, Handle< Object > gap)
template const char * string
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150