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

Unified Diff: src/js/json.js

Issue 1922603006: [JSON] implement indentation in the BasicJsonStringifier and expose via API. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 4 years, 7 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/api.cc ('k') | src/json-stringifier.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/json.js
diff --git a/src/js/json.js b/src/js/json.js
index c6dbed9cbbf7f0923bc446387f6f9c7f700f8d27..09fe688ebb1dca2755bb11e83329a5b68c749517 100644
--- a/src/js/json.js
+++ b/src/js/json.js
@@ -202,7 +202,7 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) {
function JSONStringify(value, replacer, space) {
if (arguments.length === 1 && !IS_PROXY(value)) {
- return %BasicJSONStringify(value);
+ return %BasicJSONStringify(value, "");
}
if (!IS_CALLABLE(replacer) && %is_arraylike(replacer)) {
var property_list = new InternalArray();
@@ -248,8 +248,8 @@ function JSONStringify(value, replacer, space) {
} else {
gap = "";
}
- if (!IS_CALLABLE(replacer) && !property_list && !gap && !IS_PROXY(value)) {
- return %BasicJSONStringify(value);
+ if (!IS_CALLABLE(replacer) && !property_list && !IS_PROXY(value)) {
+ return %BasicJSONStringify(value, gap);
}
return JSONSerialize('', {'': value}, replacer, new Stack(), "", gap);
}
@@ -285,11 +285,14 @@ utils.InstallFunctions(GlobalDate.prototype, DONT_ENUM, [
// -------------------------------------------------------------------
// JSON Builtins
-function JsonSerializeAdapter(key, object) {
+function JsonSerializeAdapter(key, object, indent, gap) {
var holder = {};
holder[key] = object;
// No need to pass the actual holder since there is no replacer function.
- return JSONSerialize(key, holder, UNDEFINED, new Stack(), "", "");
+ var current_indent = "";
+ for (var i = 0; i < indent; i++) current_indent += gap;
+ return JSONSerialize(
+ key, holder, UNDEFINED, new Stack(), current_indent, gap);
}
%InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]);
« no previous file with comments | « src/api.cc ('k') | src/json-stringifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698