Repository navigation
Add wasm_esm_integration_builtins compat flag for runtime-compiled Wasm #7685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ;; Only links if the runtime compiles Wasm with | ||
| ;; { builtins: ['js-string'], importedStringConstants: 'wasm:js/string-constants' }. | ||
| (module | ||
| (import "wasm:js-string" "length" | ||
| (func $length (param externref) (result i32))) | ||
|
|
||
| (import "wasm:js/string-constants" "hello world" | ||
| (global $hello externref)) | ||
|
|
||
| (func (export "constantLength") (result i32) | ||
| (call $length (global.get $hello))) | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Copyright (c) 2026 Cloudflare, Inc. | ||
| // Licensed under the Apache 2.0 license found in the LICENSE file or at: | ||
| // https://opensource.org/licenses/Apache-2.0 | ||
|
|
||
| import { rejects } from 'node:assert'; | ||
| import wasm from 'wasm-js-string'; | ||
|
|
||
| // Without the wasm_esm_integration_builtins compat flag, the `wasm:*` imports are | ||
| // ordinary imports that must be supplied by the embedder. | ||
| export const wasmJsStringBuiltinsDisabledTest = { | ||
| async test() { | ||
| await rejects(WebAssembly.instantiate(wasm, {}), { | ||
| name: 'TypeError', | ||
| message: /wasm:js-string/, | ||
| }); | ||
| }, | ||
| }; |
15 changes: 15 additions & 0 deletions
15
src/workerd/api/tests/wasm-js-string-builtins-test.wd-test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using Workerd = import "/workerd/workerd.capnp"; | ||
|
|
||
| const unitTests :Workerd.Config = ( | ||
| services = [ | ||
| ( name = "wasm-js-string-builtins-test", | ||
| worker = ( | ||
| modules = [ | ||
| (name = "worker", esModule = embed "wasm-js-string-builtins-test.js"), | ||
| (name = "wasm-js-string", wasm = embed "js-string-builtins.wasm"), | ||
| ], | ||
| compatibilityFlags = ["nodejs_compat"], | ||
| ), | ||
| ), | ||
| ], | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright (c) 2026 Cloudflare, Inc. | ||
| // Licensed under the Apache 2.0 license found in the LICENSE file or at: | ||
| // https://opensource.org/licenses/Apache-2.0 | ||
| import assert from 'node:assert'; | ||
| import source jsStringWasm from './js-string.wasm'; | ||
|
|
||
| // This worker compiles with wasm_esm_integration_builtins, so the module passed to the dynamic | ||
| // worker was compiled with the builtins. The child does not enable the flag, so it must not | ||
| // share the parent's compiled code. | ||
| export let wasmModuleSourceBuiltinsDisabledInChild = { | ||
| async test(ctrl, env, ctx) { | ||
| const instance = await WebAssembly.instantiate(jsStringWasm, {}); | ||
| assert.strictEqual(instance.exports.constantLength(), 11); | ||
|
|
||
| for (let extraFlags of [[], ['new_module_registry']]) { | ||
| let worker = env.loader.get(`wasmBuiltinsDisabled-${extraFlags}`, () => { | ||
| return { | ||
| compatibilityDate: '2025-01-01', | ||
| compatibilityFlags: extraFlags, | ||
| allowExperimental: extraFlags.length > 0, | ||
| mainModule: 'main.js', | ||
| modules: { | ||
| 'main.js': ` | ||
| import {WorkerEntrypoint} from "cloudflare:workers"; | ||
| import source wasm from './js-string.wasm'; | ||
|
|
||
| export default class extends WorkerEntrypoint { | ||
| async instantiate() { | ||
| try { | ||
| await WebAssembly.instantiate(wasm, {}); | ||
| } catch (e) { | ||
| return e.name; | ||
| } | ||
| return 'ok'; | ||
| } | ||
| } | ||
| `, | ||
| 'js-string.wasm': jsStringWasm, | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| assert.strictEqual( | ||
| await worker.getEntrypoint().instantiate(), | ||
| 'TypeError' | ||
| ); | ||
| } | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.