Files
react-native/packages/react-native-codegen
Christoph Purrer 5e86c323ce Use NSData for the JS->ObjC ArrayBuffer argument path (#57596)
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/57596

The original implementation used `NSMutableData` for both directions of the
JSI<->ObjC ArrayBuffer conversion. That is the wrong contract on the argument
(JS -> ObjC/Native) side: an inbound buffer is owned by the caller, not the
native module, and `NSMutableData` must own a resizable backing store it can
`realloc`/`free`, so it cannot durably alias a foreign buffer.

This diff keeps `NSMutableData` for the ObjC/Native -> JS (return) path, but
switches the JS -> ObjC/Native (argument) path to the immutable `NSData`:

- Codegen: `getParamObjCType` now maps `ArrayBufferTypeAnnotation` params to
  `NSData *` (return type stays `NSMutableData *`).
- Runtime: `convertJSIArrayBufferToNSMutableData` is renamed to
  `convertJSIArrayBufferToNSData` and returns an immutable `NSData`. The bytes
  are still eagerly copied, which keeps the result safe to retain, store, or
  dispatch to another thread regardless of whether the source bytes were owned
  by JS or by a native `MutableBuffer`.
- Updated the ObjC unit tests and the codegen `GenerateModuleHObjCpp` snapshot.

Changelog: [INTERNAL]

Reviewed By: javache

Differential Revision: D112582384

fbshipit-source-id: 8ed2dfb3f23e7f39677dfb1824c5530f378705bc
2026-07-21 11:46:04 -07:00
..

@react-native/codegen

npm npm downloads

Code generation tools for React Native. Parses TypeScript and Flow NativeModule and Component specs and generates the native binding code used by the New Architecture.