BridgeJS: Always provide swift_js_closure_unregister intrinsic in generated bridge-js.js#599
Merged
krodak merged 1 commit intoswiftwasm:mainfrom Feb 6, 2026
Conversation
…erated bridge-js.js
MaxDesiatov
reviewed
Feb 6, 2026
| printer.write("}") | ||
| // Always provide swift_js_closure_unregister as a no-op by default. | ||
| // The @_extern(wasm) declaration in BridgeJSIntrinsics.swift is unconditional, | ||
| // so the WASM binary always imports this symbol. When closures ARE used, |
Member
There was a problem hiding this comment.
nit
Suggested change
| // so the WASM binary always imports this symbol. When closures ARE used, | |
| // so the Wasm binary always imports this symbol. When closures ARE used, |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Overview
PR #578 added
JSTypedClosureAPI which introduced a newswift_js_closure_unregisterBridgeJS intrinsic. The@_extern(wasm)declaration inBridgeJSIntrinsics.swiftis unconditional, so the WASM binary always imports this symbol from thebjsmodule. However, the generatedbridge-js.jsonly provides it when closure signatures are detected in the API surface.Issue
When a project uses BridgeJS but does not use any closure types, the generated
bridge-js.jsomitsswift_js_closure_unregister. Since the WASM binary unconditionally imports it, instantiation fails with:The
instantiate.jstemplate hasunexpectedBjsCallstubs for all intrinsics (includingswift_js_closure_unregister), but these stubs are only used whenHAS_BRIDGEis false. When BridgeJS IS active, the template imports frombridge-js.jsinstead — which may not include the intrinsic.Fix
swift_js_closure_unregisterinBridgeJSLink.swift, alongside other always-present intrinsics likeswift_js_throw,swift_js_retain,swift_js_release