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

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

Issue 5578004: Improved JSON stringify. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years 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 | « src/json.js ('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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 var singleton = []; 271 var singleton = [];
272 var multiOccurrence = [singleton, singleton, singleton]; 272 var multiOccurrence = [singleton, singleton, singleton];
273 assertEquals("[[],[],[]]", JSON.stringify(multiOccurrence)); 273 assertEquals("[[],[],[]]", JSON.stringify(multiOccurrence));
274 274
275 assertEquals('{"x":5,"y":6}', JSON.stringify({x:5,y:6})); 275 assertEquals('{"x":5,"y":6}', JSON.stringify({x:5,y:6}));
276 assertEquals('{"x":5}', JSON.stringify({x:5,y:6}, ['x'])); 276 assertEquals('{"x":5}', JSON.stringify({x:5,y:6}, ['x']));
277 assertEquals('{\n "a": "b",\n "c": "d"\n}', 277 assertEquals('{\n "a": "b",\n "c": "d"\n}',
278 JSON.stringify({a:"b",c:"d"}, null, 1)); 278 JSON.stringify({a:"b",c:"d"}, null, 1));
279 assertEquals('{"y":6,"x":5}', JSON.stringify({x:5,y:6}, ['y', 'x'])); 279 assertEquals('{"y":6,"x":5}', JSON.stringify({x:5,y:6}, ['y', 'x']));
280 280
281 // toJSON get string keys.
282 var checker = {};
283 var array = [checker];
284 checker.toJSON = function(key) { return 1 + key; };
285 assertEquals('["10"]', JSON.stringify(array));
286
281 // The gap is capped at ten characters if specified as string. 287 // The gap is capped at ten characters if specified as string.
282 assertEquals('{\n "a": "b",\n "c": "d"\n}', 288 assertEquals('{\n "a": "b",\n "c": "d"\n}',
283 JSON.stringify({a:"b",c:"d"}, null, 289 JSON.stringify({a:"b",c:"d"}, null,
284 " /*characters after 10th*/")); 290 " /*characters after 10th*/"));
285 291
286 //The gap is capped at ten characters if specified as number. 292 //The gap is capped at ten characters if specified as number.
287 assertEquals('{\n "a": "b",\n "c": "d"\n}', 293 assertEquals('{\n "a": "b",\n "c": "d"\n}',
288 JSON.stringify({a:"b",c:"d"}, null, 15)); 294 JSON.stringify({a:"b",c:"d"}, null, 15));
289 295
290 // Replaced wrapped primitives are unwrapped. 296 // Replaced wrapped primitives are unwrapped.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 if (i < 16) { 345 if (i < 16) {
340 expected = "\\u000" + i.toString(16); 346 expected = "\\u000" + i.toString(16);
341 } else { 347 } else {
342 expected = "\\u00" + i.toString(16); 348 expected = "\\u00" + i.toString(16);
343 } 349 }
344 } else { 350 } else {
345 expected = string; 351 expected = string;
346 } 352 }
347 assertEquals('"' + expected + '"', encoded, "Codepoint " + i); 353 assertEquals('"' + expected + '"', encoded, "Codepoint " + i);
348 } 354 }
OLDNEW
« no previous file with comments | « src/json.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698