Debian Codegraph @

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

raw
1 load(libdir + "asserts.js");
2
3 // Test for various properties demanded of Proxy.revocable
4 var holder = Proxy.revocable({}, {});
5
6 // The returned object must inherit from Object.prototype
7 assertEq(Object.getPrototypeOf(holder), Object.prototype);
8
9 assertDeepEq(Object.getOwnPropertyNames(holder), [ 'proxy', 'revoke' ]);
10
11 // The revocation function must inherit from Function.prototype
12 assertEq(Object.getPrototypeOf(holder.revoke), Function.prototype);
13
14 // Proxy.revoke should return unique objects from the same opcode call.
15 var proxyLog = []
16 var revokerLog = []
17 var holderLog = []
18
19 function addUnique(l, v)
20 {
21 assertEq(l.indexOf(v), -1);
22 l.push(v);
23 }
24
25 for (let i = 0; i < 5; i++) {
26 holder = Proxy.revocable({}, {});
27 addUnique(holderLog, holder);
28 addUnique(revokerLog, holder.revoke);
29 addUnique(proxyLog, holder.proxy);
30 }
31
32 // The provided revoke function should revoke only the 1 proxy
33 var p = proxyLog.pop();
34 var r = revokerLog.pop();
35
36 // Works before, but not after. This is mostly a token. There are
37 // testDirectProxy* tests to check each trap revokes properly.
38 p.foo;
39 assertEq(r(), undefined, "Revoke trap must return undefined");
40 assertThrowsInstanceOf(() => p.foo, TypeError);
41 assertEq(r(), undefined, "Revoke trap must return undefined");
42
43 // None of this should throw, since these proxies are unrevoked.
44 for (let i = 0; i < proxyLog.length; i++)
45 proxyLog[i].foo;