Debian Codegraph @

js/src/tests/test262/built-ins/Proxy/has/trap-is-null-target-is-proxy.js

raw
1 // Copyright (C) 2020 Alexey Shvayka. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-proxy-object-internal-methods-and-internal-slots-hasproperty-p
6 description: >
7 If "has" trap is null or undefined, [[HasProperty]] call is properly
8 forwarded to [[ProxyTarget]] (which is also a Proxy object).
9 info: |
10 [[HasProperty]] ( P )
11
12 [...]
13 5. Let target be O.[[ProxyTarget]].
14 6. Let trap be ? GetMethod(handler, "has").
15 7. If trap is undefined, then
16 a. Return ? target.[[HasProperty]](P).
17 features: [Proxy, Symbol, Reflect, Array.prototype.includes]
18 ---*/
19
20 var stringTarget = new Proxy(new String("str"), {});
21 var stringProxy = new Proxy(stringTarget, {
22 get: null,
23 });
24
25 assert(Reflect.has(stringProxy, "length"));
26 assert(0 in stringProxy);
27 assert(!(4 in stringProxy));
28
29
30 var sym = Symbol();
31 var target = new Proxy({}, {
32 has: function(_target, key) {
33 return [sym, "6", "foo"].includes(key);
34 },
35 });
36
37 var proxy = new Proxy(target, {
38 get: null,
39 });
40
41 assert(Reflect.has(proxy, sym));
42 assert("6" in proxy);
43 assert("foo" in Object.create(proxy));
44 assert(!("bar" in proxy));
45
46 reportCompare(0, 0);