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

Unified Diff: src/json.js

Issue 146623009: Fix spec violations in JSON.stringify wrt replacer array. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 6 years, 10 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 | « no previous file | test/mjsunit/regress-3135.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/json.js
diff --git a/src/json.js b/src/json.js
index c21e6351d45a345ca887ef1ed3ac3a7b811f3fbf..0799deadfe957f9bf598cbfc3006d25eb60e6a2b 100644
--- a/src/json.js
+++ b/src/json.js
@@ -210,6 +210,21 @@ function JSONStringify(value, replacer, space) {
} else {
gap = "";
}
+ if (IS_ARRAY(replacer)) {
+ // Deduplicate replacer array items.
+ var property_list = new InternalArray();
+ var seen_properties = {};
+ var length = replacer.length;
+ for (var i = 0; i < length; i++) {
+ var item = replacer[i];
+ if (IS_NUMBER(item)) item = %_NumberToString(item);
+ if (IS_STRING(item) && !(item in seen_properties)) {
arv (Not doing code reviews) 2014/03/04 19:54:54 Is this correct? What about the overlapping proper
arv (Not doing code reviews) 2014/03/04 20:04:23 We are not handling IS_OBJECT correctly here. htt
+ property_list.push(item);
+ seen_properties[item] = true;
+ }
+ }
+ replacer = property_list;
+ }
return JSONSerialize('', {'': value}, replacer, new InternalArray(), "", gap);
}
« no previous file with comments | « no previous file | test/mjsunit/regress-3135.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698