summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/wasm/jsapi/instance
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/instance
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/instance')
-rw-r--r--testing/web-platform/tests/wasm/jsapi/instance/constructor-bad-imports.any.js13
-rw-r--r--testing/web-platform/tests/wasm/jsapi/instance/constructor-caching.any.js54
-rw-r--r--testing/web-platform/tests/wasm/jsapi/instance/constructor.any.js54
-rw-r--r--testing/web-platform/tests/wasm/jsapi/instance/exports.any.js66
-rw-r--r--testing/web-platform/tests/wasm/jsapi/instance/toString.any.js19
5 files changed, 206 insertions, 0 deletions
diff --git a/testing/web-platform/tests/wasm/jsapi/instance/constructor-bad-imports.any.js b/testing/web-platform/tests/wasm/jsapi/instance/constructor-bad-imports.any.js
new file mode 100644
index 0000000000..e4a5abb8eb
--- /dev/null
+++ b/testing/web-platform/tests/wasm/jsapi/instance/constructor-bad-imports.any.js
@@ -0,0 +1,13 @@
+// META: global=window,dedicatedworker,jsshell
+// META: script=/wasm/jsapi/wasm-module-builder.js
+// META: script=/wasm/jsapi/bad-imports.js
+
+test_bad_imports((name, error, build, ...arguments) => {
+ test(() => {
+ const builder = new WasmModuleBuilder();
+ build(builder);
+ const buffer = builder.toBuffer();
+ const module = new WebAssembly.Module(buffer);
+ assert_throws_js(error, () => new WebAssembly.Instance(module, ...arguments));
+ }, `new WebAssembly.Instance(module): ${name}`);
+});
diff --git a/testing/web-platform/tests/wasm/jsapi/instance/constructor-caching.any.js b/testing/web-platform/tests/wasm/jsapi/instance/constructor-caching.any.js
new file mode 100644
index 0000000000..1aa4739b62
--- /dev/null
+++ b/testing/web-platform/tests/wasm/jsapi/instance/constructor-caching.any.js
@@ -0,0 +1,54 @@
+// META: global=window,dedicatedworker,jsshell
+// META: script=/wasm/jsapi/wasm-module-builder.js
+
+function getExports() {
+ const builder = new WasmModuleBuilder();
+ builder
+ .addFunction("fn", kSig_v_d)
+ .addBody([])
+ .exportFunc();
+
+ builder.setTableBounds(1);
+ builder.addExportOfKind("table", kExternalTable, 0);
+ builder.addGlobal(kWasmI32, false).exportAs("global");
+ builder.addMemory(4, 8, true);
+
+ const buffer = builder.toBuffer();
+ const module = new WebAssembly.Module(buffer);
+ const instance = new WebAssembly.Instance(module);
+ return instance.exports;
+}
+
+test(() => {
+ const exports = getExports();
+
+ const builder = new WasmModuleBuilder();
+ const functionIndex = builder.addImport("module", "imported", kSig_v_d);
+ builder.addExport("exportedFunction", functionIndex);
+
+ const globalIndex = builder.addImportedGlobal("module", "global", kWasmI32);
+ builder.addExportOfKind("exportedGlobal", kExternalGlobal, globalIndex);
+
+ builder.addImportedMemory("module", "memory", 4);
+ builder.exportMemoryAs("exportedMemory");
+
+ const tableIndex = builder.addImportedTable("module", "table", 1);
+ builder.addExportOfKind("exportedTable", kExternalTable, tableIndex);
+
+ const buffer = builder.toBuffer();
+
+ const module = new WebAssembly.Module(buffer);
+ const instance = new WebAssembly.Instance(module, {
+ "module": {
+ "imported": exports.fn,
+ "global": exports.global,
+ "memory": exports.memory,
+ "table": exports.table,
+ }
+ });
+
+ assert_equals(instance.exports.exportedFunction, exports.fn);
+ assert_equals(instance.exports.exportedGlobal, exports.global);
+ assert_equals(instance.exports.exportedMemory, exports.memory);
+ assert_equals(instance.exports.exportedTable, exports.table);
+});
diff --git a/testing/web-platform/tests/wasm/jsapi/instance/constructor.any.js b/testing/web-platform/tests/wasm/jsapi/instance/constructor.any.js
new file mode 100644
index 0000000000..26390ebd2c
--- /dev/null
+++ b/testing/web-platform/tests/wasm/jsapi/instance/constructor.any.js
@@ -0,0 +1,54 @@
+// META: global=window,dedicatedworker,jsshell
+// META: script=/wasm/jsapi/wasm-module-builder.js
+// META: script=/wasm/jsapi/assertions.js
+// META: script=/wasm/jsapi/instanceTestFactory.js
+
+let emptyModuleBinary;
+setup(() => {
+ emptyModuleBinary = new WasmModuleBuilder().toBuffer();
+});
+
+test(() => {
+ assert_function_name(WebAssembly.Instance, "Instance", "WebAssembly.Instance");
+}, "name");
+
+test(() => {
+ assert_function_length(WebAssembly.Instance, 1, "WebAssembly.Instance");
+}, "length");
+
+test(() => {
+ assert_throws_js(TypeError, () => new WebAssembly.Instance());
+}, "No arguments");
+
+test(() => {
+ const invalidArguments = [
+ undefined,
+ null,
+ true,
+ "",
+ Symbol(),
+ 1,
+ {},
+ WebAssembly.Module,
+ WebAssembly.Module.prototype,
+ ];
+ for (const argument of invalidArguments) {
+ assert_throws_js(TypeError, () => new WebAssembly.Instance(argument),
+ `new Instance(${format_value(argument)})`);
+ }
+}, "Non-Module arguments");
+
+test(() => {
+ const module = new WebAssembly.Module(emptyModuleBinary);
+ assert_throws_js(TypeError, () => WebAssembly.Instance(module));
+}, "Calling");
+
+for (const [name, fn] of instanceTestFactory) {
+ test(() => {
+ const { buffer, args, exports, verify } = fn();
+ const module = new WebAssembly.Module(buffer);
+ const instance = new WebAssembly.Instance(module, ...args);
+ assert_Instance(instance, exports);
+ verify(instance);
+ }, name);
+}
diff --git a/testing/web-platform/tests/wasm/jsapi/instance/exports.any.js b/testing/web-platform/tests/wasm/jsapi/instance/exports.any.js
new file mode 100644
index 0000000000..6dcfbcee95
--- /dev/null
+++ b/testing/web-platform/tests/wasm/jsapi/instance/exports.any.js
@@ -0,0 +1,66 @@
+// META: global=window,dedicatedworker,jsshell
+// META: script=/wasm/jsapi/wasm-module-builder.js
+
+let emptyModuleBinary;
+setup(() => {
+ emptyModuleBinary = new WasmModuleBuilder().toBuffer();
+});
+
+test(() => {
+ const thisValues = [
+ undefined,
+ null,
+ true,
+ "",
+ Symbol(),
+ 1,
+ {},
+ WebAssembly.Instance,
+ WebAssembly.Instance.prototype,
+ ];
+
+ const desc = Object.getOwnPropertyDescriptor(WebAssembly.Instance.prototype, "exports");
+ assert_equals(typeof desc, "object");
+
+ const getter = desc.get;
+ assert_equals(typeof getter, "function");
+
+ assert_equals(typeof desc.set, "undefined");
+
+ for (const thisValue of thisValues) {
+ assert_throws_js(TypeError, () => getter.call(thisValue), `this=${format_value(thisValue)}`);
+ }
+}, "Branding");
+
+test(() => {
+ const module = new WebAssembly.Module(emptyModuleBinary);
+ const instance = new WebAssembly.Instance(module);
+ const exports = instance.exports;
+
+ const desc = Object.getOwnPropertyDescriptor(WebAssembly.Instance.prototype, "exports");
+ assert_equals(typeof desc, "object");
+
+ const getter = desc.get;
+ assert_equals(typeof getter, "function");
+
+ assert_equals(getter.call(instance, {}), exports);
+}, "Stray argument");
+
+test(() => {
+ const module = new WebAssembly.Module(emptyModuleBinary);
+ const instance = new WebAssembly.Instance(module);
+ const exports = instance.exports;
+ instance.exports = {};
+ assert_equals(instance.exports, exports, "Should not change the exports");
+}, "Setting (sloppy mode)");
+
+test(() => {
+ const module = new WebAssembly.Module(emptyModuleBinary);
+ const instance = new WebAssembly.Instance(module);
+ const exports = instance.exports;
+ assert_throws_js(TypeError, () => {
+ "use strict";
+ instance.exports = {};
+ });
+ assert_equals(instance.exports, exports, "Should not change the exports");
+}, "Setting (strict mode)");
diff --git a/testing/web-platform/tests/wasm/jsapi/instance/toString.any.js b/testing/web-platform/tests/wasm/jsapi/instance/toString.any.js
new file mode 100644
index 0000000000..547a9ca829
--- /dev/null
+++ b/testing/web-platform/tests/wasm/jsapi/instance/toString.any.js
@@ -0,0 +1,19 @@
+// META: global=window,dedicatedworker,jsshell
+// META: script=/wasm/jsapi/wasm-module-builder.js
+
+test(() => {
+ const emptyModuleBinary = new WasmModuleBuilder().toBuffer();
+ const module = new WebAssembly.Module(emptyModuleBinary);
+ const instance = new WebAssembly.Instance(module);
+ assert_class_string(instance, "WebAssembly.Instance");
+}, "Object.prototype.toString on an Instance");
+
+test(() => {
+ assert_own_property(WebAssembly.Instance.prototype, Symbol.toStringTag);
+
+ const propDesc = Object.getOwnPropertyDescriptor(WebAssembly.Instance.prototype, Symbol.toStringTag);
+ assert_equals(propDesc.value, "WebAssembly.Instance", "value");
+ assert_equals(propDesc.configurable, true, "configurable");
+ assert_equals(propDesc.enumerable, false, "enumerable");
+ assert_equals(propDesc.writable, false, "writable");
+}, "@@toStringTag exists on the prototype with the appropriate descriptor");