summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/wasm/jsapi/function
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/wasm/jsapi/function
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/wasm/jsapi/function')
-rw-r--r--testing/web-platform/tests/wasm/jsapi/function/call.tentative.any.js16
-rw-r--r--testing/web-platform/tests/wasm/jsapi/function/constructor.tentative.any.js65
-rw-r--r--testing/web-platform/tests/wasm/jsapi/function/table.tentative.any.js30
-rw-r--r--testing/web-platform/tests/wasm/jsapi/function/type.tentative.any.js28
4 files changed, 139 insertions, 0 deletions
diff --git a/testing/web-platform/tests/wasm/jsapi/function/call.tentative.any.js b/testing/web-platform/tests/wasm/jsapi/function/call.tentative.any.js
new file mode 100644
index 0000000000..626cd13c9f
--- /dev/null
+++ b/testing/web-platform/tests/wasm/jsapi/function/call.tentative.any.js
@@ -0,0 +1,16 @@
+// META: global=window,dedicatedworker,jsshell
+// META: script=/wasm/jsapi/assertions.js
+
+function addxy(x, y) {
+ return x + y
+}
+
+test(() => {
+ var fun = new WebAssembly.Function({parameters: ["i32", "i32"], results: ["i32"]}, addxy);
+ assert_equals(fun(1, 2), 3)
+}, "test calling function")
+
+test(() => {
+ var fun = new WebAssembly.Function({parameters: ["i32", "i32"], results: ["i32"]}, addxy);
+ assert_throws_js(TypeError, () => new fun(1, 2));
+}, "test constructing function");
diff --git a/testing/web-platform/tests/wasm/jsapi/function/constructor.tentative.any.js b/testing/web-platform/tests/wasm/jsapi/function/constructor.tentative.any.js
new file mode 100644
index 0000000000..636aeca4dc
--- /dev/null
+++ b/testing/web-platform/tests/wasm/jsapi/function/constructor.tentative.any.js
@@ -0,0 +1,65 @@
+// META: global=window,dedicatedworker,jsshell
+// META: script=/wasm/jsapi/assertions.js
+
+function addxy(x, y) {
+ return x + y
+}
+
+test(() => {
+ assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
+ assert_function_name(WebAssembly.Function, "Function", "WebAssembly.Function");
+}, "name");
+
+test(() => {
+ assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
+ assert_function_length(WebAssembly.Function, 2, "WebAssembly.Function");
+}, "length");
+
+test(() => {
+ assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
+ assert_throws_js(TypeError, () => new WebAssembly.Function());
+ const argument = {parameters: [], results: []};
+ assert_throws_js(TypeError, () => new WebAssembly.Function(argument));
+}, "Too few arguments");
+
+test(() => {
+ assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
+ const arguments = [{parameters: ["i32", "i32"], results: ["i32"]}, addxy];
+ assert_throws_js(TypeError, () => WebAssembly.Function(...arguments));
+}, "Calling");
+
+test(() => {
+ assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
+ var fun = new WebAssembly.Function({parameters: ["i32", "i32"], results: ["i32"]}, addxy);
+ assert_true(fun instanceof WebAssembly.Function)
+}, "construct with JS function")
+
+test(() => {
+ assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
+ assert_throws_js(TypeError, () => new WebAssembly.Function({parameters: []}, addxy))
+}, "fail with missing results")
+
+test(() => {
+ assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
+ assert_throws_js(TypeError, () => new WebAssembly.Function({results: []}, addxy))
+}, "fail with missing parameters")
+
+test(() => {
+ assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
+ assert_throws_js(TypeError, () => new WebAssembly.Function({parameters: [1], results: [true]}, addxy))
+}, "fail with non-string parameters & results")
+
+test(() => {
+ assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
+ assert_throws_js(TypeError, () => new WebAssembly.Function({parameters: ["invalid"], results: ["invalid"]}, addxy))
+}, "fail with non-existent parameter and result type")
+
+test(() => {
+ assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
+ assert_throws_js(TypeError, () => new WebAssembly.Function({parameters: [], results: []}, 72))
+}, "fail with non-function object")
+
+test(() => {
+ assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
+ assert_throws_js(TypeError, () => new WebAssembly.Function({parameters: [], results: []}, {}))
+}, "fail to construct with non-callable object")
diff --git a/testing/web-platform/tests/wasm/jsapi/function/table.tentative.any.js b/testing/web-platform/tests/wasm/jsapi/function/table.tentative.any.js
new file mode 100644
index 0000000000..d7d0d86e3b
--- /dev/null
+++ b/testing/web-platform/tests/wasm/jsapi/function/table.tentative.any.js
@@ -0,0 +1,30 @@
+// META: global=window,dedicatedworker,jsshell
+// META: script=/wasm/jsapi/assertions.js
+
+function testfunc(n) {}
+
+test(() => {
+ var table = new WebAssembly.Table({element: "anyfunc", initial: 3})
+ var func1 = new WebAssembly.Function({parameters: ["i32"], results: []}, testfunc)
+ table.set(0, func1)
+ var func2 = new WebAssembly.Function({parameters: ["f32"], results: []}, testfunc)
+ table.set(1, func2)
+ var func3 = new WebAssembly.Function({parameters: ["i64"], results: []}, testfunc)
+ table.set(2, func3)
+
+ var first = table.get(0)
+ assert_true(first instanceof WebAssembly.Function)
+ assert_equals(first, func1)
+ assert_equals(first.type().parameters[0], func1.type().parameters[0])
+
+ var second = table.get(1)
+ assert_true(second instanceof WebAssembly.Function)
+ assert_equals(second, func2)
+ assert_equals(second.type().parameters[0], func2.type().parameters[0])
+
+ var third = table.get(2)
+ assert_true(third instanceof WebAssembly.Function)
+ assert_equals(third, func3)
+ assert_equals(third.type().parameters[0], func3.type().parameters[0])
+
+}, "Test insertion into table")
diff --git a/testing/web-platform/tests/wasm/jsapi/function/type.tentative.any.js b/testing/web-platform/tests/wasm/jsapi/function/type.tentative.any.js
new file mode 100644
index 0000000000..e01a23a9e4
--- /dev/null
+++ b/testing/web-platform/tests/wasm/jsapi/function/type.tentative.any.js
@@ -0,0 +1,28 @@
+// META: global=window,dedicatedworker,jsshell
+// META: script=/wasm/jsapi/assertions.js
+
+function addNumbers(x, y, z) {
+ return x+y+z;
+}
+
+function doNothing() {}
+
+function assert_function(functype, func) {
+ var wasmFunc = new WebAssembly.Function(functype, func);
+ assert_equals(functype.parameters.length, wasmFunc.type().parameters.length);
+ for(let i = 0; i < functype.parameters.length; i++) {
+ assert_equals(functype.parameters[i], wasmFunc.type().parameters[i]);
+ }
+ assert_equals(functype.results.length, wasmFunc.type().results.length);
+ for(let i = 0; i < functype.results.length; i++) {
+ assert_equals(functype.results[i], wasmFunc.type().results[i]);
+ }
+}
+
+test(() => {
+ assert_function({results: [], parameters: []}, doNothing);
+}, "Check empty results and parameters")
+
+test(() => {
+ assert_function({results: ["f64"], parameters: ["i32", "i64", "f32"]}, addNumbers)
+}, "Check all types")