BridgeJS: Normalize wasm pointer offsets in JS#768
Merged
krodak merged 1 commit intoJun 12, 2026
swiftwasm:mainswiftwasm/JavaScriptKit:mainfrom
PassiveLogic:fix/bridgejs-pointer-limitationsPassiveLogic/JavaScriptKit:fix/bridgejs-pointer-limitationsCopy head branch name to clipboard
Merged
BridgeJS: Normalize wasm pointer offsets in JS#768krodak merged 1 commit intoswiftwasm:mainswiftwasm/JavaScriptKit:mainfrom PassiveLogic:fix/bridgejs-pointer-limitationsPassiveLogic/JavaScriptKit:fix/bridgejs-pointer-limitationsCopy head branch name to clipboard
krodak merged 1 commit into
swiftwasm:mainswiftwasm/JavaScriptKit:mainfrom
PassiveLogic:fix/bridgejs-pointer-limitationsPassiveLogic/JavaScriptKit:fix/bridgejs-pointer-limitationsCopy head branch name to clipboard
Conversation
70acd64 to
c5e5a2c
Compare
c5e5a2c to
e3315ec
Compare
kateinoigakukun
approved these changes
Jun 12, 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
This PR fixes signed
i32pointer handling at the Swift-to-JavaScript boundary. WebAssembly pointers can legally point above the 2 GiB line, but the JS API exposesi32values as signed numbers. When generated BridgeJS glue or runtime helpers used those signed values directly as typed-array orDataViewoffsets, pointers above0x7fff_ffffcould become negative and fail with an out-of-boundsRangeError.The change normalizes pointer offsets with
>>> 0before using them to index WebAssembly linear memory. It also canonicalizes Swift heap object wrapper identity keys so signed and unsigned representations of the same pointer do not miss the identity cache.1. BridgeJS generated glue
Generated
swift_js_init_memory,swift_js_init_memory_with_result, and released-closure debug paths now unsigned-normalize pointer inputs before creatingUint8Arrayviews. Swift heap object wrappers normalize pointers before storing or looking up identity-cache entries.2. Runtime helpers
Runtime
DataViewand typed-array helper paths now unsigned-normalize pointer offsets before reading or writing memory. This covers JSValue array decoding, object-ref decoding, result payload writes, string loading/decoding, and typed-array creation/loading.