Skip to content

ArrayBuffer support to Java TurboModules#57062

Open
paradowstack wants to merge 5 commits into
facebook:mainfrom
paradowstack:feat/array-buffers-java
Open

ArrayBuffer support to Java TurboModules#57062
paradowstack wants to merge 5 commits into
facebook:mainfrom
paradowstack:feat/array-buffers-java

Conversation

@paradowstack
Copy link
Copy Markdown
Contributor

@paradowstack paradowstack commented Jun 3, 2026

Summary

Adds ArrayBuffer support to Java/Kotlin TurboModules, following the C++ ArrayBuffer PR (#56729) and the ObjC ArrayBuffer PR (#56986).

  • Codegen support for ArrayBufferTypeAnnotation in Java module specs (java.nio.ByteBuffer params/returns, ArrayBufferKind in JNI host functions.
  • JMutableDataBufferjsi::MutableBuffer backed by a direct ByteBuffer for zero-copy ArrayBuffer return to JS (with ThreadScope in the destructor for Hermes GC finalization)
  • JZeroCopyByteBufferHolder — retains a native jsi::MutableBuffer while JNI passes a zero-copy ByteBuffer view into Java
  • Three-path JSI↔Java conversion in JavaTurboModule: native-backed zero-copy (holder + view), sync JS-backed borrow (JByteBuffer::wrapBytes), async copy (allocateDirect + memcpy)
  • Sync vs async strategy matches ObjC/C++: isSync when return type is not void / Promise (VoidKind / PromiseKind copy JS-heap inputs; sync methods may borrow for the duration of the call)
  • CxxCallbackImpl fast path for a single direct ByteBuffer on Promise.resolve / Callback.invoke (bypasses folly::dynamic); CxxCallbackRejectImpl for reject-only callbacks

This PR touches some Objective-C++ parts only to get the project building. As soon as Objective-C++ work lands, this PR will be rebased.

Changelog:

[ANDROID] [ADDED] - Add ArrayBuffer support to Java TurboModules

Test plan

  • Codegen: Jest snapshot tests updated for array_buffer_native_module (GenerateModuleJavaSpec, GenerateModuleJniCpp, GenerateModuleJniH)
  • rn-tester (Android): getArrayBuffer, createNativeBuffer, processAsyncBuffer, getAsyncBuffer on NativeSampleTurboModule (SampleTurboModuleExample.js)
  • C++ bridging behavior unchanged; covered by existing BridgingTest.cpp ArrayBuffer / AsyncArrayBuffer tests from the C++ PR

@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 Jun 3, 2026
@facebook-github-tools facebook-github-tools Bot added p: Callstack Partner: Callstack Partner labels Jun 3, 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 Jun 3, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Jun 3, 2026

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

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.

1 participant