mirror of
https://github.com/react/react-native.git
synced 2026-09-28 05:13:06 +08:00
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