Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /wasm/jsapi/esm-integration/source-phase-string-builtins.tentative.any.js - WPT Dashboard Interop Dashboard
- /wasm/jsapi/esm-integration/source-phase-string-builtins.tentative.any.html - WPT Dashboard Interop Dashboard
- /wasm/jsapi/esm-integration/source-phase-string-builtins.tentative.any.shadowrealm-in-dedicatedworker.html - WPT Dashboard Interop Dashboard
- /wasm/jsapi/esm-integration/source-phase-string-builtins.tentative.any.shadowrealm-in-shadowrealm.html - WPT Dashboard Interop Dashboard
- /wasm/jsapi/esm-integration/source-phase-string-builtins.tentative.any.shadowrealm-in-sharedworker.html - WPT Dashboard Interop Dashboard
- /wasm/jsapi/esm-integration/source-phase-string-builtins.tentative.any.shadowrealm-in-window.html - WPT Dashboard Interop Dashboard
- /wasm/jsapi/esm-integration/source-phase-string-builtins.tentative.any.worker.html - WPT Dashboard Interop Dashboard
- /wasm/jsapi/esm-integration/source-phase-string-builtins.tentative.https.any.shadowrealm-in-audioworklet.html - WPT Dashboard Interop Dashboard
- /wasm/jsapi/esm-integration/source-phase-string-builtins.tentative.https.any.shadowrealm-in-serviceworker.html - WPT Dashboard Interop Dashboard
// META: global=window,dedicatedworker,jsshell,shadowrealm
promise_test(async () => {
const wasmModuleSource = await import.source("./resources/js-string-builtins.wasm");
assert_true(wasmModuleSource instanceof WebAssembly.Module);
const instance = new WebAssembly.Instance(wasmModuleSource, {});
assert_equals(instance.exports.getLength("hello"), 5);
assert_equals(
instance.exports.concatStrings("hello", " world"),
"hello world"
);
assert_equals(instance.exports.compareStrings("test", "test"), 1);
assert_equals(instance.exports.compareStrings("test", "different"), 0);
assert_equals(instance.exports.testString("hello"), 1);
assert_equals(instance.exports.testString(42), 0);
}, "String builtins should be supported in source phase imports");
promise_test(async () => {
const wasmModuleSource = await import.source("./resources/js-string-builtins.wasm");
const exports = WebAssembly.Module.exports(wasmModuleSource);
const exportNames = exports.map((exp) => exp.name);
assert_true(exportNames.includes("getLength"));
assert_true(exportNames.includes("concatStrings"));
assert_true(exportNames.includes("compareStrings"));
assert_true(exportNames.includes("testString"));
}, "Source phase import should properly expose string builtin exports");
promise_test(async () => {
const wasmModuleSource = await import.source("./resources/js-string-builtins.wasm");
const imports = WebAssembly.Module.imports(wasmModuleSource);
assert_equals(imports.length, 0);
}, "Source phase import should handle string builtin import reflection correctly");