Skip to content

ArrayBuffer support to ObjC TurboModules #56986

Open
paradowstack wants to merge 6 commits into
react:mainfrom
paradowstack:feat/array-buffers-objc
Open

ArrayBuffer support to ObjC TurboModules #56986
paradowstack wants to merge 6 commits into
react:mainfrom
paradowstack:feat/array-buffers-objc

Conversation

@paradowstack

Copy link
Copy Markdown
Contributor

Summary:

Adds ArrayBuffer support to ObjC TurboModules, following the C++ ArrayBuffer PR (226ef2e).

  • Codegen support for ArrayBufferTypeAnnotation in ObjC module specs (NSMutableData * params/returns, new ArrayBufferKind)
  • RCTZeroCopyDataNSMutableData subclass for wrapping external memory without copying
  • Three-path JSI↔ObjC conversion: native-backed zero-copy, sync JS-backed borrow, async copy
  • isSync flag threaded through the invocation path to select the correct conversion strategy; defaults to NO (safe copy) for call sites outside the TurboModule dispatch path

Android support will follow in a separate PR. This PR touches some Java parts only to get the project building.

Changelog:

[IOS] [ADDED] - Add ArrayBuffer support to ObjC TurboModules

Test Plan:

  • New unit tests in RCTTurboModuleArrayBufferTests.mm
  • rn-tester: getArrayBuffer, createNativeBuffer, processAsyncBuffer, getAsyncBuffer added to NativeSampleTurboModule

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 28, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label May 28, 2026
@meta-codesync

meta-codesync Bot commented May 29, 2026

Copy link
Copy Markdown

@christophpurrer has imported this pull request. If you are a Meta employee, you can view this in D106846249.

meta-codesync Bot pushed a commit that referenced this pull request Jun 28, 2026
Summary:
Adds ArrayBuffer support to ObjC TurboModules, following the C++ ArrayBuffer PR ([`226ef2e`](226ef2e)).

- Codegen support for `ArrayBufferTypeAnnotation` in ObjC module specs (`NSMutableData *` params/returns, new `ArrayBufferKind`)
- JSI↔ObjC conversion wraps native-backed buffers zero-copy via `-[NSMutableData initWithBytesNoCopy:length:deallocator:]`; the deallocator retains the backing store so the bytes stay valid even if the `NSMutableData` escapes the call or the source ArrayBuffer is garbage-collected
- JS-backed buffers are copied, which is safe on both the synchronous and asynchronous paths

This PR is iOS-only; Android support follows in a separate PR.

## Changelog:

[IOS] [ADDED] - Add ArrayBuffer support to ObjC TurboModules

X-link: #56986

Reviewed By: javache

Differential Revision: D106846249

Pulled By: christophpurrer

fbshipit-source-id: 3393d5d6f31a1412f5d52328c90e51205aa6b153
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Callstack Partner: Callstack Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants