Skip to content

BridgeJS: Normalize pointer in swift_js_push_typed_array - #828

Merged
kateinoigakukun merged 1 commit into
swiftwasm:mainfrom
PassiveLogic:kr/bridgejs-push-typed-array-pointer
Nov 7, 2026
Merged

kateinoigakukun merged 1 commit into
swiftwasm:mainfrom
PassiveLogic:kr/bridgejs-push-typed-array-pointer

Conversation

@krodak

@krodak krodak commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Overview

Follow-up to #768, which normalized wasm pointer offsets with >>> 0 in the generated BridgeJS glue. It missed one site: swift_js_push_typed_array, added by #745, which copies a Swift numeric array out of linear memory into a JS array.

Once memory grows past 2 GiB, ptr arrives as a negative i32. ArrayBuffer.slice treats a negative index as an offset from the end of the buffer, so the copy reads the wrong bytes and JS silently gets wrong values. This PR normalizes ptr before the slice.

Before:

const copy = memory.buffer.slice(ptr, ptr + byteLen);

After:

const start = ptr >>> 0;
const copy = memory.buffer.slice(start, start + byteLen);

@krodak krodak self-assigned this Nov 6, 2026

@kateinoigakukun kateinoigakukun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! This was the last pointer offset in the generated glue that wasn't normalized.

@kateinoigakukun
kateinoigakukun enabled auto-merge (squash) November 7, 2026 07:27
@kateinoigakukun
kateinoigakukun merged commit 0a1c5a8 into swiftwasm:main Nov 7, 2026
16 checks passed
@krodak

krodak commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Yeah, missed tytanowe initially 😅

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