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

Unified Diff: src/js/json.js

Issue 2004413002: [json] support property list argument in BasicJsonStringifier. (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 e2f7646f21e7309b3e0daf918b45f48dd9cb08e9..eee56afae05c20d8e88e20e23f8e59234520f6e9 100644
--- a/src/js/json.js
+++ b/src/js/json.js
@@ -121,29 +121,15 @@ function SerializeObject(value, replacer, stack, indent, gap) {
var stepback = indent;
indent += gap;
var partial = new InternalArray();
- if (IS_ARRAY(replacer)) {
- var length = replacer.length;
- for (var i = 0; i < length; i++) {
- var p = replacer[i];
- var strP = JSONSerialize(p, value, replacer, stack, indent, gap);
- if (!IS_UNDEFINED(strP)) {
- var member = %QuoteJSONString(p) + ":";
- if (gap != "") member += " ";
- member += strP;
- partial.push(member);
- }
- }
- } else {
- var keys = %object_keys(value);
- for (var i = 0; i < keys.length; i++) {
- var p = keys[i];
- var strP = JSONSerialize(p, value, replacer, stack, indent, gap);
- if (!IS_UNDEFINED(strP)) {
- var member = %QuoteJSONString(p) + ":";
- if (gap != "") member += " ";
- member += strP;
- partial.push(member);
- }
+ var keys = %object_keys(value);
+ for (var i = 0; i < keys.length; i++) {
+ var p = keys[i];
+ var strP = JSONSerialize(p, value, replacer, stack, indent, gap);
+ if (!IS_UNDEFINED(strP)) {
+ var member = %QuoteJSONString(p) + ":";
+ if (gap != "") member += " ";
+ member += strP;
+ partial.push(member);
}
}
var final;
@@ -201,29 +187,9 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) {
function JSONStringify(value, replacer, space) {
- if (arguments.length === 1) return %BasicJSONStringify(value, "");
- if (!IS_CALLABLE(replacer) && %is_arraylike(replacer)) {
- var property_list = new InternalArray();
- var seen_properties = new GlobalSet();
- var length = TO_LENGTH(replacer.length);
- for (var i = 0; i < length; i++) {
- var v = replacer[i];
- var item;
- if (IS_STRING(v)) {
- item = v;
- } else if (IS_NUMBER(v)) {
- item = %_NumberToString(v);
- } else if (IS_STRING_WRAPPER(v) || IS_NUMBER_WRAPPER(v)) {
- item = TO_STRING(v);
- } else {
- continue;
- }
- if (!seen_properties.has(item)) {
- property_list.push(item);
- seen_properties.add(item);
- }
- }
- replacer = property_list;
+ if (arguments.length === 1) return %BasicJSONStringify(value, UNDEFINED, "");
+ if (!IS_CALLABLE(replacer)) {
+ return %BasicJSONStringify(value, replacer, space);
}
if (IS_OBJECT(space)) {
// Unwrap 'space' if it is wrapped
@@ -233,9 +199,6 @@ function JSONStringify(value, replacer, space) {
space = TO_STRING(space);
}
}
- if (!IS_CALLABLE(replacer) && !property_list) {
- return %BasicJSONStringify(value, space);
- }
var gap;
if (IS_NUMBER(space)) {
space = MaxSimple(0, MinSimple(TO_INTEGER(space), 10));
« 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