Skip to content

Add wasm_esm_integration_builtins compat flag for runtime-compiled Wasm - #7685

Open
guybedford wants to merge 3 commits into
mainfrom
gbedford/wasm-js-string-builtins
Open

guybedford wants to merge 3 commits into
mainfrom
gbedford/wasm-js-string-builtins

Conversation

@guybedford

Copy link
Copy Markdown
Contributor

This adds a wasm_esm_integration_builtins compatibility flag that compiles Wasm modules with the js-string builtins and imported string constants enabled, resolves #6811. Equivalent to the JS-visible options:

new WebAssembly.Module(src, {
  builtins: ['js-string'],
  importedStringConstants: 'wasm:js/string-constants',
});

V8 has no global flag for these; they are strictly per-module opt-in, so workerd-compiled modules (which never go through the JS constructor) couldn't use them. V8 now exposes WasmModuleObject::Compile with CompileOptions, so when the flag is set jsg::compileWasmModule passes:

options.builtins = v8::WasmModuleObject::CompileOptions::Builtins::kJsString;
options.imported_string_constants_module = "wasm:js/string-constants";

Since this is the single shared compile helper, it covers all runtime-compiled Wasm: import / import source in both module registries, and the deprecated Service Worker syntax wasmModule binding. The flag is plumbed through IsolateBase like the other module-related compat flags.

The js-string-builtins proposal is still in the implementation phase, so the flag is opt-in with no enable date.

Test coverage: adds a js-string-builtins.wat fixture importing the js-string length builtin and a "hello world" string constant, which only links if both features are enabled. new-module-registry-test (flag on) asserts constantLength() returns 11 across normal import, static import source, and dynamic import.source(), using query-distinct specifiers so each path gets its own compile. wasm-js-string-builtins-test (flag off, legacy registry) asserts the wasm:js-string import is treated as an ordinary unsupplied import.

@guybedford
guybedford requested review from a team as code owners October 10, 2026 05:03
@guybedford
guybedford requested a review from jasnell October 10, 2026 05:03
@ask-bonk

ask-bonk Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Since last review: 0 resolved, 0 still open, 0 new.
LGTM!

Not re-run: tests, api-compat, docs, compat-flags, design-simplicity, jsg-gc, kj-style, memory-safety (no author changes in their files since the last review)


Reviewed commit: b25c2849 · github run

Comment thread src/workerd/jsg/modules.c++
Comment thread src/workerd/api/tests/worker-loader-wasm-test.js
Compile Wasm modules with the js-string builtins and imported string
constants enabled, equivalent to the JS options
`{ builtins: ['js-string'], importedStringConstants: 'wasm:js/string-constants' }`.
These are strictly per-module opt-in in V8 with no global flag, so pass
them via WasmModuleObject::CompileOptions in jsg::compileWasmModule, which
covers all runtime-compiled Wasm: ESM import / import source in both module
registries, and the deprecated Service Worker syntax wasmModule binding.

The proposal is still in the implementation phase, so this is gated behind
the opt-in wasm_esm_integration_builtins compat flag with no enable date.
…matches

A WebAssembly.Module passed to the worker loader carries compiled code that
bakes in the compile-time imports of the isolate that compiled it. Both
module registries previously reused that code unconditionally, so the child
worker's wasm_esm_integration_builtins setting was never applied to loader-
provided modules. Record the parent's mode alongside the compiled module
and recompile from the wire bytes when the child's setting differs.
Covers the reverse direction of the compiled-module sharing check: a parent
compiled with wasm_esm_integration_builtins passing a module to a child
that has the flag disabled must recompile, so the child does not gain the
builtins.
@guybedford
guybedford force-pushed the gbedford/wasm-js-string-builtins branch from 62d89d9 to b25c284 Compare October 10, 2026 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant