wasm: support js string constant esm import by guybedford · Pull Request #62198 · nodejs/node · GitHub
Skip to content
Closed
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
9 changes: 9 additions & 0 deletions doc/api/esm.md
1 change: 1 addition & 0 deletions lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ translators.set('wasm', function(url, translateContext) {
try {
compiled = new WebAssembly.Module(source, {
builtins: ['js-string'],
importedStringConstants: 'wasm:js/string-constants',
});
} catch (err) {
err.message = errPath(url) + ': ' + err.message;
Expand Down
Binary file modified test/fixtures/es-modules/js-string-builtins.wasm
Binary file not shown.
8 changes: 8 additions & 0 deletions test/fixtures/es-modules/js-string-builtins.wat
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
(import "wasm:js-string" "length" (func $string_length (param externref) (result i32)))
(import "wasm:js-string" "concat" (func $string_concat (param externref externref) (result (ref extern))))
(import "wasm:js-string" "equals" (func $string_equals (param externref externref) (result i32)))

;; Import a string constant via importedStringConstants
(import "wasm:js/string-constants" "hello" (global $hello externref))

;; Export functions that use the builtins
(export "getLength" (func $get_length))
(export "concatStrings" (func $concat_strings))
(export "compareStrings" (func $compare_strings))
(export "getHello" (func $get_hello))

(func $get_length (param $str externref) (result i32)
local.get $str
Expand All @@ -26,4 +30,8 @@
local.get $str2
call $string_equals
)

(func $get_hello (result externref)
global.get $hello
)
)
1 change: 1 addition & 0 deletions test/fixtures/es-modules/test-wasm-js-string-builtins.mjs
Loading