BridgeJS: Fix reject path of zero-parameter async throwing exports#760
Merged
krodak merged 1 commit intoJun 10, 2026
swiftwasm:mainswiftwasm/JavaScriptKit:mainfrom
PassiveLogic:kr/fix-async-thunk-capturelessPassiveLogic/JavaScriptKit:kr/fix-async-thunk-capturelessCopy head branch name to clipboard
Merged
BridgeJS: Fix reject path of zero-parameter async throwing exports#760krodak merged 1 commit intoswiftwasm:mainswiftwasm/JavaScriptKit:mainfrom PassiveLogic:kr/fix-async-thunk-capturelessPassiveLogic/JavaScriptKit:kr/fix-async-thunk-capturelessCopy head branch name to clipboard
krodak merged 1 commit into
swiftwasm:mainswiftwasm/JavaScriptKit:mainfrom
PassiveLogic:kr/fix-async-thunk-capturelessPassiveLogic/JavaScriptKit:kr/fix-async-thunk-capturelessCopy head branch name to clipboard
Conversation
kateinoigakukun
approved these changes
Jun 10, 2026
Member
Author
|
@kateinoigakukun sure, done: #761 |
This was referenced Jun 10, 2026
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
A zero-parameter
async throws(JSException)export traps the Wasm instance when it throws. The generated thunk wraps the call in a_bjs_makePromisebody closure; with no parameters there is nothing to capture, so the closure lowers viathin_to_thick_function, and invoking that value with an indirect typed error miscompiles on Wasm (swiftlang/swift#89320): the thrownJSExceptionarrives corrupted inPromise_rejectand lowering it traps withRuntimeError: table index is out of bounds(or the promise rejects with a garbage value). Exports with parameters are unaffected because their hoisted parameter locals are captured, which makes the body closure a partial apply with a matching call signature.Generated thunk before:
After:
1. Force a capture in captureless async throwing thunk bodies. When the body closure would otherwise capture nothing (zero-parameter top-level functions, static methods, and constructors share this shape), the generator emits a dummy local captured by the closure. The body must also read the captured value: an unread capture list entry is dropped by capture analysis, leaving the closure thin and the bug in place. The read is what produces a real
partial_apply.2. Tests. A codegen snapshot covers the zero-parameter shape, and an end-to-end regression test asserts the rejection arrives with the thrown message instead of trapping. Existing thunks are emitted byte-identically.
This is a codegen-level workaround for swiftlang/swift#89320; once the IRGen fix in swiftlang/swift#89715 lands in a release toolchain, the forced capture can be removed.