Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/JSON/parse/revived-proxy.js

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