revived-proxy.js (2108B)
1 // Copyright (C) 2016 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-json.parse 5 description: Behavior when revived value is a Proxy exotic object 6 info: | 7 [...] 8 7. If IsCallable(reviver) is true, then 9 a. Let root be ObjectCreate(%ObjectPrototype%). 10 b. Let rootName be the empty String. 11 c. Let status be CreateDataProperty(root, rootName, unfiltered). 12 d. Assert: status is true. 13 e. Return ? InternalizeJSONProperty(root, rootName). 14 15 24.3.1.1 Runtime Semantics: InternalizeJSONProperty 16 17 [...] 18 2. If Type(val) is Object, then 19 a. Let isArray be ? IsArray(val). 20 b. If isArray is true, then 21 [...] 22 c. Else, 23 [...] 24 25 7.2.2 IsArray 26 27 [...] 28 3. If argument is a Proxy exotic object, then 29 a. If the value of the [[ProxyHandler]] internal slot of argument is null, 30 throw a TypeError exception. 31 b. Let target be the value of the [[ProxyTarget]] internal slot of 32 argument. 33 c. Return ? IsArray(target). 34 features: [Proxy] 35 ---*/ 36 37 var objectProxy = new Proxy({ 38 length: 0, 39 other: 0 40 }, {}); 41 var arrayProxy = new Proxy([], {}); 42 var arrayProxyProxy = new Proxy(arrayProxy, {}); 43 var visitedOther, injectProxy; 44 45 arrayProxy.other = 0; 46 47 injectProxy = function(name, val) { 48 if (name === 'other') { 49 visitedOther = true; 50 } 51 this[1] = objectProxy; 52 return val; 53 }; 54 visitedOther = false; 55 56 JSON.parse('[null, null]', injectProxy); 57 58 assert.sameValue(visitedOther, true, 'proxy for ordinary object'); 59 60 injectProxy = function(name, val) { 61 if (name === 'other') { 62 visitedOther = true; 63 } 64 this[1] = arrayProxy; 65 return val; 66 }; 67 visitedOther = false; 68 69 JSON.parse('[null, null]', injectProxy); 70 71 assert.sameValue(visitedOther, false, 'proxy for array'); 72 73 injectProxy = function(name, val) { 74 if (name === 'other') { 75 visitedOther = true; 76 } 77 this[1] = arrayProxyProxy; 78 return val; 79 }; 80 visitedOther = false; 81 82 JSON.parse('[null, null]', injectProxy); 83 84 assert.sameValue(visitedOther, false, 'proxy for array proxy'); 85 86 reportCompare(0, 0);