Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/common/wpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ class WPTRunner {
console.log(test.stack);
}
const command = `${process.execPath} ${process.execArgv}` +
` ${require.main.filename} '${spec.filename}${spec.variant}'`;
` ${require.main?.filename} '${spec.filename}${spec.variant}'`;
console.log(`Command: ${command}\n`);

reportResult?.addSubtest(test.name, 'FAIL', test.message);
Expand Down
16 changes: 13 additions & 3 deletions test/common/wpt/worker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
'use strict';

const { runInNewContext, runInThisContext } = require('vm');
const {
runInNewContext,
runInThisContext,
constants: { USE_MAIN_CONTEXT_DEFAULT_LOADER },
} = require('vm');
const { setFlagsFromString } = require('v8');
const { parentPort, workerData } = require('worker_threads');

Expand Down Expand Up @@ -28,11 +32,14 @@ globalThis.fetch = function fetch(file) {
};

if (workerData.initScript) {
runInThisContext(workerData.initScript);
runInThisContext(workerData.initScript, {
importModuleDynamically: USE_MAIN_CONTEXT_DEFAULT_LOADER,
});
}

runInThisContext(workerData.harness.code, {
filename: workerData.harness.filename,
importModuleDynamically: USE_MAIN_CONTEXT_DEFAULT_LOADER,
});

// eslint-disable-next-line no-undef
Expand Down Expand Up @@ -66,5 +73,8 @@ add_completion_callback((_, status) => {
});

