Debian Codegraph @

js/src/jit-test/tests/proxy/testDirectProxyGet3.js

raw
1 load(libdir + "asserts.js");
2
3 function testProxy(handlerReturn, prop, shouldThrow) {
4 var handler = { get: function () { return handlerReturn; } };
5 for (let p of [new Proxy(target, handler), Proxy.revocable(target, handler).proxy]) {
6 if (shouldThrow)
7 assertThrowsInstanceOf(function () { return p[prop]; }, TypeError);
8 else
9 assertEq(p[prop], handlerReturn);
10 }
11 }
12
13 /*
14 * Throw a TypeError if the trap reports a different value for a non-writable,
15 * non-configurable property
16 */
17 var target = {};
18 Object.defineProperty(target, 'foo', {
19 value: 'bar',
20 writable: false,
21 configurable: false
22 });
23 testProxy('baz', 'foo', true);
24 /*
25 * Don't throw a TypeError if the trap reports the same value for a non-writable,
26 * non-configurable property
27 */
28 testProxy('bar', 'foo', false);
29
30 /*
31 * Don't throw a TypeError if the trap reports a different value for a writable,
32 * non-configurable property
33 */
34 Object.defineProperty(target, 'prop', {
35 value: 'bar',
36 writable: true,
37 configurable: false
38 });
39 testProxy('baz', 'prop', false);
40
41 /*
42 * Don't throw a TypeError if the trap reports a different value for a non-writable,
43 * configurable property
44 */
45 Object.defineProperty(target, 'prop2', {
46 value: 'bar',
47 writable: false,
48 configurable: true
49 });
50 testProxy('baz', 'prop2', false);