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

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

Issue 11225026: Revert r12760 (JSON.stringify). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 2 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 | « src/runtime.cc ('k') | test/mjsunit/json-recursive.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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 assertEquals("[\n^1,\n^2,\n^3\n]", 250 assertEquals("[\n^1,\n^2,\n^3\n]",
251 JSON.stringify([1, 2, 3], null, new String("^"))); 251 JSON.stringify([1, 2, 3], null, new String("^")));
252 assertEquals("[\n 1,\n 2,\n [\n 3,\n [\n 4\n ],\n 5\n ],\n 6,\n 7\n]", 252 assertEquals("[\n 1,\n 2,\n [\n 3,\n [\n 4\n ],\n 5\n ],\n 6,\n 7\n]",
253 JSON.stringify([1, 2, [3, [4], 5], 6, 7], null, 1)); 253 JSON.stringify([1, 2, [3, [4], 5], 6, 7], null, 1));
254 assertEquals("[]", JSON.stringify([], null, 1)); 254 assertEquals("[]", JSON.stringify([], null, 1));
255 assertEquals("[1,2,[3,[4],5],6,7]", 255 assertEquals("[1,2,[3,[4],5],6,7]",
256 JSON.stringify([1, 2, [3, [4], 5], 6, 7], null)); 256 JSON.stringify([1, 2, [3, [4], 5], 6, 7], null));
257 assertEquals("[2,4,[6,[8],10],12,14]", 257 assertEquals("[2,4,[6,[8],10],12,14]",
258 JSON.stringify([1, 2, [3, [4], 5], 6, 7], DoubleNumbers)); 258 JSON.stringify([1, 2, [3, [4], 5], 6, 7], DoubleNumbers));
259 assertEquals('["a","ab","abc"]', JSON.stringify(["a","ab","abc"])); 259 assertEquals('["a","ab","abc"]', JSON.stringify(["a","ab","abc"]));
260 assertEquals('{"a":1,"c":true}',
261 JSON.stringify({ a : 1,
262 b : function() { 1 },
263 c : true,
264 d : function() { 2 } }));
265 assertEquals('[1,null,true,null]',
266 JSON.stringify([1, function() { 1 }, true, function() { 2 }]));
267 assertEquals('"toJSON 123"',
268 JSON.stringify({ toJSON : function() { return 'toJSON 123'; } }));
269 assertEquals('{"a":321}',
270 JSON.stringify({ a : { toJSON : function() { return 321; } } }));
271 var counter = 0;
272 assertEquals('{"getter":123}',
273 JSON.stringify({ get getter() { counter++; return 123; } }));
274 assertEquals(1, counter);
275 assertEquals('{"a":"abc","b":"\u1234bc"}',
276 JSON.stringify({ a : "abc", b : "\u1234bc" }));
277
278
279 var a = { a : 1, b : 2 };
280 delete a.a;
281 assertEquals('{"b":2}', JSON.stringify(a));
282
283 var b = {};
284 b.__proto__ = { toJSON : function() { return 321;} };
285 assertEquals("321", JSON.stringify(b));
286
287 var array = [""];
288 var expected = '""';
289 for (var i = 0; i < 10000; i++) {
290 array.push("");
291 expected = '"",' + expected;
292 }
293 expected = '[' + expected + ']';
294 assertEquals(expected, JSON.stringify(array));
295
296 260
297 var circular = [1, 2, 3]; 261 var circular = [1, 2, 3];
298 circular[2] = circular; 262 circular[2] = circular;
299 assertThrows(function () { JSON.stringify(circular); }, TypeError); 263 assertThrows(function () { JSON.stringify(circular); }, TypeError);
300 264
301 var singleton = []; 265 var singleton = [];
302 var multiOccurrence = [singleton, singleton, singleton]; 266 var multiOccurrence = [singleton, singleton, singleton];
303 assertEquals("[[],[],[]]", JSON.stringify(multiOccurrence)); 267 assertEquals("[[],[],[]]", JSON.stringify(multiOccurrence));
304 268
305 assertEquals('{"x":5,"y":6}', JSON.stringify({x:5,y:6})); 269 assertEquals('{"x":5,"y":6}', JSON.stringify({x:5,y:6}));
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 // objects in JSON.parse. Instead we read them as we would JS object 421 // objects in JSON.parse. Instead we read them as we would JS object
458 // literals. If we change that, this test should change with it. 422 // literals. If we change that, this test should change with it.
459 // 423 //
460 // Parse a non-object value as __proto__. This must not create a 424 // Parse a non-object value as __proto__. This must not create a
461 // __proto__ property different from the original, and should not 425 // __proto__ property different from the original, and should not
462 // change the original. 426 // change the original.
463 var o = JSON.parse('{"__proto__":5}'); 427 var o = JSON.parse('{"__proto__":5}');
464 assertEquals(Object.prototype, o.__proto__); // __proto__ isn't changed. 428 assertEquals(Object.prototype, o.__proto__); // __proto__ isn't changed.
465 assertEquals(0, Object.keys(o).length); // __proto__ isn't added as enumerable. 429 assertEquals(0, Object.keys(o).length); // __proto__ isn't added as enumerable.
466 430
467
468 var json = '{"stuff before slash\\\\stuff after slash":"whatever"}'; 431 var json = '{"stuff before slash\\\\stuff after slash":"whatever"}';
469 assertEquals(json, JSON.stringify(JSON.parse(json))); 432 assertEquals(json, JSON.stringify(JSON.parse(json)));
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/json-recursive.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698