From b990cba074e7429e01ff4522e01b2b582df4bbf5 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 23 Mar 2026 12:00:54 -0700 Subject: [PATCH] [wasm] Add ESM integration tests for wasm:js/string-constants builtin Tests string constants support in both the instance phase and source phase Wasm ESM integration, covering the wasm:js/string-constants import namespace as specified in the JS API spec. Spec PR: https://github.com/WebAssembly/esm-integration/pull/115 --- .../resources/js-string-constants.wasm | Bin 0 -> 217 bytes .../resources/js-string-constants.wat | 11 ++++++ ...rce-phase-string-builtins.tentative.any.js | 1 + ...ce-phase-string-constants.tentative.any.js | 32 ++++++++++++++++++ .../string-builtins.tentative.any.js | 1 + .../string-constants.tentative.any.js | 10 ++++++ 6 files changed, 55 insertions(+) create mode 100644 wasm/jsapi/esm-integration/resources/js-string-constants.wasm create mode 100644 wasm/jsapi/esm-integration/resources/js-string-constants.wat create mode 100644 wasm/jsapi/esm-integration/source-phase-string-constants.tentative.any.js create mode 100644 wasm/jsapi/esm-integration/string-constants.tentative.any.js 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 0000000000000000000000000000000000000000..4ba2d9e7c5811f99d888292c55e361cc5c5c79c2 GIT binary patch literal 217 zcmZQbEY4+QU|?XXXOSoevaPa;^@~f2GV{`Plk@Y6OA_-+iW!*m8E{H6;+191NX^N~ z$ETm=!~7WyKn3h7EUc-y1tpct3> { 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");