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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 oddball2.__proto__ = { __proto__: null, | 446 oddball2.__proto__ = { __proto__: null, |
447 toJSON: function () { return oddball3; } } | 447 toJSON: function () { return oddball3; } } |
448 assertEquals('"true"', JSON.stringify(oddball2)); | 448 assertEquals('"true"', JSON.stringify(oddball2)); |
449 | 449 |
450 | 450 |
451 var falseNum = Object("37"); | 451 var falseNum = Object("37"); |
452 falseNum.__proto__ = Number.prototype; | 452 falseNum.__proto__ = Number.prototype; |
453 falseNum.toString = function() { return 42; }; | 453 falseNum.toString = function() { return 42; }; |
454 assertEquals('"42"', JSON.stringify(falseNum)); | 454 assertEquals('"42"', JSON.stringify(falseNum)); |
455 | 455 |
456 // We don't currently allow plain properties called __proto__ in JSON | 456 // Parse an object value as __proto__. |
457 // objects in JSON.parse. Instead we read them as we would JS object | 457 var o1 = JSON.parse('{"__proto__":[]}'); |
458 // literals. If we change that, this test should change with it. | 458 assertEquals([], o1.__proto__); |
459 // | 459 assertEquals(["__proto__"], Object.keys(o1)); |
460 // Parse a non-object value as __proto__. This must not create a | 460 assertEquals([], Object.getOwnPropertyDescriptor(o1, "__proto__").value); |
461 // __proto__ property different from the original, and should not | 461 assertEquals(["__proto__"], Object.getOwnPropertyNames(o1)); |
462 // change the original. | 462 assertTrue(o1.hasOwnProperty("__proto__")); |
463 var o = JSON.parse('{"__proto__":5}'); | 463 assertTrue(Object.prototype.isPrototypeOf(o1)); |
464 assertEquals(Object.prototype, o.__proto__); // __proto__ isn't changed. | 464 |
465 assertEquals(0, Object.keys(o).length); // __proto__ isn't added as enumerable. | 465 // Parse a non-object value as __proto__. |
| 466 var o2 = JSON.parse('{"__proto__":5}'); |
| 467 assertEquals(5, o2.__proto__); |
| 468 assertEquals(["__proto__"], Object.keys(o2)); |
| 469 assertEquals(5, Object.getOwnPropertyDescriptor(o2, "__proto__").value); |
| 470 assertEquals(["__proto__"], Object.getOwnPropertyNames(o2)); |
| 471 assertTrue(o2.hasOwnProperty("__proto__")); |
| 472 assertTrue(Object.prototype.isPrototypeOf(o2)); |
466 | 473 |
467 var json = '{"stuff before slash\\\\stuff after slash":"whatever"}'; | 474 var json = '{"stuff before slash\\\\stuff after slash":"whatever"}'; |
468 assertEquals(json, JSON.stringify(JSON.parse(json))); | 475 assertEquals(json, JSON.stringify(JSON.parse(json))); |
OLD | NEW |