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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/regress-3135.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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 gap = %_SubString(" ", 0, space); 203 gap = %_SubString(" ", 0, space);
204 } else if (IS_STRING(space)) { 204 } else if (IS_STRING(space)) {
205 if (space.length > 10) { 205 if (space.length > 10) {
206 gap = %_SubString(space, 0, 10); 206 gap = %_SubString(space, 0, 10);
207 } else { 207 } else {
208 gap = space; 208 gap = space;
209 } 209 }
210 } else { 210 } else {
211 gap = ""; 211 gap = "";
212 } 212 }
213 if (IS_ARRAY(replacer)) {
214 // Deduplicate replacer array items.
215 var property_list = new InternalArray();
216 var seen_properties = {};
217 var length = replacer.length;
218 for (var i = 0; i < length; i++) {
219 var item = replacer[i];
220 if (IS_NUMBER(item)) item = %_NumberToString(item);
221 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
222 property_list.push(item);
223 seen_properties[item] = true;
224 }
225 }
226 replacer = property_list;
227 }
213 return JSONSerialize('', {'': value}, replacer, new InternalArray(), "", gap); 228 return JSONSerialize('', {'': value}, replacer, new InternalArray(), "", gap);
214 } 229 }
215 230
216 231
217 // ------------------------------------------------------------------- 232 // -------------------------------------------------------------------
218 233
219 function SetUpJSON() { 234 function SetUpJSON() {
220 %CheckIsBootstrapping(); 235 %CheckIsBootstrapping();
221 236
222 // Set up non-enumerable properties of the JSON object. 237 // Set up non-enumerable properties of the JSON object.
223 InstallFunctions($JSON, DONT_ENUM, $Array( 238 InstallFunctions($JSON, DONT_ENUM, $Array(
224 "parse", JSONParse, 239 "parse", JSONParse,
225 "stringify", JSONStringify 240 "stringify", JSONStringify
226 )); 241 ));
227 } 242 }
228 243
229 SetUpJSON(); 244 SetUpJSON();
230 245
231 246
232 // ------------------------------------------------------------------- 247 // -------------------------------------------------------------------
233 // JSON Builtins 248 // JSON Builtins
234 249
235 function JSONSerializeAdapter(key, object) { 250 function JSONSerializeAdapter(key, object) {
236 var holder = {}; 251 var holder = {};
237 holder[key] = object; 252 holder[key] = object;
238 // No need to pass the actual holder since there is no replacer function. 253 // No need to pass the actual holder since there is no replacer function.
239 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); 254 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", "");
240 } 255 }
OLDNEW
« 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