Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

BridgeJS: Normalize wasm pointer offsets in JS#768

Merged
krodak merged 1 commit into
swiftwasm:mainswiftwasm/JavaScriptKit:mainfrom
PassiveLogic:fix/bridgejs-pointer-limitationsPassiveLogic/JavaScriptKit:fix/bridgejs-pointer-limitationsCopy head branch name to clipboard
Jun 12, 2026
Merged

BridgeJS: Normalize wasm pointer offsets in JS#768
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

@krodak

@krodak krodak commented Jun 12, 2026

Copy link
Copy Markdown
Member

Overview

This PR fixes signed i32 pointer handling at the Swift-to-JavaScript boundary. WebAssembly pointers can legally point above the 2 GiB line, but the JS API exposes i32 values as signed numbers. When generated BridgeJS glue or runtime helpers used those signed values directly as typed-array or DataView offsets, pointers above 0x7fff_ffff could become negative and fail with an out-of-bounds RangeError.

The change normalizes pointer offsets with >>> 0 before 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 creating Uint8Array views. Swift heap object wrappers normalize pointers before storing or looking up identity-cache entries.

2. Runtime helpers

Runtime DataView and 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.

@krodak krodak self-assigned this Jun 12, 2026
@krodak krodak requested a review from kateinoigakukun June 12, 2026 11:55
Comment thread Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSLinkTests.swift Outdated
Comment thread Runtime/test/pointer-normalization.test.ts
@krodak krodak force-pushed the fix/bridgejs-pointer-limitations branch 2 times, most recently from 70acd64 to c5e5a2c Compare June 12, 2026 12:28
@krodak krodak force-pushed the fix/bridgejs-pointer-limitations branch from c5e5a2c to e3315ec Compare June 12, 2026 12:44
@krodak krodak merged commit fba3be0 into swiftwasm:main Jun 12, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.