Use NSData for the JS->ObjC ArrayBuffer argument path#57596
Open
christophpurrer wants to merge 1 commit into
Open
Use NSData for the JS->ObjC ArrayBuffer argument path#57596christophpurrer wants to merge 1 commit into
christophpurrer wants to merge 1 commit into
Conversation
Summary: 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] Differential Revision: D112582384
|
@christophpurrer has exported this pull request. If you are a Meta employee, you can view the originating Diff in D112582384. |
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:
The original implementation used
NSMutableDatafor both directions of theJSI<->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
NSMutableDatamust own a resizable backing store it canrealloc/free, so it cannot durably alias a foreign buffer.This diff keeps
NSMutableDatafor the ObjC/Native -> JS (return) path, butswitches the JS -> ObjC/Native (argument) path to the immutable
NSData:getParamObjCTypenow mapsArrayBufferTypeAnnotationparams toNSData *(return type staysNSMutableData *).convertJSIArrayBufferToNSMutableDatais renamed toconvertJSIArrayBufferToNSDataand returns an immutableNSData. The bytesare 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.GenerateModuleHObjCppsnapshot.Changelog: [INTERNAL]
Differential Revision: D112582384