| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 n3.toISOString = function () { return {}; }; | 78 n3.toISOString = function () { return {}; }; |
| 79 assertThrows(function () { n3.toJSON(); }, TypeError, "result_not_primitive"); | 79 assertThrows(function () { n3.toJSON(); }, TypeError, "result_not_primitive"); |
| 80 var n4 = new Date(10003); | 80 var n4 = new Date(10003); |
| 81 n4.toISOString = function () { | 81 n4.toISOString = function () { |
| 82 assertEquals(0, arguments.length); | 82 assertEquals(0, arguments.length); |
| 83 assertEquals(this, n4); | 83 assertEquals(this, n4); |
| 84 return null; | 84 return null; |
| 85 }; | 85 }; |
| 86 assertEquals(null, n4.toJSON()); | 86 assertEquals(null, n4.toJSON()); |
| 87 | 87 |
| 88 assertEquals(Object.prototype, JSON.__proto__); | 88 assertTrue(Object.prototype === JSON.__proto__); |
| 89 assertEquals("[object JSON]", Object.prototype.toString.call(JSON)); | 89 assertEquals("[object JSON]", Object.prototype.toString.call(JSON)); |
| 90 | 90 |
| 91 // DontEnum | 91 // DontEnum |
| 92 for (var p in this) | 92 for (var p in this) |
| 93 assertFalse(p == "JSON"); | 93 assertFalse(p == "JSON"); |
| 94 | 94 |
| 95 // Parse | 95 // Parse |
| 96 assertEquals({}, JSON.parse("{}")); | 96 assertEquals({}, JSON.parse("{}")); |
| 97 assertEquals({42:37}, JSON.parse('{"42":37}')); | 97 assertEquals({42:37}, JSON.parse('{"42":37}')); |
| 98 assertEquals(null, JSON.parse("null")); | 98 assertEquals(null, JSON.parse("null")); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 JSON.stringify({a: undefined, b: function(){}, c: 42, d: 42}, | 306 JSON.stringify({a: undefined, b: function(){}, c: 42, d: 42}, |
| 307 function(k, v) { if (k == "c") return undefined; | 307 function(k, v) { if (k == "c") return undefined; |
| 308 if (k == "d") return function(){}; | 308 if (k == "d") return function(){}; |
| 309 return v; })); | 309 return v; })); |
| 310 | 310 |
| 311 TestInvalid('1); throw "foo"; (1'); | 311 TestInvalid('1); throw "foo"; (1'); |
| 312 | 312 |
| 313 var x = 0; | 313 var x = 0; |
| 314 eval("(1); x++; (1)"); | 314 eval("(1); x++; (1)"); |
| 315 TestInvalid('1); x++; (1'); | 315 TestInvalid('1); x++; (1'); |
| 316 |
| 317 // Test string conversion of argument. |
| 318 var o = { toString: function() { return "42"; } }; |
| 319 assertEquals(42, JSON.parse(o)); |
| OLD | NEW |