diff --git a/wasm/jsapi/esm-integration/resources/js-string-constants.wasm b/wasm/jsapi/esm-integration/resources/js-string-constants.wasm new file mode 100644 index 00000000000000..4ba2d9e7c5811f Binary files /dev/null and b/wasm/jsapi/esm-integration/resources/js-string-constants.wasm differ diff --git a/wasm/jsapi/esm-integration/resources/js-string-constants.wat b/wasm/jsapi/esm-integration/resources/js-string-constants.wat new file mode 100644 index 00000000000000..2de58bc19cdf12 --- /dev/null +++ b/wasm/jsapi/esm-integration/resources/js-string-constants.wat @@ -0,0 +1,11 @@ +(module + (import "wasm:js/string-constants" "" (global $empty externref)) + (import "wasm:js/string-constants" "\00" (global $null_byte externref)) + (import "wasm:js/string-constants" "hello" (global $hello externref)) + (import "wasm:js/string-constants" "\f0\9f\98\80" (global $emoji externref)) + + (export "empty" (global $empty)) + (export "nullByte" (global $null_byte)) + (export "hello" (global $hello)) + (export "emoji" (global $emoji)) +) diff --git a/wasm/jsapi/esm-integration/source-phase-string-builtins.tentative.any.js b/wasm/jsapi/esm-integration/source-phase-string-builtins.tentative.any.js index e79b457dd464fc..bedb4d5b6a58bd 100644 --- a/wasm/jsapi/esm-integration/source-phase-string-builtins.tentative.any.js +++ b/wasm/jsapi/esm-integration/source-phase-string-builtins.tentative.any.js @@ -37,3 +37,4 @@ promise_test(async () => { assert_equals(imports.length, 0); }, "Source phase import should handle string builtin import reflection correctly"); + diff --git a/wasm/jsapi/esm-integration/source-phase-string-constants.tentative.any.js b/wasm/jsapi/esm-integration/source-phase-string-constants.tentative.any.js new file mode 100644 index 00000000000000..66ee89c5394281 --- /dev/null +++ b/wasm/jsapi/esm-integration/source-phase-string-constants.tentative.any.js @@ -0,0 +1,32 @@ +// META: global=window,dedicatedworker,jsshell,shadowrealm + +promise_test(async () => { + const wasmModuleSource = await import.source("./resources/js-string-constants.wasm"); + + const instance = new WebAssembly.Instance(wasmModuleSource, {}); + + assert_equals(instance.exports.empty.value, ""); + assert_equals(instance.exports.nullByte.value, "\0"); + assert_equals(instance.exports.hello.value, "hello"); + assert_equals(instance.exports.emoji.value, "\u{1F600}"); +}, "String constants from wasm:js/string-constants should be supported in source phase imports"); + +promise_test(async () => { + const wasmModuleSource = await import.source("./resources/js-string-constants.wasm"); + + const exports = WebAssembly.Module.exports(wasmModuleSource); + const exportNames = exports.map((exp) => exp.name); + + assert_true(exportNames.includes("empty")); + assert_true(exportNames.includes("nullByte")); + assert_true(exportNames.includes("hello")); + assert_true(exportNames.includes("emoji")); +}, "Source phase import should properly expose string constants exports"); + +promise_test(async () => { + const wasmModuleSource = await import.source("./resources/js-string-constants.wasm"); + + const imports = WebAssembly.Module.imports(wasmModuleSource); + + assert_equals(imports.length, 0); +}, "Source phase import should handle string constants import reflection correctly"); diff --git a/wasm/jsapi/esm-integration/string-builtins.tentative.any.js b/wasm/jsapi/esm-integration/string-builtins.tentative.any.js index bac8fd92727437..f291c4ff53c453 100644 --- a/wasm/jsapi/esm-integration/string-builtins.tentative.any.js +++ b/wasm/jsapi/esm-integration/string-builtins.tentative.any.js @@ -10,3 +10,4 @@ promise_test(async () => { assert_equals(wasmModule.testString("hello"), 1); assert_equals(wasmModule.testString(42), 0); }, "String builtins should be supported in imports in ESM integration"); + diff --git a/wasm/jsapi/esm-integration/string-constants.tentative.any.js b/wasm/jsapi/esm-integration/string-constants.tentative.any.js new file mode 100644 index 00000000000000..8166bb4f721726 --- /dev/null +++ b/wasm/jsapi/esm-integration/string-constants.tentative.any.js @@ -0,0 +1,10 @@ +// META: global=window,dedicatedworker,jsshell,shadowrealm + +promise_test(async () => { + const wasmModule = await import("./resources/js-string-constants.wasm"); + + assert_equals(wasmModule.empty, ""); + assert_equals(wasmModule.nullByte, "\0"); + assert_equals(wasmModule.hello, "hello"); + assert_equals(wasmModule.emoji, "\u{1F600}"); +}, "String constants from wasm:js/string-constants should be supported in ESM integration");