node/test/fixtures/es-modules/js-string-builtins.wat
Guy Bedford a936d8968f wasm: support js string constant esm import
Extends the Wasm ESM Integration for importing WebAssembly
modules in either the source phase or instance phase to support
importing static JS string constants from the special
import name `wasm:js/string-constants`.

PR-URL: https://github.com/nodejs/node/pull/62198
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2026-03-14 15:08:49 -04:00

37 lines
No EOL
1.2 KiB
WebAssembly Text Format

;; Test WASM module using js-string builtins
(module
;; Import js-string builtins with correct signatures
(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
call $string_length
)
(func $concat_strings (param $str1 externref) (param $str2 externref) (result (ref extern))
local.get $str1
local.get $str2
call $string_concat
)
(func $compare_strings (param $str1 externref) (param $str2 externref) (result i32)
local.get $str1
local.get $str2
call $string_equals
)
(func $get_hello (result externref)
global.get $hello
)
)