BridgeJS: Use a BigInt zero placeholder for Wasm i64 in generated JS#757
Merged
krodak merged 1 commit intoJun 8, 2026
Merged
Conversation
kateinoigakukun
approved these changes
Jun 8, 2026
A Wasm i64 parameter or return value is represented as a JavaScript BigInt. The generated JS used a plain 0 as the placeholder for the absent case of an optional i64 parameter (isSome ? v : 0) and for the error-path return of an imported thunk, so calling such an export with null (or an imported i64 function throwing) raised "TypeError: Cannot convert 0 to a BigInt". Emit 0n for i64 in both placeholders (jsZeroLiteral and the imported-thunk return placeholder). This was latent because the optional Int64/UInt64 round-trip tests never exercised the none case; add those assertions.
bbd2500 to
7aef830
Compare
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 Wasm
i64parameter or return value is represented as a JavaScriptBigInt. The generated JS, however, used a plain0as the placeholder for two cases:i64parameter when lowering a call into a Wasm export (isSome ? v : 0).catchblock after an exception is recorded).Passing a plain number
0where the Wasm boundary expects ani64raisesTypeError: Cannot convert 0 to a BigInt. So calling an export with an optionalInt64/UInt64argument ofnull, or having an importedi64-returning function throw, crashed:The fix emits
0nfori64in both placeholder paths (the optional-parameter zero literal and the imported-thunk return placeholder); other core types are unchanged.This was latent because the optional
Int64/UInt64round-trip tests only ever exercised the present case. The PR adds thenoneassertions that reproduce and lock down the fix.This is the last in a short series of small, focused ABI fixes (optional
@JS structimports, case-enum imports, and now thei64BigInt placeholder) that together unblock complete async support for non-ConvertibleToJSValuereturn types across all bridged stack types.