Add ArrayBuffer support for React Native TurboModules - copies data between JavaScript and native (#56689)#56689
Open
christophpurrer wants to merge 1 commit intofacebook:mainfrom
Open
Conversation
|
@christophpurrer has exported this pull request. If you are a Meta employee, you can view the originating Diff in D95649873. |
christophpurrer
added a commit
to christophpurrer/react-native-macos
that referenced
this pull request
May 5, 2026
…etween JavaScript and native (facebook#56689) Summary: Pull Request resolved: facebook#56689 ## Changelog: [General] [Added] - Add ArrayBuffer support for React Native Turbo Modules react-native-community/discussions-and-proposals#947 Adds first-class `ArrayBuffer` support across the entire TurboModule pipeline, enabling efficient binary data transfer between JavaScript and native code without base64 encoding overhead. **Schema & Parser:** - Added `NativeModuleArrayBufferTypeAnnotation` to `CodegenSchema.js` and `.d.ts` - Added `emitArrayBuffer` to `parsers-primitives.js` type map **C++ (Bridging & Generator):** - Added `ArrayBufferKind` to `TurboModuleMethodValueKind` enum - Created `ArrayBuffer.h` bridging header with `OwnedMutableBuffer` and `Bridging<std::vector<uint8_t>>` - Added `jsi::ArrayBuffer` conversion operators to `Convert.h` - Mapped `ArrayBufferTypeAnnotation` → `jsi::ArrayBuffer` in `GenerateModuleH.js` **Android (Java/JNI):** - Mapped `ArrayBufferTypeAnnotation` → `java.nio.ByteBuffer` in Java spec generator - Mapped to `Ljava/nio/ByteBuffer;` JNI signature in JNI generator - Added `ByteBuffer` arg/return handling in `JavaTurboModule.cpp` via `NewDirectByteBuffer`/`GetDirectBufferAddress` **iOS (ObjC):** - Mapped `ArrayBufferTypeAnnotation` → `NSData *` in ObjC spec generator - Added ArrayBuffer→NSData conversion in `convertJSIValueToObjCObject()` - Added NSData→ArrayBuffer conversion in `convertReturnIdToJSIValue()` **Flow-Schema:** - Added `ArrayBuffer` to `JAVASCRIPT_BUILTINS` in `BoundaryTypes.js` **Tests:** - Added Flow and TypeScript parser fixtures (`NATIVE_MODULE_WITH_ARRAYBUFFER`) - Added generator schema fixture (`ARRAYBUFFER_MODULE`) - Added `emitArrayBuffer` unit tests Differential Revision: D95649873
1a57ca3 to
523dd41
Compare
…etween JavaScript and native (facebook#56689) Summary: Pull Request resolved: facebook#56689 ## Changelog: [General] [Added] - Add ArrayBuffer support for React Native Turbo Modules react-native-community/discussions-and-proposals#947 Adds first-class `ArrayBuffer` support across the entire TurboModule pipeline, enabling efficient binary data transfer between JavaScript and native code without base64 encoding overhead. **Schema & Parser:** - Added `NativeModuleArrayBufferTypeAnnotation` to `CodegenSchema.js` and `.d.ts` - Added `emitArrayBuffer` to `parsers-primitives.js` type map **C++ (Bridging & Generator):** - Added `ArrayBufferKind` to `TurboModuleMethodValueKind` enum - Created `ArrayBuffer.h` bridging header with `OwnedMutableBuffer` and `Bridging<std::vector<uint8_t>>` - Added `jsi::ArrayBuffer` conversion operators to `Convert.h` - Mapped `ArrayBufferTypeAnnotation` → `jsi::ArrayBuffer` in `GenerateModuleH.js` **Android (Java/JNI):** - Mapped `ArrayBufferTypeAnnotation` → `java.nio.ByteBuffer` in Java spec generator - Mapped to `Ljava/nio/ByteBuffer;` JNI signature in JNI generator - Added `ByteBuffer` arg/return handling in `JavaTurboModule.cpp` via `NewDirectByteBuffer`/`GetDirectBufferAddress` **iOS (ObjC):** - Mapped `ArrayBufferTypeAnnotation` → `NSData *` in ObjC spec generator - Added ArrayBuffer→NSData conversion in `convertJSIValueToObjCObject()` - Added NSData→ArrayBuffer conversion in `convertReturnIdToJSIValue()` **Flow-Schema:** - Added `ArrayBuffer` to `JAVASCRIPT_BUILTINS` in `BoundaryTypes.js` **Tests:** - Added Flow and TypeScript parser fixtures (`NATIVE_MODULE_WITH_ARRAYBUFFER`) - Added generator schema fixture (`ARRAYBUFFER_MODULE`) - Added `emitArrayBuffer` unit tests Differential Revision: D95649873
523dd41 to
df904d3
Compare
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.
Summary:
Changelog:
[General] [Added] - Add ArrayBuffer support for React Native Turbo Modules
react-native-community/discussions-and-proposals#947
Adds first-class
ArrayBuffersupport across the entire TurboModule pipeline, enabling efficient binary data transfer between JavaScript and native code without base64 encoding overhead.Schema & Parser:
NativeModuleArrayBufferTypeAnnotationtoCodegenSchema.jsand.d.tsemitArrayBuffertoparsers-primitives.jstype mapC++ (Bridging & Generator):
ArrayBufferKindtoTurboModuleMethodValueKindenumArrayBuffer.hbridging header withOwnedMutableBufferandBridging<std::vector<uint8_t>>jsi::ArrayBufferconversion operators toConvert.hArrayBufferTypeAnnotation→jsi::ArrayBufferinGenerateModuleH.jsAndroid (Java/JNI):
ArrayBufferTypeAnnotation→java.nio.ByteBufferin Java spec generatorLjava/nio/ByteBuffer;JNI signature in JNI generatorByteBufferarg/return handling inJavaTurboModule.cppviaNewDirectByteBuffer/GetDirectBufferAddressiOS (ObjC):
ArrayBufferTypeAnnotation→NSData *in ObjC spec generatorconvertJSIValueToObjCObject()convertReturnIdToJSIValue()Flow-Schema:
ArrayBuffertoJAVASCRIPT_BUILTINSinBoundaryTypes.jsTests:
NATIVE_MODULE_WITH_ARRAYBUFFER)ARRAYBUFFER_MODULE)emitArrayBufferunit testsDifferential Revision: D95649873