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

Side by Side Diff: test/mjsunit/json.js

Issue 2740073002: [json] use OrderedHashSet for replacer property list. (Closed)
Patch Set: Created 3 years, 9 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 | « src/json-stringifier.cc ('k') | no next file » | 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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 320
321 var singleton = []; 321 var singleton = [];
322 var multiOccurrence = [singleton, singleton, singleton]; 322 var multiOccurrence = [singleton, singleton, singleton];
323 TestStringify("[[],[],[]]", multiOccurrence); 323 TestStringify("[[],[],[]]", multiOccurrence);
324 324
325 TestStringify('{"x":5,"y":6}', {x:5,y:6}); 325 TestStringify('{"x":5,"y":6}', {x:5,y:6});
326 assertEquals('{"x":5}', JSON.stringify({x:5,y:6}, ['x'])); 326 assertEquals('{"x":5}', JSON.stringify({x:5,y:6}, ['x']));
327 assertEquals('{\n "a": "b",\n "c": "d"\n}', 327 assertEquals('{\n "a": "b",\n "c": "d"\n}',
328 JSON.stringify({a:"b",c:"d"}, null, 1)); 328 JSON.stringify({a:"b",c:"d"}, null, 1));
329 assertEquals('{"y":6,"x":5}', JSON.stringify({x:5,y:6}, ['y', 'x'])); 329 assertEquals('{"y":6,"x":5}', JSON.stringify({x:5,y:6}, ['y', 'x']));
330 assertEquals('{"y":6,"x":5}', JSON.stringify({x:5,y:6}, ['y', 'x', 'x', 'y']));
330 331
331 // toJSON get string keys. 332 // toJSON get string keys.
332 var checker = {}; 333 var checker = {};
333 var array = [checker]; 334 var array = [checker];
334 checker.toJSON = function(key) { return 1 + key; }; 335 checker.toJSON = function(key) { return 1 + key; };
335 TestStringify('["10"]', array); 336 TestStringify('["10"]', array);
336 337
337 // The gap is capped at ten characters if specified as string. 338 // The gap is capped at ten characters if specified as string.
338 assertEquals('{\n "a": "b",\n "c": "d"\n}', 339 assertEquals('{\n "a": "b",\n "c": "d"\n}',
339 JSON.stringify({a:"b",c:"d"}, null, 340 JSON.stringify({a:"b",c:"d"}, null,
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 // Make sure a failed [[DefineProperty]] doesn't throw 517 // Make sure a failed [[DefineProperty]] doesn't throw
517 518
518 reviver = function(p, v) { 519 reviver = function(p, v) {
519 Object.freeze(this); 520 Object.freeze(this);
520 return p === "" ? v : 42; 521 return p === "" ? v : 42;
521 } 522 }
522 assertEquals({a: 0, b: 1}, JSON.parse('{"a":0,"b":1}', reviver)); 523 assertEquals({a: 0, b: 1}, JSON.parse('{"a":0,"b":1}', reviver));
523 524
524 reviver = (k, v) => (v === Infinity) ? "inf" : v; 525 reviver = (k, v) => (v === Infinity) ? "inf" : v;
525 assertEquals('{"":"inf"}', JSON.stringify({"":Infinity}, reviver)); 526 assertEquals('{"":"inf"}', JSON.stringify({"":Infinity}, reviver));
OLDNEW
« no previous file with comments | « src/json-stringifier.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698