| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 | 29 |
| 30 /////////////////////////////////////////////////////////////////////////////// | 30 /////////////////////////////////////////////////////////////////////////////// |
| 31 // JSON.stringify | 31 // JSON.stringify |
| 32 | 32 |
| 33 | 33 |
| 34 function testStringify(expected, object) { | 34 function testStringify(expected, object) { |
| 35 // Test fast case that bails out to slow case. | 35 // Test fast case that bails out to slow case. |
| 36 assertEquals(expected, JSON.stringify(object)); | 36 assertEquals(expected, JSON.stringify(object)); |
| 37 // Test slow case. | 37 // Test slow case. |
| 38 assertEquals(expected, JSON.stringify(object, undefined, 0)); | 38 assertEquals(expected, JSON.stringify(object, (key, value) => value)); |
| 39 // Test gap. |
| 40 assertEquals(JSON.stringify(object, null, "="), |
| 41 JSON.stringify(object, (key, value) => value, "=")); |
| 39 } | 42 } |
| 40 | 43 |
| 41 | 44 |
| 42 // Test serializing a proxy, a function proxy, and objects that contain them. | 45 // Test serializing a proxy, a function proxy, and objects that contain them. |
| 43 | 46 |
| 44 var handler1 = { | 47 var handler1 = { |
| 45 get: function(target, name) { | 48 get: function(target, name) { |
| 46 return name.toUpperCase(); | 49 return name.toUpperCase(); |
| 47 }, | 50 }, |
| 48 ownKeys: function() { | 51 ownKeys: function() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 60 assertTrue(typeof(proxy_fun) === 'function'); | 63 assertTrue(typeof(proxy_fun) === 'function'); |
| 61 testStringify(undefined, proxy_fun); | 64 testStringify(undefined, proxy_fun); |
| 62 testStringify('[1,null]', [1, proxy_fun]); | 65 testStringify('[1,null]', [1, proxy_fun]); |
| 63 | 66 |
| 64 handler1.apply = function() { return 666; }; | 67 handler1.apply = function() { return 666; }; |
| 65 testStringify(undefined, proxy_fun); | 68 testStringify(undefined, proxy_fun); |
| 66 testStringify('[1,null]', [1, proxy_fun]); | 69 testStringify('[1,null]', [1, proxy_fun]); |
| 67 | 70 |
| 68 var parent1a = { b: proxy1 }; | 71 var parent1a = { b: proxy1 }; |
| 69 testStringify('{"b":{"a":"A","b":"B","c":"C"}}', parent1a); | 72 testStringify('{"b":{"a":"A","b":"B","c":"C"}}', parent1a); |
| 73 testStringify('{"b":{"a":"A","b":"B","c":"C"}}', parent1a); |
| 70 | 74 |
| 71 var parent1b = { a: 123, b: proxy1, c: true }; | 75 var parent1b = { a: 123, b: proxy1, c: true }; |
| 72 testStringify('{"a":123,"b":{"a":"A","b":"B","c":"C"},"c":true}', parent1b); | 76 testStringify('{"a":123,"b":{"a":"A","b":"B","c":"C"},"c":true}', parent1b); |
| 73 | 77 |
| 74 var parent1c = [123, proxy1, true]; | 78 var parent1c = [123, proxy1, true]; |
| 75 testStringify('[123,{"a":"A","b":"B","c":"C"},true]', parent1c); | 79 testStringify('[123,{"a":"A","b":"B","c":"C"},true]', parent1c); |
| 76 | 80 |
| 77 | 81 |
| 78 // Proxy with side effect. | 82 // Proxy with side effect. |
| 79 | 83 |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 | 500 |
| 497 var result = JSON.parse('{"foo":0,"bar":1}', reviver); | 501 var result = JSON.parse('{"foo":0,"bar":1}', reviver); |
| 498 assertEquals({foo: 0, bar: proxy}, result); | 502 assertEquals({foo: 0, bar: proxy}, result); |
| 499 assertSame(result.bar, proxy); | 503 assertSame(result.bar, proxy); |
| 500 assertEquals(3, log.length); | 504 assertEquals(3, log.length); |
| 501 for (var i in log) assertSame(target, log[i][1]); | 505 for (var i in log) assertSame(target, log[i][1]); |
| 502 | 506 |
| 503 assertEquals(["get", target, "length", proxy], log[0]); | 507 assertEquals(["get", target, "length", proxy], log[0]); |
| 504 assertEquals(["get", target, "0", proxy], log[1]); | 508 assertEquals(["get", target, "0", proxy], log[1]); |
| 505 assertEquals(["deleteProperty", target, "0"], log[2]); | 509 assertEquals(["deleteProperty", target, "0"], log[2]); |
| OLD | NEW |