Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Unified Diff: src/builtins/builtins-json.cc

Issue 2165593002: [builtins] Move builtins into own files (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove builtins-error.cc from BUILD.gn Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/builtins/builtins-internal.cc ('k') | src/builtins/builtins-math.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-json.cc
diff --git a/src/builtins/builtins-json.cc b/src/builtins/builtins-json.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4a8c7c5ea80cf3c802f1fda79f663e3f76e43015
--- /dev/null
+++ b/src/builtins/builtins-json.cc
@@ -0,0 +1,41 @@
+// Copyright 2016 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/builtins/builtins.h"
+#include "src/builtins/builtins-utils.h"
+
+#include "src/json-parser.h"
+#include "src/json-stringifier.h"
+
+namespace v8 {
+namespace internal {
+
+// ES6 section 24.3.1 JSON.parse.
+BUILTIN(JsonParse) {
+ HandleScope scope(isolate);
+ Handle<Object> source = args.atOrUndefined(isolate, 1);
+ Handle<Object> reviver = args.atOrUndefined(isolate, 2);
+ Handle<String> string;
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, string,
+ Object::ToString(isolate, source));
+ string = String::Flatten(string);
+ RETURN_RESULT_OR_FAILURE(
+ isolate, string->IsSeqOneByteString()
+ ? JsonParser<true>::Parse(isolate, string, reviver)
+ : JsonParser<false>::Parse(isolate, string, reviver));
+}
+
+// ES6 section 24.3.2 JSON.stringify.
+BUILTIN(JsonStringify) {
+ HandleScope scope(isolate);
+ JsonStringifier stringifier(isolate);
+ Handle<Object> object = args.atOrUndefined(isolate, 1);
+ Handle<Object> replacer = args.atOrUndefined(isolate, 2);
+ Handle<Object> indent = args.atOrUndefined(isolate, 3);
+ RETURN_RESULT_OR_FAILURE(isolate,
+ stringifier.Stringify(object, replacer, indent));
+}
+
+} // namespace internal
+} // namespace v8
« no previous file with comments | « src/builtins/builtins-internal.cc ('k') | src/builtins/builtins-math.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698