summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Function/get-function-realm.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/non262/Function/get-function-realm.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Function/get-function-realm.js')
-rw-r--r--js/src/tests/non262/Function/get-function-realm.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/js/src/tests/non262/Function/get-function-realm.js b/js/src/tests/non262/Function/get-function-realm.js
new file mode 100644
index 0000000000..4efd94f971
--- /dev/null
+++ b/js/src/tests/non262/Function/get-function-realm.js
@@ -0,0 +1,45 @@
+var g1 = newGlobal();
+var g1Fun = g1.eval("function Fun() {}; Fun");
+
+// Bound function => cross-realm function.
+var bound1 = Function.prototype.bind.call(g1Fun);
+assertEq(Object.getPrototypeOf(new bound1()), g1.Fun.prototype);
+
+// Proxy => cross-realm function.
+var proxy1 = new Proxy(g1Fun, {
+ get: function() {} // Ensure "prototype" is |undefined|.
+});
+assertEq(Object.getPrototypeOf(new proxy1()), g1.Object.prototype);
+
+// Proxy => bound function => cross-realm function.
+var proxy2 = new Proxy(bound1, {
+ get: function() {}
+});
+assertEq(Object.getPrototypeOf(new proxy2()), g1.Object.prototype);
+
+// Revoked proxy => cross-realm function.
+var r1 = Proxy.revocable(g1Fun, {
+ get: function(t, name) {
+ assertEq(name, "prototype");
+ r1.revoke();
+ }
+});
+assertThrowsInstanceOf(() => new r1.proxy(), g1.TypeError);
+
+// Bound function => proxy => bound function => cross-realm function.
+var bound2 = Function.prototype.bind.call(proxy2);
+assertEq(Object.getPrototypeOf(new bound2()), g1.Object.prototype);
+
+// Proxy => cross-realm revoked proxy => cross-realm function.
+var r2 = Proxy.revocable(g1Fun, {
+ get: function(t, name) {
+ assertEq(name, "prototype");
+ r2.revoke();
+ }
+});
+var g2 = newGlobal();
+var proxy3 = new g2.Proxy(r2.proxy, {});
+assertThrowsInstanceOf(() => new proxy3(), g1.TypeError);
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);