summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/js-types/function-ctor-callable.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /js/src/jit-test/tests/wasm/js-types/function-ctor-callable.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/wasm/js-types/function-ctor-callable.js')
-rw-r--r--js/src/jit-test/tests/wasm/js-types/function-ctor-callable.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/wasm/js-types/function-ctor-callable.js b/js/src/jit-test/tests/wasm/js-types/function-ctor-callable.js
new file mode 100644
index 0000000000..d99a64eaf7
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/js-types/function-ctor-callable.js
@@ -0,0 +1,33 @@
+// |jit-test| skip-if: !('Function' in WebAssembly)
+
+load(libdir + "asserts.js");
+
+function testWasmFunc(f, arg, rval) {
+ var func = new WebAssembly.Function({parameters: ["i32"], results: ["i32"]}, f);
+ assertEq(func instanceof WebAssembly.Function, true);
+ assertEq(func(arg), rval);
+}
+
+let f = n => n + 5;
+
+// Callable objects.
+testWasmFunc(f, 1, 6);
+testWasmFunc(f.bind(null), 2, 7);
+testWasmFunc(f.bind(null, 9), 2, 14);
+testWasmFunc(new Proxy(f, {}), 3, 8);
+testWasmFunc(new Proxy(f, {apply() { return 123; }}), 3, 123);
+
+// Cross-realm but same-compartment function.
+let global1 = newGlobal({sameCompartmentAs: this});
+global1.evaluate("function f(n) { return n + 8; }");
+testWasmFunc(global1.f, 1, 9);
+
+// Non-callable values.
+assertErrorMessage(() => testWasmFunc({}, 1, 6), TypeError, /must be a function/);
+assertErrorMessage(() => testWasmFunc(null, 1, 6), TypeError, /must be a function/);
+assertErrorMessage(() => testWasmFunc("", 1, 6), TypeError, /must be a function/);
+
+// Cross-compartment wrappers are not supported yet. See IsCallableNonCCW.
+let global2 = newGlobal({newCompartment: true});
+global2.evaluate("function f() {}");
+assertErrorMessage(() => testWasmFunc(global2.f, 1, 6), TypeError, /must be a function/);