Line data Source code
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 :
5 : #include "src/builtins/builtins-utils-inl.h"
6 : #include "src/builtins/builtins.h"
7 : #include "src/counters.h"
8 : #include "src/json-parser.h"
9 : #include "src/json-stringifier.h"
10 : #include "src/objects-inl.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 :
15 : // ES6 section 24.3.1 JSON.parse.
16 2679360 : BUILTIN(JsonParse) {
17 : HandleScope scope(isolate);
18 535872 : Handle<Object> source = args.atOrUndefined(isolate, 1);
19 535872 : Handle<Object> reviver = args.atOrUndefined(isolate, 2);
20 : Handle<String> string;
21 1071744 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, string,
22 : Object::ToString(isolate, source));
23 535872 : string = String::Flatten(isolate, string);
24 1072418 : RETURN_RESULT_OR_FAILURE(
25 : isolate, string->IsSeqOneByteString()
26 : ? JsonParser<true>::Parse(isolate, string, reviver)
27 : : JsonParser<false>::Parse(isolate, string, reviver));
28 : }
29 :
30 : // ES6 section 24.3.2 JSON.stringify.
31 5630085 : BUILTIN(JsonStringify) {
32 : HandleScope scope(isolate);
33 1126017 : Handle<Object> object = args.atOrUndefined(isolate, 1);
34 1126017 : Handle<Object> replacer = args.atOrUndefined(isolate, 2);
35 1126017 : Handle<Object> indent = args.atOrUndefined(isolate, 3);
36 2252342 : RETURN_RESULT_OR_FAILURE(isolate,
37 : JsonStringify(isolate, object, replacer, indent));
38 : }
39 :
40 : } // namespace internal
41 121996 : } // namespace v8
|