Debian Codegraph @

js/src/tests/non262/Function/get-function-realm.js

raw
1 // SKIP test262 export
2 // Pending review.
3
4 var g1 = newGlobal();
5 var g1Fun = g1.eval("function Fun() {}; Fun");
6
7 // Bound function => cross-realm function.
8 var bound1 = Function.prototype.bind.call(g1Fun);
9 assertEq(Object.getPrototypeOf(new bound1()), g1.Fun.prototype);
10
11 // Proxy => cross-realm function.
12 var proxy1 = new Proxy(g1Fun, {
13 get: function() {} // Ensure "prototype" is |undefined|.
14 });
15 assertEq(Object.getPrototypeOf(new proxy1()), g1.Object.prototype);
16
17 // Proxy => bound function => cross-realm function.
18 var proxy2 = new Proxy(bound1, {
19 get: function() {}
20 });
21 assertEq(Object.getPrototypeOf(new proxy2()), g1.Object.prototype);
22
23 // Revoked proxy => cross-realm function.
24 var r1 = Proxy.revocable(g1Fun, {
25 get: function(t, name) {
26 assertEq(name, "prototype");
27 r1.revoke();
28 }
29 });
30 assertThrowsInstanceOf(() => new r1.proxy(), g1.TypeError);
31
32 // Bound function => proxy => bound function => cross-realm function.
33 var bound2 = Function.prototype.bind.call(proxy2);
34 assertEq(Object.getPrototypeOf(new bound2()), g1.Object.prototype);
35
36 // Proxy => cross-realm revoked proxy => cross-realm function.
37 var r2 = Proxy.revocable(g1Fun, {
38 get: function(t, name) {
39 assertEq(name, "prototype");
40 r2.revoke();
41 }
42 });
43 var g2 = newGlobal();
44 var proxy3 = new g2.Proxy(r2.proxy, {});
45 assertThrowsInstanceOf(() => new proxy3(), g1.TypeError);
46
47 if (typeof reportCompare === "function")
48 reportCompare(true, true);