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

Side by Side Diff: src/json.js

Issue 1207013002: JSON.stringify should use toString of replacer and not valueOf (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Align better with spec algorithm Created 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/json-replacer-number-wrapper-tostring.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var $jsonSerializeAdapter; 5 var $jsonSerializeAdapter;
6 6
7 (function(global, utils) { 7 (function(global, utils) {
8 8
9 "use strict"; 9 "use strict";
10 10
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } else { 201 } else {
202 gap = space; 202 gap = space;
203 } 203 }
204 } else { 204 } else {
205 gap = ""; 205 gap = "";
206 } 206 }
207 if (IS_ARRAY(replacer)) { 207 if (IS_ARRAY(replacer)) {
208 // Deduplicate replacer array items. 208 // Deduplicate replacer array items.
209 var property_list = new InternalArray(); 209 var property_list = new InternalArray();
210 var seen_properties = { __proto__: null }; 210 var seen_properties = { __proto__: null };
211 var seen_sentinel = {};
212 var length = replacer.length; 211 var length = replacer.length;
213 for (var i = 0; i < length; i++) { 212 for (var i = 0; i < length; i++) {
214 var item = replacer[i]; 213 var v = replacer[i];
215 if (IS_STRING_WRAPPER(item)) { 214 var item;
216 item = $toString(item); 215 if (IS_STRING(v)) {
216 item = v;
217 } else if (IS_NUMBER(v)) {
218 item = %_NumberToString(v);
219 } else if (IS_STRING_WRAPPER(v) || IS_NUMBER_WRAPPER(v)) {
220 item = $toString(v);
217 } else { 221 } else {
218 if (IS_NUMBER_WRAPPER(item)) item = $toNumber(item); 222 continue;
219 if (IS_NUMBER(item)) item = %_NumberToString(item);
220 } 223 }
221 if (IS_STRING(item) && seen_properties[item] != seen_sentinel) { 224 if (!seen_properties[item]) {
222 property_list.push(item); 225 property_list.push(item);
223 // We cannot use true here because __proto__ needs to be an object. 226 seen_properties[item] = true;
arv (Not doing code reviews) 2015/06/24 20:57:57 This comment does not apply now that __proto__ is
224 seen_properties[item] = seen_sentinel;
225 } 227 }
226 } 228 }
227 replacer = property_list; 229 replacer = property_list;
228 } 230 }
229 return JSONSerialize('', {'': value}, replacer, new InternalArray(), "", gap); 231 return JSONSerialize('', {'': value}, replacer, new InternalArray(), "", gap);
230 } 232 }
231 233
232 // ------------------------------------------------------------------- 234 // -------------------------------------------------------------------
233 235
234 %AddNamedProperty(GlobalJSON, symbolToStringTag, "JSON", READ_ONLY | DONT_ENUM); 236 %AddNamedProperty(GlobalJSON, symbolToStringTag, "JSON", READ_ONLY | DONT_ENUM);
235 237
236 // Set up non-enumerable properties of the JSON object. 238 // Set up non-enumerable properties of the JSON object.
237 utils.InstallFunctions(GlobalJSON, DONT_ENUM, [ 239 utils.InstallFunctions(GlobalJSON, DONT_ENUM, [
238 "parse", JSONParse, 240 "parse", JSONParse,
239 "stringify", JSONStringify 241 "stringify", JSONStringify
240 ]); 242 ]);
241 243
242 // ------------------------------------------------------------------- 244 // -------------------------------------------------------------------
243 // JSON Builtins 245 // JSON Builtins
244 246
245 $jsonSerializeAdapter = function(key, object) { 247 $jsonSerializeAdapter = function(key, object) {
246 var holder = {}; 248 var holder = {};
247 holder[key] = object; 249 holder[key] = object;
248 // No need to pass the actual holder since there is no replacer function. 250 // No need to pass the actual holder since there is no replacer function.
249 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); 251 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", "");
250 } 252 }
251 253
252 }) 254 })
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/json-replacer-number-wrapper-tostring.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698