| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 function Filter(key, value) { | 133 function Filter(key, value) { |
| 134 return (key == name) ? undefined : value; | 134 return (key == name) ? undefined : value; |
| 135 } | 135 } |
| 136 return Filter; | 136 return Filter; |
| 137 } | 137 } |
| 138 | 138 |
| 139 var pointJson = '{"x": 1, "y": 2}'; | 139 var pointJson = '{"x": 1, "y": 2}'; |
| 140 assertEquals({'x': 1, 'y': 2}, JSON.parse(pointJson)); | 140 assertEquals({'x': 1, 'y': 2}, JSON.parse(pointJson)); |
| 141 assertEquals({'x': 1}, JSON.parse(pointJson, GetFilter('y'))); | 141 assertEquals({'x': 1}, JSON.parse(pointJson, GetFilter('y'))); |
| 142 assertEquals({'y': 2}, JSON.parse(pointJson, GetFilter('x'))); | 142 assertEquals({'y': 2}, JSON.parse(pointJson, GetFilter('x'))); |
| 143 |
| 143 assertEquals([1, 2, 3], JSON.parse("[1, 2, 3]")); | 144 assertEquals([1, 2, 3], JSON.parse("[1, 2, 3]")); |
| 144 assertEquals([1, undefined, 3], JSON.parse("[1, 2, 3]", GetFilter(1))); | 145 |
| 145 assertEquals([1, 2, undefined], JSON.parse("[1, 2, 3]", GetFilter(2))); | 146 var array1 = JSON.parse("[1, 2, 3]", GetFilter(1)); |
| 147 assertEquals([1, , 3], array1); |
| 148 assertFalse(array1.hasOwnProperty(1)); // assertEquals above is not enough |
| 149 |
| 150 var array2 = JSON.parse("[1, 2, 3]", GetFilter(2)); |
| 151 assertEquals([1, 2, ,], array2); |
| 152 assertFalse(array2.hasOwnProperty(2)); |
| 146 | 153 |
| 147 function DoubleNumbers(key, value) { | 154 function DoubleNumbers(key, value) { |
| 148 return (typeof value == 'number') ? 2 * value : value; | 155 return (typeof value == 'number') ? 2 * value : value; |
| 149 } | 156 } |
| 150 | 157 |
| 151 var deepObject = '{"a": {"b": 1, "c": 2}, "d": {"e": {"f": 3}}}'; | 158 var deepObject = '{"a": {"b": 1, "c": 2}, "d": {"e": {"f": 3}}}'; |
| 152 assertEquals({"a": {"b": 1, "c": 2}, "d": {"e": {"f": 3}}}, | 159 assertEquals({"a": {"b": 1, "c": 2}, "d": {"e": {"f": 3}}}, |
| 153 JSON.parse(deepObject)); | 160 JSON.parse(deepObject)); |
| 154 assertEquals({"a": {"b": 2, "c": 4}, "d": {"e": {"f": 6}}}, | 161 assertEquals({"a": {"b": 2, "c": 4}, "d": {"e": {"f": 6}}}, |
| 155 JSON.parse(deepObject, DoubleNumbers)); | 162 JSON.parse(deepObject, DoubleNumbers)); |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 var o2 = JSON.parse('{"__proto__":5}'); | 482 var o2 = JSON.parse('{"__proto__":5}'); |
| 476 assertEquals(5, o2.__proto__); | 483 assertEquals(5, o2.__proto__); |
| 477 assertEquals(["__proto__"], Object.keys(o2)); | 484 assertEquals(["__proto__"], Object.keys(o2)); |
| 478 assertEquals(5, Object.getOwnPropertyDescriptor(o2, "__proto__").value); | 485 assertEquals(5, Object.getOwnPropertyDescriptor(o2, "__proto__").value); |
| 479 assertEquals(["__proto__"], Object.getOwnPropertyNames(o2)); | 486 assertEquals(["__proto__"], Object.getOwnPropertyNames(o2)); |
| 480 assertTrue(o2.hasOwnProperty("__proto__")); | 487 assertTrue(o2.hasOwnProperty("__proto__")); |
| 481 assertTrue(Object.prototype.isPrototypeOf(o2)); | 488 assertTrue(Object.prototype.isPrototypeOf(o2)); |
| 482 | 489 |
| 483 var json = '{"stuff before slash\\\\stuff after slash":"whatever"}'; | 490 var json = '{"stuff before slash\\\\stuff after slash":"whatever"}'; |
| 484 TestStringify(json, JSON.parse(json)); | 491 TestStringify(json, JSON.parse(json)); |
| OLD | NEW |