for (const scriptToRun of workerData.scriptsToRun) {
runInThisContext(scriptToRun.code, { filename: scriptToRun.filename });
runInThisContext(scriptToRun.code, {
filename: scriptToRun.filename,
importModuleDynamically: USE_MAIN_CONTEXT_DEFAULT_LOADER,
});
}
2 changes: 1 addition & 1 deletion test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Last update:
- url: https://github.com/web-platform-tests/wpt/tree/c928b19ab0/url
- urlpattern: https://github.com/web-platform-tests/wpt/tree/a2e15ad405/urlpattern
- user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/65a2134d50/wasm/jsapi
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
- web-locks: https://github.com/web-platform-tests/wpt/tree/10a122a6bc/web-locks
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/6a1c545d77/WebCryptoAPI
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wpt/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"path": "user-timing"
},
"wasm/jsapi": {
"commit": "cde25e7e3c3b9d2280eb088a3fb9da988793d255",
"commit": "65a2134d50",
"path": "wasm/jsapi"
},
"wasm/webapi": {
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/wpt/wasm/jsapi/WEB_FEATURES.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
features:
- name: wasm
files:
- "*"
5 changes: 5 additions & 0 deletions test/fixtures/wpt/wasm/jsapi/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function assert_function_name(fn, name, description) {
assert_true(propdesc.configurable, "configurable", `${description} name should be configurable`);
assert_equals(propdesc.value, name, `${description} name should be ${name}`);
}
globalThis.assert_function_name = assert_function_name;

function assert_function_length(fn, length, description) {
const propdesc = Object.getOwnPropertyDescriptor(fn, "length");
Expand All @@ -15,6 +16,7 @@ function assert_function_length(fn, length, description) {
assert_true(propdesc.configurable, "configurable", `${description} length should be configurable`);
assert_equals(propdesc.value, length, `${description} length should be ${length}`);
}
globalThis.assert_function_length = assert_function_length;

function assert_exported_function(fn, { name, length }, description) {
if (WebAssembly.Function === undefined) {
Expand All @@ -28,6 +30,7 @@ function assert_exported_function(fn, { name, length }, description) {
assert_function_name(fn, name, description);
assert_function_length(fn, length, description);
}
globalThis.assert_exported_function = assert_exported_function;

function assert_Instance(instance, expected_exports) {
assert_equals(Object.getPrototypeOf(instance), WebAssembly.Instance.prototype,
Expand Down Expand Up @@ -77,6 +80,7 @@ function assert_Instance(instance, expected_exports) {
}
}
}
globalThis.assert_Instance = assert_Instance;

function assert_WebAssemblyInstantiatedSource(actual, expected_exports={}) {
assert_equals(Object.getPrototypeOf(actual), Object.prototype,
Expand All @@ -98,3 +102,4 @@ function assert_WebAssemblyInstantiatedSource(actual, expected_exports={}) {
assert_true(instance.configurable, "instance: configurable");
assert_Instance(instance.value, expected_exports);
}
globalThis.assert_WebAssemblyInstantiatedSource = assert_WebAssemblyInstantiatedSource;
1 change: 1 addition & 0 deletions test/fixtures/wpt/wasm/jsapi/bad-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,4 @@ function test_bad_imports(t) {
});
}
}
globalThis.test_bad_imports = test_bad_imports;
8 changes: 8 additions & 0 deletions test/fixtures/wpt/wasm/jsapi/constructor/WEB_FEATURES.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
features:
- name: wasm
files:
- "*"
- "!multi-value.any.js"
- name: wasm-multi-value
files:
- "multi-value.any.js"
2 changes: 1 addition & 1 deletion test/fixtures/wpt/wasm/jsapi/constructor/compile.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js

function assert_Module(module) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/bad-imports.js

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/assertions.js
// META: script=/wasm/jsapi/instanceTestFactory.js
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/assertions.js

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm

"use strict";
// https://webidl.spec.whatwg.org/#es-namespaces
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wpt/wasm/jsapi/constructor/validate.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: global=window,dedicatedworker,jsshell
// META: global=window,dedicatedworker,jsshell,shadowrealm
// META: script=/wasm/jsapi/wasm-module-builder.js

let emptyModuleBinary;
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/wpt/wasm/jsapi/esm-integration/WEB_FEATURES.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
features:
- name: wasm-mutable-globals
files:
- "global-exports-live-bindings.tentative.any.js"
- "mutable-global-sharing.tentative.any.js"
- name: wasm-string-builtins
files:
- "source-phase-string-builtins.tentative.any.js"
- "string-builtins.tentative.any.js"
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// META: global=window,dedicatedworker,jsshell,shadowrealm

"use strict";

promise_test(async () => {
const mod = await import("./resources/exports.wasm");

assert_array_equals(Object.getOwnPropertyNames(mod).sort(), [
"a\u200Bb\u0300c",
"func",
"glob",
"mem",
"tab",
"value with spaces",
"🎯test-func!",
]);
assert_true(mod.func instanceof Function);
assert_true(mod.mem instanceof WebAssembly.Memory);
assert_true(mod.tab instanceof WebAssembly.Table);

assert_false(mod.glob instanceof WebAssembly.Global);
assert_equals(typeof mod.glob, "number");

assert_throws_js(TypeError, () => {
mod.func = 2;
});

assert_equals(typeof mod["value with spaces"], "number");
assert_equals(mod["value with spaces"], 123);

assert_true(mod["🎯test-func!"] instanceof Function);
assert_equals(mod["🎯test-func!"](), 456);

assert_equals(typeof mod["a\u200Bb\u0300c"], "number");
assert_equals(mod["a\u200Bb\u0300c"], 789);
}, "Exported names from a WebAssembly module");
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// META: global=window,dedicatedworker,jsshell,shadowrealm

promise_test(async () => {
const wasmExports = await import("./resources/globals.wasm");

wasmExports.setLocalMutI32(555);
assert_equals(wasmExports.getLocalMutI32(), 555);
assert_equals(wasmExports.localMutI32, 555);

wasmExports.setLocalMutI64(444n);
assert_equals(wasmExports.getLocalMutI64(), 444n);
assert_equals(wasmExports.localMutI64, 444n);

wasmExports.setLocalMutF32(3.33);
assert_equals(Math.round(wasmExports.getLocalMutF32() * 100) / 100, 3.33);
assert_equals(Math.round(wasmExports.localMutF32 * 100) / 100, 3.33);

wasmExports.setLocalMutF64(2.22);
assert_equals(wasmExports.getLocalMutF64(), 2.22);
assert_equals(wasmExports.localMutF64, 2.22);

const anotherTestObj = { another: "test object" };
wasmExports.setLocalMutExternref(anotherTestObj);
assert_equals(wasmExports.getLocalMutExternref(), anotherTestObj);
assert_equals(wasmExports.localMutExternref, anotherTestObj);
}, "Local mutable global exports should be live bindings");

promise_test(async () => {
const wasmExports = await import("./resources/globals.wasm");

wasmExports.setDepMutI32(3001);
assert_equals(wasmExports.getDepMutI32(), 3001);
assert_equals(wasmExports.depMutI32, 3001);

wasmExports.setDepMutI64(30000000001n);
assert_equals(wasmExports.getDepMutI64(), 30000000001n);
assert_equals(wasmExports.depMutI64, 30000000001n);

wasmExports.setDepMutF32(30.01);
assert_equals(Math.round(wasmExports.getDepMutF32() * 100) / 100, 30.01);
assert_equals(Math.round(wasmExports.depMutF32 * 100) / 100, 30.01);

wasmExports.setDepMutF64(300.0001);
assert_equals(wasmExports.getDepMutF64(), 300.0001);
assert_equals(wasmExports.depMutF64, 300.0001);
}, "Dep module mutable global exports should be live bindings");
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// META: global=window,dedicatedworker,jsshell,shadowrealm

promise_test(async () => {
const wasmModule = await import("./resources/globals.wasm");

assert_equals(wasmModule.importedI32, 42);
assert_equals(wasmModule.importedI64, 9223372036854775807n);
assert_equals(Math.round(wasmModule.importedF32 * 100000) / 100000, 3.14159);
assert_equals(wasmModule.importedF64, 3.141592653589793);
assert_not_equals(wasmModule.importedExternref, null);
assert_equals(wasmModule.importedNullExternref, null);
}, "WebAssembly module global values should be unwrapped when importing in ESM integration");

promise_test(async () => {
const wasmModule = await import("./resources/globals.wasm");

assert_equals(wasmModule.importedMutI32, 100);
assert_equals(wasmModule.importedMutI64, 200n);
assert_equals(
Math.round(wasmModule.importedMutF32 * 100000) / 100000,
2.71828
);
assert_equals(wasmModule.importedMutF64, 2.718281828459045);
assert_not_equals(wasmModule.importedMutExternref, null);
assert_equals(wasmModule.importedMutExternref.mutable, "global");
}, "WebAssembly mutable global values should be unwrapped when importing in ESM integration");

promise_test(async () => {
const wasmModule = await import("./resources/globals.wasm");

assert_equals(wasmModule["🚀localI32"], 42);
assert_equals(wasmModule.localMutI32, 100);
assert_equals(wasmModule.localI64, 9223372036854775807n);
assert_equals(wasmModule.localMutI64, 200n);
assert_equals(Math.round(wasmModule.localF32 * 100000) / 100000, 3.14159);
assert_equals(Math.round(wasmModule.localMutF32 * 100000) / 100000, 2.71828);
assert_equals(wasmModule.localF64, 2.718281828459045);
assert_equals(wasmModule.localMutF64, 3.141592653589793);
}, "WebAssembly local global values should be unwrapped when exporting in ESM integration");

promise_test(async () => {
const wasmModule = await import("./resources/globals.wasm");

assert_equals(wasmModule.depI32, 1001);
assert_equals(wasmModule.depMutI32, 2001);
assert_equals(wasmModule.depI64, 10000000001n);
assert_equals(wasmModule.depMutI64, 20000000001n);
assert_equals(Math.round(wasmModule.depF32 * 100) / 100, 10.01);
assert_equals(Math.round(wasmModule.depMutF32 * 100) / 100, 20.01);
assert_equals(wasmModule.depF64, 100.0001);
assert_equals(wasmModule.depMutF64, 200.0001);
}, "WebAssembly module globals from imported WebAssembly modules should be unwrapped");

promise_test(async () => {
const wasmModule = await import("./resources/globals.wasm");

assert_equals(wasmModule.importedI32, 42);
assert_equals(wasmModule.importedMutI32, 100);
assert_equals(wasmModule.importedI64, 9223372036854775807n);
assert_equals(wasmModule.importedMutI64, 200n);
assert_equals(Math.round(wasmModule.importedF32 * 100000) / 100000, 3.14159);
assert_equals(
Math.round(wasmModule.importedMutF32 * 100000) / 100000,
2.71828
);
assert_equals(wasmModule.importedF64, 3.141592653589793);
assert_equals(wasmModule.importedMutF64, 2.718281828459045);
assert_equals(wasmModule.importedExternref !== null, true);
assert_equals(wasmModule.importedMutExternref !== null, true);
assert_equals(wasmModule.importedNullExternref, null);

assert_equals(wasmModule["🚀localI32"], 42);
assert_equals(wasmModule.localMutI32, 100);
assert_equals(wasmModule.localI64, 9223372036854775807n);
assert_equals(wasmModule.localMutI64, 200n);
assert_equals(Math.round(wasmModule.localF32 * 100000) / 100000, 3.14159);
assert_equals(Math.round(wasmModule.localMutF32 * 100000) / 100000, 2.71828);
assert_equals(wasmModule.localF64, 2.718281828459045);
assert_equals(wasmModule.localMutF64, 3.141592653589793);

assert_equals(wasmModule.getImportedMutI32(), 100);
assert_equals(wasmModule.getImportedMutI64(), 200n);
assert_equals(
Math.round(wasmModule.getImportedMutF32() * 100000) / 100000,
2.71828
);
assert_equals(wasmModule.getImportedMutF64(), 2.718281828459045);
assert_equals(wasmModule.getImportedMutExternref() !== null, true);

assert_equals(wasmModule.getLocalMutI32(), 100);
assert_equals(wasmModule.getLocalMutI64(), 200n);
assert_equals(
Math.round(wasmModule.getLocalMutF32() * 100000) / 100000,
2.71828
);
assert_equals(wasmModule.getLocalMutF64(), 3.141592653589793);
assert_equals(wasmModule.getLocalMutExternref(), null);

assert_equals(wasmModule.depI32, 1001);
assert_equals(wasmModule.depMutI32, 2001);
assert_equals(wasmModule.getDepMutI32(), 2001);
assert_equals(wasmModule.depI64, 10000000001n);
assert_equals(wasmModule.depMutI64, 20000000001n);
assert_equals(wasmModule.getDepMutI64(), 20000000001n);
assert_equals(Math.round(wasmModule.depF32 * 100) / 100, 10.01);
assert_equals(Math.round(wasmModule.depMutF32 * 100) / 100, 20.01);
assert_equals(Math.round(wasmModule.getDepMutF32() * 100) / 100, 20.01);
assert_equals(wasmModule.depF64, 100.0001);
assert_equals(wasmModule.depMutF64, 200.0001);
assert_equals(wasmModule.getDepMutF64(), 200.0001);
}, "WebAssembly should properly handle all global types");
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// META: global=window,dedicatedworker,jsshell,shadowrealm

promise_test(async () => {
const { f } = await import("./resources/js-wasm-cycle.js");

assert_equals(f(), 24);
}, "Check bindings in JavaScript and WebAssembly cycle (JS higher)");
Loading
Loading