OLD | NEW |
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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 JSON.stringify({ a : 1, | 261 JSON.stringify({ a : 1, |
262 b : function() { 1 }, | 262 b : function() { 1 }, |
263 c : true, | 263 c : true, |
264 d : function() { 2 } })); | 264 d : function() { 2 } })); |
265 assertEquals('[1,null,true,null]', | 265 assertEquals('[1,null,true,null]', |
266 JSON.stringify([1, function() { 1 }, true, function() { 2 }])); | 266 JSON.stringify([1, function() { 1 }, true, function() { 2 }])); |
267 assertEquals('"toJSON 123"', | 267 assertEquals('"toJSON 123"', |
268 JSON.stringify({ toJSON : function() { return 'toJSON 123'; } })); | 268 JSON.stringify({ toJSON : function() { return 'toJSON 123'; } })); |
269 assertEquals('{"a":321}', | 269 assertEquals('{"a":321}', |
270 JSON.stringify({ a : { toJSON : function() { return 321; } } })); | 270 JSON.stringify({ a : { toJSON : function() { return 321; } } })); |
| 271 var counter = 0; |
271 assertEquals('{"getter":123}', | 272 assertEquals('{"getter":123}', |
272 JSON.stringify({ get getter() { return 123; } })); | 273 JSON.stringify({ get getter() { counter++; return 123; } })); |
| 274 assertEquals(1, counter); |
273 assertEquals('{"a":"abc","b":"\u1234bc"}', | 275 assertEquals('{"a":"abc","b":"\u1234bc"}', |
274 JSON.stringify({ a : "abc", b : "\u1234bc" })); | 276 JSON.stringify({ a : "abc", b : "\u1234bc" })); |
275 | 277 |
| 278 |
276 var a = { a : 1, b : 2 }; | 279 var a = { a : 1, b : 2 }; |
277 delete a.a; | 280 delete a.a; |
278 assertEquals('{"b":2}', JSON.stringify(a)); | 281 assertEquals('{"b":2}', JSON.stringify(a)); |
279 | 282 |
280 var b = {}; | 283 var b = {}; |
281 b.__proto__ = { toJSON : function() { return 321;} }; | 284 b.__proto__ = { toJSON : function() { return 321;} }; |
282 assertEquals("321", JSON.stringify(b)); | 285 assertEquals("321", JSON.stringify(b)); |
283 | 286 |
284 var array = [""]; | 287 var array = [""]; |
285 var expected = '""'; | 288 var expected = '""'; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 // Parse a non-object value as __proto__. This must not create a | 460 // Parse a non-object value as __proto__. This must not create a |
458 // __proto__ property different from the original, and should not | 461 // __proto__ property different from the original, and should not |
459 // change the original. | 462 // change the original. |
460 var o = JSON.parse('{"__proto__":5}'); | 463 var o = JSON.parse('{"__proto__":5}'); |
461 assertEquals(Object.prototype, o.__proto__); // __proto__ isn't changed. | 464 assertEquals(Object.prototype, o.__proto__); // __proto__ isn't changed. |
462 assertEquals(0, Object.keys(o).length); // __proto__ isn't added as enumerable. | 465 assertEquals(0, Object.keys(o).length); // __proto__ isn't added as enumerable. |
463 | 466 |
464 | 467 |
465 var json = '{"stuff before slash\\\\stuff after slash":"whatever"}'; | 468 var json = '{"stuff before slash\\\\stuff after slash":"whatever"}'; |
466 assertEquals(json, JSON.stringify(JSON.parse(json))); | 469 assertEquals(json, JSON.stringify(JSON.parse(json))); |
OLD | NEW |