mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Revert "RCTArrayBuffer zero-copy class for ObjC TM (#57879)"
This reverts commit 11f9a7f449.
# Conflicts:
# packages/react-native/ReactCommon/react/nativemodule/core/iostests/RCTTurboModuleTests.mm
# packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm
This commit is contained in:
1 parent
f2439a83cf
commit
639cdedb50
16 files changed
+150
-626
No files matched your search
-2
@@ -26,7 +26,6 @@ exports[`GenerateModuleObjCpp can generate a header file NativeModule specs 1`]
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
@@ -1579,7 +1578,6 @@ exports[`GenerateModuleObjCpp can generate a header file NativeModule specs with
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
|
||||
-1
@@ -97,7 +97,6 @@ const HeaderFileTemplate = ({
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
|
||||
Vendored
+2
-2
@@ -227,7 +227,7 @@ function getParamObjCType(
|
||||
return notStruct(wrapOptional('NSArray *', !nullable));
|
||||
}
|
||||
case 'ArrayBufferTypeAnnotation': {
|
||||
return notStruct(wrapOptional('RCTArrayBuffer *', !nullable));
|
||||
return notStruct(wrapOptional('NSData *', !nullable));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ function getReturnObjCType(
|
||||
case 'GenericObjectTypeAnnotation':
|
||||
return wrapOptional('NSDictionary *', isRequired);
|
||||
case 'ArrayBufferTypeAnnotation':
|
||||
return wrapOptional('RCTArrayBuffer *', isRequired);
|
||||
return wrapOptional('NSMutableData *', isRequired);
|
||||
default:
|
||||
typeAnnotation.type as 'MixedTypeAnnotation';
|
||||
throw new Error(
|
||||
|
||||
+3
-16
@@ -27,7 +27,6 @@ Map {
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
@@ -93,7 +92,6 @@ Map {
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
@@ -104,9 +102,9 @@ Map {
|
||||
|
||||
@protocol NativeSampleTurboModuleSpec <RCTBridgeModule, RCTTurboModule>
|
||||
|
||||
- (RCTArrayBuffer *)getArrayBuffer;
|
||||
- (void)voidArrayBuffer:(RCTArrayBuffer *)arg;
|
||||
- (void)voidNullableArrayBuffer:(RCTArrayBuffer * _Nullable)arg;
|
||||
- (NSMutableData *)getArrayBuffer;
|
||||
- (void)voidArrayBuffer:(NSData *)arg;
|
||||
- (void)voidNullableArrayBuffer:(NSData * _Nullable)arg;
|
||||
|
||||
@end
|
||||
|
||||
@@ -161,7 +159,6 @@ Map {
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
@@ -203,7 +200,6 @@ Map {
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
@@ -479,7 +475,6 @@ Map {
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
@@ -521,7 +516,6 @@ Map {
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
@@ -587,7 +581,6 @@ Map {
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
@@ -661,7 +654,6 @@ Map {
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
@@ -847,7 +839,6 @@ Map {
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
@@ -1116,7 +1107,6 @@ Map {
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
@@ -1246,7 +1236,6 @@ Map {
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
@@ -1312,7 +1301,6 @@ Map {
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
@@ -1404,7 +1392,6 @@ Map {
|
||||
#import <RCTRequired/RCTRequired.h>
|
||||
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
||||
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
* A fixed-length byte buffer shared between JS `ArrayBuffer`s and ObjC TurboModules. Fixed
|
||||
* length lets the backing store alias JS memory; `NSMutableData` cannot do that.
|
||||
*
|
||||
* `isOwningBytes`:
|
||||
* - `YES` — safe to retain and use from any thread (synchronize if aliasing JS
|
||||
* memory).
|
||||
* - `NO` — valid only during the synchronous call on the calling thread; copy with
|
||||
* `arrayBufferWithCopiedBytes:length:` to keep the bytes.
|
||||
*/
|
||||
@interface RCTArrayBuffer : NSObject
|
||||
|
||||
/**
|
||||
* NULL when `length` is 0, non-NULL otherwise, matching `NSData.bytes`.
|
||||
*/
|
||||
@property (nonatomic, readonly, nullable) void *mutableBytes NS_RETURNS_INNER_POINTER;
|
||||
|
||||
@property (nonatomic, readonly) NSUInteger length;
|
||||
|
||||
/** Whether the buffer owns its bytes. See the class comment. */
|
||||
@property (nonatomic, readonly, getter=isOwningBytes) BOOL owningBytes;
|
||||
|
||||
/**
|
||||
* A new zero-filled owning buffer.
|
||||
*/
|
||||
+ (instancetype)arrayBufferWithLength:(NSUInteger)length;
|
||||
|
||||
/**
|
||||
* A new owning buffer holding a copy of `bytes`. Passing NULL zero-fills.
|
||||
*/
|
||||
+ (instancetype)arrayBufferWithCopiedBytes:(const void *_Nullable)bytes length:(NSUInteger)length;
|
||||
|
||||
/**
|
||||
* An owning buffer aliasing `bytes` without copying. If `cleanup` is non-nil, it runs on dealloc,
|
||||
* like `-[NSData dataWithBytesNoCopy:length:freeWhenDone:YES]`; if nil, the caller must keep
|
||||
* `bytes` valid until dealloc. NULL `bytes` with non-zero `length` raises NSInvalidArgumentException.
|
||||
*/
|
||||
+ (instancetype)arrayBufferWithOwnedBytes:(nullable void *)bytes
|
||||
length:(NSUInteger)length
|
||||
cleanup:(nullable void (^)(void))cleanup;
|
||||
|
||||
/**
|
||||
* A non-owning, zero-copy alias of `bytes`. See the class comment for lifetime rules. NULL `bytes`
|
||||
* with non-zero `length` raises NSInvalidArgumentException.
|
||||
*/
|
||||
+ (instancetype)arrayBufferWithUnownedBytes:(nullable void *)bytes length:(NSUInteger)length;
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
+ (instancetype)new NS_UNAVAILABLE;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "RCTArrayBuffer.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@interface RCTArrayBuffer ()
|
||||
|
||||
- (instancetype)initWithBytesNoCopy:(nullable void *)bytes
|
||||
length:(NSUInteger)length
|
||||
owningBytes:(BOOL)owningBytes
|
||||
cleanup:(nullable void (^)(void))cleanup NS_DESIGNATED_INITIALIZER;
|
||||
- (instancetype)initWithCopiedBytes:(const void *_Nullable)bytes length:(NSUInteger)length;
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTArrayBuffer {
|
||||
void *_bytes;
|
||||
NSUInteger _length;
|
||||
BOOL _owningBytes;
|
||||
void (^_cleanup)(void);
|
||||
std::vector<uint8_t> _copiedBytes;
|
||||
}
|
||||
|
||||
#pragma mark - Initializers
|
||||
|
||||
- (instancetype)initWithBytesNoCopy:(void *)bytes
|
||||
length:(NSUInteger)length
|
||||
owningBytes:(BOOL)owningBytes
|
||||
cleanup:(void (^)(void))cleanup
|
||||
{
|
||||
if (bytes == NULL && length != 0) {
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"RCTArrayBuffer: NULL bytes with length %lu", (unsigned long)length];
|
||||
}
|
||||
|
||||
if (self = [super init]) {
|
||||
_bytes = bytes;
|
||||
_length = length;
|
||||
_owningBytes = owningBytes;
|
||||
_cleanup = [cleanup copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCopiedBytes:(const void *)bytes length:(NSUInteger)length
|
||||
{
|
||||
if (length == 0) {
|
||||
return [self initWithBytesNoCopy:NULL length:0 owningBytes:YES cleanup:nil];
|
||||
}
|
||||
|
||||
std::vector<uint8_t> copy(length);
|
||||
if (bytes != NULL) {
|
||||
std::memcpy(copy.data(), bytes, length);
|
||||
}
|
||||
|
||||
// Moving a vector hands over its heap buffer, so `data()` stays valid in `_copiedBytes`.
|
||||
if (self = [self initWithBytesNoCopy:copy.data() length:length owningBytes:YES cleanup:nil]) {
|
||||
_copiedBytes = std::move(copy);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (instancetype)arrayBufferWithLength:(NSUInteger)length
|
||||
{
|
||||
return [[self alloc] initWithCopiedBytes:NULL length:length];
|
||||
}
|
||||
|
||||
+ (instancetype)arrayBufferWithCopiedBytes:(const void *)bytes length:(NSUInteger)length
|
||||
{
|
||||
return [[self alloc] initWithCopiedBytes:bytes length:length];
|
||||
}
|
||||
|
||||
+ (instancetype)arrayBufferWithOwnedBytes:(void *)bytes
|
||||
length:(NSUInteger)length
|
||||
cleanup:(nullable void (^)(void))cleanup
|
||||
{
|
||||
return [[self alloc] initWithBytesNoCopy:bytes length:length owningBytes:YES cleanup:cleanup];
|
||||
}
|
||||
|
||||
+ (instancetype)arrayBufferWithUnownedBytes:(void *)bytes length:(NSUInteger)length
|
||||
{
|
||||
return [[self alloc] initWithBytesNoCopy:bytes length:length owningBytes:NO cleanup:nil];
|
||||
}
|
||||
|
||||
#pragma mark - Accessors
|
||||
|
||||
- (void *)mutableBytes
|
||||
{
|
||||
return _bytes;
|
||||
}
|
||||
|
||||
- (NSUInteger)length
|
||||
{
|
||||
return _length;
|
||||
}
|
||||
|
||||
- (BOOL)isOwningBytes
|
||||
{
|
||||
return _owningBytes;
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"<%@: %p; length = %lu; owningBytes = %@>",
|
||||
NSStringFromClass([self class]),
|
||||
self,
|
||||
(unsigned long)_length,
|
||||
_owningBytes ? @"YES" : @"NO"];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
if (_cleanup != nil) {
|
||||
_cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
+16
-64
@@ -7,10 +7,8 @@
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <ReactCommon/RCTTurboModule.h>
|
||||
#import <hermes/hermes.h>
|
||||
#import <jsi/decorator.h>
|
||||
#import <react/featureflags/ReactNativeFeatureFlags.h>
|
||||
#import <react/featureflags/ReactNativeFeatureFlagsDefaults.h>
|
||||
|
||||
@@ -94,39 +92,6 @@ class TestMutableBuffer : public facebook::jsi::MutableBuffer {
|
||||
std::vector<uint8_t> bytes_;
|
||||
};
|
||||
|
||||
// `jsi::Runtime::tryGetMutableBuffer` is optional — the Hermes branch linked into apps returns
|
||||
// nullptr for every ArrayBuffer — so decorate the runtime to answer it for the buffers created
|
||||
// through it. That keeps the coverage of the native-backed path independent of the engine.
|
||||
// The registry is weak, so the only owners of a backing store remain the JS ArrayBuffer and
|
||||
// whatever the conversion retains.
|
||||
class MutableBufferAwareRuntime final : public facebook::jsi::RuntimeDecorator<facebook::jsi::Runtime> {
|
||||
public:
|
||||
explicit MutableBufferAwareRuntime(facebook::jsi::Runtime &plain) : RuntimeDecorator(plain) {}
|
||||
|
||||
facebook::jsi::ArrayBuffer createArrayBuffer(std::shared_ptr<facebook::jsi::MutableBuffer> buffer) override
|
||||
{
|
||||
auto arrayBuffer = RuntimeDecorator::createArrayBuffer(buffer);
|
||||
buffers_.push_back(buffer);
|
||||
return arrayBuffer;
|
||||
}
|
||||
|
||||
std::shared_ptr<facebook::jsi::MutableBuffer> tryGetMutableBuffer(
|
||||
const facebook::jsi::ArrayBuffer &arrayBuffer) override
|
||||
{
|
||||
uint8_t *data = arrayBuffer.data(*this);
|
||||
for (const auto &weakBuffer : buffers_) {
|
||||
auto buffer = weakBuffer.lock();
|
||||
if (buffer != nullptr && buffer->data() == data) {
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::weak_ptr<facebook::jsi::MutableBuffer>> buffers_;
|
||||
};
|
||||
|
||||
class StubNativeMethodCallInvoker : public NativeMethodCallInvoker {
|
||||
public:
|
||||
void invokeAsync(const std::string &methodName, NativeMethodCallFunc &&func) noexcept override
|
||||
@@ -354,46 +319,33 @@ class ExceptionCapturingNativeMethodCallInvoker : public NativeMethodCallInvoker
|
||||
XCTAssertNotNil(original.callStackSymbols);
|
||||
}
|
||||
|
||||
// A native-backed ArrayBuffer is aliased rather than copied, and the RCTArrayBuffer retains
|
||||
// the backing MutableBuffer, so the alias outlives the JS object.
|
||||
- (void)testNativeBackedArrayBufferIsAliasedAndKeepsBackingStoreAlive
|
||||
// A JS ArrayBuffer converts (on the argument path) to an immutable NSData that
|
||||
// owns an independent copy of the bytes, so the result stays valid after the
|
||||
// source buffer is gone. This covers the ArrayBuffer-backed-by-native-MutableBuffer
|
||||
// case, which is the one that could in principle have been aliased zero-copy.
|
||||
- (void)testArrayBufferConvertsToIndependentNSData
|
||||
{
|
||||
constexpr size_t kBufferSize = 64 * 1024;
|
||||
|
||||
auto hermesRuntime = facebook::hermes::makeHermesRuntime();
|
||||
MutableBufferAwareRuntime runtime(*hermesRuntime);
|
||||
facebook::jsi::Runtime *rt = hermesRuntime.get();
|
||||
|
||||
auto buffer = std::make_shared<TestMutableBuffer>(kBufferSize);
|
||||
*buffer->data() = 0xAB;
|
||||
const uint8_t *sourceBytes = buffer->data();
|
||||
|
||||
RCTArrayBuffer *converted = nil;
|
||||
{
|
||||
facebook::jsi::ArrayBuffer arrayBuffer(runtime, buffer);
|
||||
const long ownersBeforeConversion = buffer.use_count();
|
||||
facebook::jsi::ArrayBuffer arrayBuffer(*rt, buffer);
|
||||
id converted =
|
||||
TurboModuleConvertUtils::convertJSIValueToObjCObject(*rt, facebook::jsi::Value(*rt, arrayBuffer), nullptr);
|
||||
|
||||
id result = TurboModuleConvertUtils::convertJSIValueToObjCObject(
|
||||
runtime, facebook::jsi::Value(runtime, arrayBuffer), nullptr, NO, NO);
|
||||
XCTAssertTrue([result isKindOfClass:[RCTArrayBuffer class]]);
|
||||
converted = (RCTArrayBuffer *)result;
|
||||
XCTAssertTrue([converted isKindOfClass:[NSData class]]);
|
||||
NSData *data = (NSData *)converted;
|
||||
XCTAssertEqual(data.length, (NSUInteger)kBufferSize);
|
||||
XCTAssertEqual(*static_cast<const uint8_t *>(data.bytes), 0xAB);
|
||||
|
||||
XCTAssertEqual(
|
||||
buffer.use_count(), ownersBeforeConversion + 1, @"The RCTArrayBuffer must retain the backing MutableBuffer");
|
||||
}
|
||||
|
||||
XCTAssertTrue(converted.isOwningBytes, @"A native-backed buffer must be safe to retain");
|
||||
XCTAssertEqual(converted.length, (NSUInteger)kBufferSize);
|
||||
XCTAssertEqual(converted.mutableBytes, (void *)sourceBytes, @"Bytes must be aliased, not copied");
|
||||
|
||||
// Writes through the source are visible, and vice versa: one shared allocation.
|
||||
// Independent copy: mutating the source MutableBuffer must not write through to
|
||||
// the NSData.
|
||||
*buffer->data() = 0xCD;
|
||||
XCTAssertEqual(*static_cast<const uint8_t *>(converted.mutableBytes), 0xCD);
|
||||
*static_cast<uint8_t *>(converted.mutableBytes) = 0xEF;
|
||||
XCTAssertEqual(*buffer->data(), 0xEF);
|
||||
|
||||
// Dropping the caller's reference leaves the bytes valid.
|
||||
buffer.reset();
|
||||
XCTAssertEqual(*static_cast<const uint8_t *>(converted.mutableBytes), 0xEF);
|
||||
XCTAssertEqual(*static_cast<const uint8_t *>(data.bytes), 0xAB, @"NSData must not alias the source buffer");
|
||||
}
|
||||
|
||||
@end
|
||||
+1
-2
@@ -75,8 +75,7 @@ class JSI_EXPORT ObjCInteropTurboModule : public ObjCTurboModule {
|
||||
const jsi::Value &arg,
|
||||
size_t i,
|
||||
NSInvocation *inv,
|
||||
NSMutableArray *retainedObjectsForInvocation,
|
||||
bool mustCopyBytes) override;
|
||||
NSMutableArray *retainedObjectsForInvocation) override;
|
||||
|
||||
private:
|
||||
std::vector<MethodDescriptor> methodDescriptors_;
|
||||
|
||||
+1
-2
@@ -363,8 +363,7 @@ void ObjCInteropTurboModule::setInvocationArg(
|
||||
const jsi::Value &jsiArg,
|
||||
size_t index,
|
||||
NSInvocation *inv,
|
||||
NSMutableArray *retainedObjectsForInvocation,
|
||||
[[maybe_unused]] bool mustCopyBytes)
|
||||
NSMutableArray *retainedObjectsForInvocation)
|
||||
{
|
||||
NSString *methodName = @(methodNameCStr);
|
||||
std::string methodJsSignature = name_ + "." + methodNameCStr + "()";
|
||||
|
||||
+2
-9
@@ -35,8 +35,7 @@ id convertJSIValueToObjCObject(
|
||||
jsi::Runtime &runtime,
|
||||
const jsi::Value &value,
|
||||
const std::shared_ptr<CallInvoker> &jsInvoker,
|
||||
BOOL useNSNull = NO,
|
||||
BOOL mustCopyBytes = YES);
|
||||
BOOL useNSNull = NO);
|
||||
} // namespace TurboModuleConvertUtils
|
||||
|
||||
template <>
|
||||
@@ -114,9 +113,6 @@ class JSI_EXPORT ObjCTurboModule : public TurboModule {
|
||||
* ObjCInteropTurboModule relies heavily on RCTConvert to convert arguments from JavaScript values to Objective C
|
||||
* values. ObjCTurboModule tries to minimize reliance on RCTConvert: RCTConvert uses the RCT_EXPORT_METHOD macros,
|
||||
* which we want to remove long term from React Native.
|
||||
*
|
||||
* mustCopyBytes says whether the invocation may outlive the JS call, in which case ArrayBuffer arguments must be
|
||||
* copied rather than aliased.
|
||||
*/
|
||||
virtual void setInvocationArg(
|
||||
jsi::Runtime &runtime,
|
||||
@@ -125,8 +121,7 @@ class JSI_EXPORT ObjCTurboModule : public TurboModule {
|
||||
const jsi::Value &arg,
|
||||
size_t i,
|
||||
NSInvocation *inv,
|
||||
NSMutableArray *retainedObjectsForInvocation,
|
||||
bool mustCopyBytes);
|
||||
NSMutableArray *retainedObjectsForInvocation);
|
||||
|
||||
private:
|
||||
// Does the NativeModule dispatch async methods to the JS thread?
|
||||
@@ -142,13 +137,11 @@ class JSI_EXPORT ObjCTurboModule : public TurboModule {
|
||||
NSDictionary<NSString *, NSArray<NSString *> *> *methodArgumentTypeNames_;
|
||||
|
||||
bool isMethodSync(TurboModuleMethodValueKind returnType);
|
||||
bool mustCopyJSHeapArrayBufferBytes(TurboModuleMethodValueKind returnType);
|
||||
BOOL hasMethodArgConversionSelector(NSString *methodName, size_t argIndex);
|
||||
SEL getMethodArgConversionSelector(NSString *methodName, size_t argIndex);
|
||||
NSInvocation *createMethodInvocation(
|
||||
jsi::Runtime &runtime,
|
||||
bool isSync,
|
||||
bool mustCopyBytes,
|
||||
const char *methodName,
|
||||
SEL selector,
|
||||
const jsi::Value *args,
|
||||
|
||||
+32
-71
@@ -7,7 +7,6 @@
|
||||
|
||||
#import "RCTTurboModule.h"
|
||||
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTConvert.h>
|
||||
#import <React/RCTCxxConvert.h>
|
||||
@@ -90,43 +89,35 @@ static std::vector<jsi::Value> convertNSArrayToStdVector(jsi::Runtime &runtime,
|
||||
return result;
|
||||
}
|
||||
|
||||
static jsi::ArrayBuffer convertRCTArrayBufferToJSIArrayBuffer(jsi::Runtime &runtime, RCTArrayBuffer *value)
|
||||
static jsi::ArrayBuffer convertNSMutableDataToJSIArrayBuffer(jsi::Runtime &runtime, NSMutableData *value)
|
||||
{
|
||||
class RCTArrayBufferMutableBuffer final : public jsi::MutableBuffer {
|
||||
class NSMutableDataBuffer final : public jsi::MutableBuffer {
|
||||
public:
|
||||
explicit RCTArrayBufferMutableBuffer(RCTArrayBuffer *buffer)
|
||||
: buffer_(buffer), data_(static_cast<uint8_t *>(buffer.mutableBytes)), size_(buffer.length)
|
||||
{
|
||||
}
|
||||
explicit NSMutableDataBuffer(NSMutableData *data) : data_(data) {}
|
||||
|
||||
size_t size() const override
|
||||
{
|
||||
return size_;
|
||||
return data_.length;
|
||||
}
|
||||
|
||||
uint8_t *data() override
|
||||
{
|
||||
return data_;
|
||||
return static_cast<uint8_t *>(data_.mutableBytes);
|
||||
}
|
||||
|
||||
private:
|
||||
// Never read: retains the buffer so `data_` stays valid for the ArrayBuffer's lifetime.
|
||||
[[maybe_unused]] RCTArrayBuffer *buffer_;
|
||||
uint8_t *data_;
|
||||
size_t size_;
|
||||
NSMutableData *data_;
|
||||
};
|
||||
|
||||
// nil would yield a NULL pointer via ObjC nil-messaging and corrupt the ArrayBuffer.
|
||||
// A nil NSMutableData would silently yield a NULL `mutableBytes` pointer
|
||||
// (ObjC nil-messaging) and corrupt the resulting ArrayBuffer. Substitute a
|
||||
// fresh empty NSMutableData so the wrapped pointer is always well-defined.
|
||||
if (value == nil) {
|
||||
RCTLogWarn(@"convertRCTArrayBufferToJSIArrayBuffer: received nil RCTArrayBuffer; returning empty ArrayBuffer");
|
||||
value = [RCTArrayBuffer arrayBufferWithLength:0];
|
||||
RCTLogWarn(@"convertNSMutableDataToJSIArrayBuffer: received nil NSMutableData; returning empty ArrayBuffer");
|
||||
value = [NSMutableData data];
|
||||
}
|
||||
|
||||
if (!value.isOwningBytes) {
|
||||
value = [RCTArrayBuffer arrayBufferWithCopiedBytes:value.mutableBytes length:value.length];
|
||||
}
|
||||
|
||||
return {runtime, std::make_shared<RCTArrayBufferMutableBuffer>(value)};
|
||||
auto buffer = std::make_shared<NSMutableDataBuffer>(value);
|
||||
return {runtime, std::move(buffer)};
|
||||
}
|
||||
|
||||
jsi::Value convertObjCObjectToJSIValue(jsi::Runtime &runtime, id value)
|
||||
@@ -142,8 +133,8 @@ jsi::Value convertObjCObjectToJSIValue(jsi::Runtime &runtime, id value)
|
||||
return convertNSDictionaryToJSIObject(runtime, (NSDictionary *)value);
|
||||
} else if ([value isKindOfClass:[NSArray class]]) {
|
||||
return convertNSArrayToJSIArray(runtime, (NSArray *)value);
|
||||
} else if ([value isKindOfClass:[RCTArrayBuffer class]]) {
|
||||
return convertRCTArrayBufferToJSIArrayBuffer(runtime, (RCTArrayBuffer *)value);
|
||||
} else if ([value isKindOfClass:[NSMutableData class]]) {
|
||||
return convertNSMutableDataToJSIArrayBuffer(runtime, (NSMutableData *)value);
|
||||
} else if (value == (id)kCFNull) {
|
||||
return jsi::Value::null();
|
||||
}
|
||||
@@ -210,41 +201,22 @@ convertJSIFunctionToCallback(jsi::Runtime &rt, jsi::Function &&function, const s
|
||||
};
|
||||
}
|
||||
|
||||
// Native-backed buffers are aliased and keep their backing store alive, so they stay valid for
|
||||
// as long as the module holds them. JS-heap buffers have nothing to retain — their bytes are
|
||||
// freed when the ArrayBuffer is collected or detached — so `mustCopyBytes` is set whenever the
|
||||
// invocation may outlive the JS call, and they are aliased only when it cannot. Engines that
|
||||
// don't hand out the backing MutableBuffer fall back to those JS-heap rules for every buffer.
|
||||
static RCTArrayBuffer *
|
||||
convertJSIArrayBufferToRCTArrayBuffer(jsi::Runtime &rt, const jsi::ArrayBuffer &arrayBuffer, BOOL mustCopyBytes)
|
||||
// Copy the ArrayBuffer's bytes into an immutable NSData. An inbound buffer is
|
||||
// owned by the caller, not the native module, so NSData (not NSMutableData) is
|
||||
// the correct read-only contract. Copying makes the NSData self-contained and
|
||||
// safe to retain in a block, store, or dispatch to another thread, regardless of
|
||||
// whether the bytes were owned by JS (valid only for this callstack) or by a
|
||||
// native MutableBuffer (which the JS ArrayBuffer may GC concurrently).
|
||||
static NSData *convertJSIArrayBufferToNSData(jsi::Runtime &rt, const jsi::ArrayBuffer &value)
|
||||
{
|
||||
if (auto nativeBuffer = arrayBuffer.tryGetMutableBuffer(rt)) {
|
||||
auto keepAlive = std::move(nativeBuffer);
|
||||
return [RCTArrayBuffer arrayBufferWithOwnedBytes:keepAlive->data()
|
||||
length:keepAlive->size()
|
||||
cleanup:^{
|
||||
(void)keepAlive;
|
||||
}];
|
||||
}
|
||||
|
||||
void *bytes = arrayBuffer.data(rt);
|
||||
size_t size = arrayBuffer.size(rt);
|
||||
|
||||
// The bytes belong to the JS heap -> async call.
|
||||
if (mustCopyBytes) {
|
||||
return [RCTArrayBuffer arrayBufferWithCopiedBytes:bytes length:size];
|
||||
}
|
||||
|
||||
// The bytes belong to the JS heap -> sync call.
|
||||
return [RCTArrayBuffer arrayBufferWithUnownedBytes:bytes length:size];
|
||||
return [NSData dataWithBytes:value.data(rt) length:value.size(rt)];
|
||||
}
|
||||
|
||||
id convertJSIValueToObjCObject(
|
||||
jsi::Runtime &runtime,
|
||||
const jsi::Value &value,
|
||||
const std::shared_ptr<CallInvoker> &jsInvoker,
|
||||
BOOL useNSNull,
|
||||
BOOL mustCopyBytes)
|
||||
BOOL useNSNull)
|
||||
{
|
||||
if (value.isUndefined() || (value.isNull() && !useNSNull)) {
|
||||
return nil;
|
||||
@@ -270,7 +242,7 @@ id convertJSIValueToObjCObject(
|
||||
return convertJSIFunctionToCallback(runtime, o.getFunction(runtime), jsInvoker);
|
||||
}
|
||||
if (o.isArrayBuffer(runtime)) {
|
||||
return convertJSIArrayBufferToRCTArrayBuffer(runtime, o.getArrayBuffer(runtime), mustCopyBytes);
|
||||
return convertJSIArrayBufferToNSData(runtime, o.getArrayBuffer(runtime));
|
||||
}
|
||||
return convertJSIObjectToNSDictionary(runtime, o, jsInvoker, useNSNull);
|
||||
}
|
||||
@@ -629,11 +601,11 @@ jsi::Value ObjCTurboModule::convertReturnIdToJSIValue(
|
||||
break;
|
||||
}
|
||||
case ArrayBufferKind: {
|
||||
if (result != nil && ![result isKindOfClass:[RCTArrayBuffer class]]) {
|
||||
RCTLogError(@"convertReturnIdToJSIValue: expected RCTArrayBuffer for ArrayBufferKind, got %@", [result class]);
|
||||
if (result != nil && ![result isKindOfClass:[NSMutableData class]]) {
|
||||
RCTLogError(@"convertReturnIdToJSIValue: expected NSMutableData for ArrayBufferKind, got %@", [result class]);
|
||||
break;
|
||||
}
|
||||
returnValue = convertRCTArrayBufferToJSIArrayBuffer(runtime, (RCTArrayBuffer *)result);
|
||||
returnValue = convertNSMutableDataToJSIArrayBuffer(runtime, (NSMutableData *)result);
|
||||
break;
|
||||
}
|
||||
case FunctionKind:
|
||||
@@ -710,8 +682,7 @@ void ObjCTurboModule::setInvocationArg(
|
||||
const jsi::Value &arg,
|
||||
size_t i,
|
||||
NSInvocation *inv,
|
||||
NSMutableArray *retainedObjectsForInvocation,
|
||||
bool mustCopyBytes)
|
||||
NSMutableArray *retainedObjectsForInvocation)
|
||||
{
|
||||
if (arg.isBool()) {
|
||||
bool v = arg.getBool();
|
||||
@@ -754,15 +725,13 @@ void ObjCTurboModule::setInvocationArg(
|
||||
* Convert arg to ObjC objects.
|
||||
*/
|
||||
BOOL enableModuleArgumentNSNullConversionIOS = ReactNativeFeatureFlags::enableModuleArgumentNSNullConversionIOS();
|
||||
id objCArg =
|
||||
convertJSIValueToObjCObject(runtime, arg, jsInvoker_, enableModuleArgumentNSNullConversionIOS, mustCopyBytes);
|
||||
id objCArg = convertJSIValueToObjCObject(runtime, arg, jsInvoker_, enableModuleArgumentNSNullConversionIOS);
|
||||
|
||||
// A JS `null` in argument position must reach ObjC as `nil`; only nulls nested inside arrays and
|
||||
// dictionaries are preserved as `kCFNull`. Skipping `setArgument:` leaves the slot zeroed.
|
||||
if (enableModuleArgumentNSNullConversionIOS && objCArg == (id)kCFNull) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (objCArg != nullptr) {
|
||||
NSString *methodNameNSString = @(methodName);
|
||||
|
||||
@@ -823,7 +792,6 @@ void ObjCTurboModule::setInvocationArg(
|
||||
NSInvocation *ObjCTurboModule::createMethodInvocation(
|
||||
jsi::Runtime &runtime,
|
||||
bool isSync,
|
||||
bool mustCopyBytes,
|
||||
const char *methodName,
|
||||
SEL selector,
|
||||
const jsi::Value *args,
|
||||
@@ -852,7 +820,7 @@ NSInvocation *ObjCTurboModule::createMethodInvocation(
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
const jsi::Value &arg = args[i];
|
||||
const std::string objCArgType = [methodSignature getArgumentTypeAtIndex:i + 2];
|
||||
setInvocationArg(runtime, methodName, objCArgType, arg, i, inv, retainedObjectsForInvocation, mustCopyBytes);
|
||||
setInvocationArg(runtime, methodName, objCArgType, arg, i, inv, retainedObjectsForInvocation);
|
||||
}
|
||||
|
||||
if (isSync) {
|
||||
@@ -873,12 +841,6 @@ bool ObjCTurboModule::isMethodSync(TurboModuleMethodValueKind returnType)
|
||||
return returnType != VoidKind && returnType != PromiseKind;
|
||||
}
|
||||
|
||||
bool ObjCTurboModule::mustCopyJSHeapArrayBufferBytes(TurboModuleMethodValueKind returnType)
|
||||
{
|
||||
// Void always dispatches via invokeAsync and promise may.
|
||||
return returnType == VoidKind || returnType == PromiseKind;
|
||||
}
|
||||
|
||||
ObjCTurboModule::ObjCTurboModule(const InitParams ¶ms)
|
||||
: TurboModule(params.moduleName, params.jsInvoker),
|
||||
instance_(params.instance),
|
||||
@@ -899,7 +861,6 @@ jsi::Value ObjCTurboModule::invokeObjCMethod(
|
||||
const char *methodName = methodNameStr.c_str();
|
||||
|
||||
bool isSyncInvocation = isMethodSync(returnType);
|
||||
bool mustCopyBytes = mustCopyJSHeapArrayBufferBytes(returnType);
|
||||
|
||||
if (isSyncInvocation) {
|
||||
TurboModulePerfLogger::syncMethodCallStart(moduleName, methodName);
|
||||
@@ -909,7 +870,7 @@ jsi::Value ObjCTurboModule::invokeObjCMethod(
|
||||
|
||||
NSMutableArray *retainedObjectsForInvocation = [NSMutableArray arrayWithCapacity:count + 2];
|
||||
NSInvocation *inv = createMethodInvocation(
|
||||
runtime, isSyncInvocation, mustCopyBytes, methodName, selector, args, count, retainedObjectsForInvocation);
|
||||
runtime, isSyncInvocation, methodName, selector, args, count, retainedObjectsForInvocation);
|
||||
|
||||
jsi::Value returnValue = jsi::Value::undefined();
|
||||
|
||||
|
||||
+8
-19
@@ -6,8 +6,6 @@
|
||||
*/
|
||||
|
||||
#import "RCTSampleTurboModule.h"
|
||||
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import "RCTSampleTurboModulePlugin.h"
|
||||
|
||||
#import <React/RCTAssert.h>
|
||||
@@ -16,8 +14,6 @@
|
||||
#import <ReactCommon/RCTTurboModuleWithJSIBindings.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#include <span>
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
@interface RCTSampleTurboModule () <RCTTurboModuleWithJSIBindings, RCTInitializing>
|
||||
@@ -149,27 +145,20 @@ RCT_EXPORT_MODULE()
|
||||
};
|
||||
}
|
||||
|
||||
// The argument aliases the JS ArrayBuffer's bytes, so mutating in place is visible to JS.
|
||||
- (RCTArrayBuffer *)getArrayBuffer:(RCTArrayBuffer *)buffer
|
||||
// Arguments arrive as an immutable NSData, but an ArrayBuffer return must be
|
||||
// NSMutableData: it is handed to JS as a jsi::MutableBuffer, whose data() is
|
||||
// non-const. Echoing the argument back therefore needs a mutable copy.
|
||||
- (NSMutableData *)getArrayBuffer:(NSData *)buffer
|
||||
{
|
||||
auto *bytes = static_cast<uint8_t *>(buffer.mutableBytes);
|
||||
if (bytes == nullptr) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::span<uint8_t> byteSpan(bytes, static_cast<size_t>(buffer.length));
|
||||
for (auto &byte : byteSpan) {
|
||||
byte = static_cast<uint8_t>(byte * 2);
|
||||
}
|
||||
return buffer;
|
||||
return [buffer mutableCopy];
|
||||
}
|
||||
|
||||
- (RCTArrayBuffer *)createNativeBuffer:(double)size
|
||||
- (NSMutableData *)createNativeBuffer:(double)size
|
||||
{
|
||||
return [RCTArrayBuffer arrayBufferWithLength:(NSUInteger)size];
|
||||
return [NSMutableData dataWithLength:(NSUInteger)size];
|
||||
}
|
||||
|
||||
- (void)processAsyncBuffer:(RCTArrayBuffer *)payload
|
||||
- (void)processAsyncBuffer:(NSData *)payload
|
||||
resolve:(RCTPromiseResolveBlock)resolve
|
||||
reject:(RCTPromiseRejectBlock)reject
|
||||
{
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import <React/RCTArrayBuffer.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <ReactCommon/RCTTurboModule.h>
|
||||
#import <ReactCommon/TestCallInvoker.h>
|
||||
@@ -30,14 +29,14 @@ std::shared_ptr<facebook::jsi::Runtime> createHermesRuntime(bool enableMicrotask
|
||||
return facebook::hermes::makeHermesRuntime(::hermes::vm::RuntimeConfig::Builder().withMicrotaskQueue(true).build());
|
||||
}
|
||||
|
||||
RCTArrayBuffer *createIntegerSequenceBuffer(NSUInteger size)
|
||||
NSMutableData *createIntegerSequenceData(NSUInteger size)
|
||||
{
|
||||
RCTArrayBuffer *buffer = [RCTArrayBuffer arrayBufferWithLength:size];
|
||||
auto *bytes = static_cast<uint8_t *>(buffer.mutableBytes);
|
||||
NSMutableData *data = [NSMutableData dataWithLength:size];
|
||||
auto *bytes = static_cast<uint8_t *>(data.mutableBytes);
|
||||
for (NSUInteger i = 0; i < size; ++i) {
|
||||
bytes[i] = static_cast<uint8_t>(i);
|
||||
}
|
||||
return buffer;
|
||||
return data;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> bytesFromData(NSData *data)
|
||||
@@ -99,8 +98,6 @@ class QueueingNativeMethodCallInvoker final : public NativeMethodCallInvoker {
|
||||
@interface RCTTestArrayBufferTurboModule : NSObject <RCTBridgeModule>
|
||||
|
||||
@property (nonatomic, copy) NSData *lastReceivedPayload;
|
||||
@property (nonatomic, assign) BOOL sawAliasedBytes;
|
||||
@property (nonatomic, assign) BOOL sawUnownedBytes;
|
||||
|
||||
@end
|
||||
|
||||
@@ -108,54 +105,36 @@ class QueueingNativeMethodCallInvoker final : public NativeMethodCallInvoker {
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
|
||||
- (RCTArrayBuffer *)testMethodWhichTransformsArrayBuffer:(RCTArrayBuffer *)buffer
|
||||
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSMutableData *, testMethodWhichTransformsArrayBuffer : (NSData *)buffer)
|
||||
{
|
||||
RCTArrayBuffer *result = [RCTArrayBuffer arrayBufferWithLength:buffer.length];
|
||||
auto *destinationBytes = static_cast<uint8_t *>(result.mutableBytes);
|
||||
for (NSUInteger i = 0; i < buffer.length; ++i) {
|
||||
destinationBytes[i] = static_cast<uint8_t>((i + 1) * 10);
|
||||
NSMutableData *result = [buffer mutableCopy];
|
||||
auto *bytes = static_cast<uint8_t *>(result.mutableBytes);
|
||||
for (NSUInteger i = 0; i < result.length; ++i) {
|
||||
bytes[i] = static_cast<uint8_t>((i + 1) * 10);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
- (RCTArrayBuffer *)testMethodWhichReturnsItsArgument:(RCTArrayBuffer *)buffer
|
||||
RCT_EXPORT_METHOD(testMethodWhichStoresArrayBuffer : (NSData *)payload)
|
||||
{
|
||||
auto *bytes = static_cast<uint8_t *>(buffer.mutableBytes);
|
||||
for (NSUInteger i = 0; i < buffer.length && i < 3; ++i) {
|
||||
bytes[i] = static_cast<uint8_t>(99 - i);
|
||||
}
|
||||
return buffer;
|
||||
self.lastReceivedPayload = [payload copy];
|
||||
}
|
||||
|
||||
- (NSNumber *)testMethodWhichChecksArrayBufferAliasing:(RCTArrayBuffer *)buffer
|
||||
RCT_EXPORT_METHOD(testMethodWhichStoresNestedArrayBuffer : (NSDictionary *)payload)
|
||||
{
|
||||
// An observable in-place write proves the bytes were aliased, not copied on the way in.
|
||||
auto *bytes = static_cast<uint8_t *>(buffer.mutableBytes);
|
||||
bytes[0] = 77;
|
||||
self.sawAliasedBytes = buffer.length == 3 && bytes[0] == 77;
|
||||
self.sawUnownedBytes = !buffer.isOwningBytes;
|
||||
return @(YES);
|
||||
NSDictionary *nestedPayload = payload[@"nested"];
|
||||
self.lastReceivedPayload = [nestedPayload[@"buffer"] copy];
|
||||
}
|
||||
|
||||
- (void)testMethodWhichStoresArrayBuffer:(RCTArrayBuffer *)payload
|
||||
{
|
||||
self.lastReceivedPayload = [NSData dataWithBytes:payload.mutableBytes length:payload.length];
|
||||
}
|
||||
|
||||
- (void)testMethodWhichCallsBackWithArrayBuffer:(double)size callback:(RCTResponseSenderBlock)callback
|
||||
{
|
||||
callback(@[ createIntegerSequenceBuffer(static_cast<NSUInteger>(size)) ]);
|
||||
}
|
||||
|
||||
- (void)testMethodWhichReturnsArrayBuffer:(double)size
|
||||
resolve:(RCTPromiseResolveBlock)resolve
|
||||
reject:(RCTPromiseRejectBlock)reject
|
||||
RCT_EXPORT_METHOD(
|
||||
testMethodWhichReturnsArrayBuffer : (double)size resolve : (RCTPromiseResolveBlock)
|
||||
resolve reject : (RCTPromiseRejectBlock)reject)
|
||||
{
|
||||
if (resolve == nil || reject == nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(createIntegerSequenceBuffer(static_cast<NSUInteger>(size)));
|
||||
resolve(createIntegerSequenceData(static_cast<NSUInteger>(size)));
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -207,116 +186,6 @@ RCT_EXPORT_MODULE()
|
||||
XCTAssertEqual(returnedBytes[2], 30);
|
||||
}
|
||||
|
||||
// The sync argument is a live alias: an in-place write lands on the JS ArrayBuffer itself.
|
||||
- (void)testJSBackedArrayBufferIsNotCopiedDuringTheCall
|
||||
{
|
||||
auto hermesRuntime = createHermesRuntime();
|
||||
facebook::jsi::Runtime *rt = hermesRuntime.get();
|
||||
auto *instance = [RCTTestArrayBufferTurboModule new];
|
||||
|
||||
ObjCTurboModule::InitParams params = {
|
||||
.moduleName = "TestModule",
|
||||
.instance = instance,
|
||||
.jsInvoker = nullptr,
|
||||
.nativeMethodCallInvoker = std::make_shared<ImmediateNativeMethodCallInvoker>(),
|
||||
.isSyncModule = false,
|
||||
};
|
||||
ObjCTurboModule module(params);
|
||||
|
||||
auto sourceBuffer = rt->global()
|
||||
.getPropertyAsFunction(*rt, "eval")
|
||||
.call(*rt, "new Uint8Array([1, 2, 3]).buffer")
|
||||
.asObject(*rt)
|
||||
.getArrayBuffer(*rt);
|
||||
facebook::jsi::Value args[1] = {facebook::jsi::Value(*rt, sourceBuffer)};
|
||||
|
||||
module.invokeObjCMethod(
|
||||
*rt,
|
||||
BooleanKind,
|
||||
"testMethodWhichChecksArrayBufferAliasing",
|
||||
@selector(testMethodWhichChecksArrayBufferAliasing:),
|
||||
args,
|
||||
1);
|
||||
|
||||
XCTAssertTrue(instance.sawAliasedBytes, @"The argument must alias the JS ArrayBuffer's bytes");
|
||||
XCTAssertTrue(instance.sawUnownedBytes, @"A JS-heap argument to a sync method must not own its bytes");
|
||||
XCTAssertEqual(bytesFromArrayBuffer(*rt, sourceBuffer)[0], 77, @"The native write must land on the JS ArrayBuffer");
|
||||
}
|
||||
|
||||
// Returning the argument must hand JS the mutated bytes: it has to stay valid through the
|
||||
// return-value conversion.
|
||||
- (void)testSyncMethodCanReturnItsOwnArgument
|
||||
{
|
||||
auto hermesRuntime = createHermesRuntime();
|
||||
facebook::jsi::Runtime *rt = hermesRuntime.get();
|
||||
auto *instance = [RCTTestArrayBufferTurboModule new];
|
||||
|
||||
ObjCTurboModule::InitParams params = {
|
||||
.moduleName = "TestModule",
|
||||
.instance = instance,
|
||||
.jsInvoker = nullptr,
|
||||
.nativeMethodCallInvoker = std::make_shared<ImmediateNativeMethodCallInvoker>(),
|
||||
.isSyncModule = false,
|
||||
};
|
||||
ObjCTurboModule module(params);
|
||||
|
||||
auto sourceBuffer = rt->global()
|
||||
.getPropertyAsFunction(*rt, "eval")
|
||||
.call(*rt, "new Uint8Array([1, 2, 3]).buffer")
|
||||
.asObject(*rt)
|
||||
.getArrayBuffer(*rt);
|
||||
facebook::jsi::Value args[1] = {facebook::jsi::Value(*rt, sourceBuffer)};
|
||||
|
||||
auto result = module.invokeObjCMethod(
|
||||
*rt,
|
||||
ArrayBufferKind,
|
||||
"testMethodWhichReturnsItsArgument",
|
||||
@selector(testMethodWhichReturnsItsArgument:),
|
||||
args,
|
||||
1);
|
||||
|
||||
XCTAssertTrue(result.isObject());
|
||||
XCTAssertTrue(result.asObject(*rt).isArrayBuffer(*rt));
|
||||
auto returnedBytes = bytesFromArrayBuffer(*rt, result.asObject(*rt).getArrayBuffer(*rt));
|
||||
XCTAssertEqual(returnedBytes.size(), 3u, @"Returning the argument must not yield an empty buffer");
|
||||
XCTAssertEqual(returnedBytes[0], 99);
|
||||
XCTAssertEqual(returnedBytes[1], 98);
|
||||
XCTAssertEqual(returnedBytes[2], 97);
|
||||
}
|
||||
|
||||
// A zero-length ArrayBuffer must round-trip, NULL bytes pointer and all.
|
||||
- (void)testEmptyArrayBufferRoundTrip
|
||||
{
|
||||
auto hermesRuntime = createHermesRuntime();
|
||||
facebook::jsi::Runtime *rt = hermesRuntime.get();
|
||||
auto *instance = [RCTTestArrayBufferTurboModule new];
|
||||
|
||||
ObjCTurboModule::InitParams params = {
|
||||
.moduleName = "TestModule",
|
||||
.instance = instance,
|
||||
.jsInvoker = nullptr,
|
||||
.nativeMethodCallInvoker = std::make_shared<ImmediateNativeMethodCallInvoker>(),
|
||||
.isSyncModule = false,
|
||||
};
|
||||
ObjCTurboModule module(params);
|
||||
|
||||
auto sourceBuffer =
|
||||
rt->global().getPropertyAsFunction(*rt, "eval").call(*rt, "new ArrayBuffer(0)").asObject(*rt).getArrayBuffer(*rt);
|
||||
facebook::jsi::Value args[1] = {facebook::jsi::Value(*rt, sourceBuffer)};
|
||||
|
||||
auto result = module.invokeObjCMethod(
|
||||
*rt,
|
||||
ArrayBufferKind,
|
||||
"testMethodWhichTransformsArrayBuffer",
|
||||
@selector(testMethodWhichTransformsArrayBuffer:),
|
||||
args,
|
||||
1);
|
||||
|
||||
XCTAssertTrue(result.isObject());
|
||||
XCTAssertTrue(result.asObject(*rt).isArrayBuffer(*rt));
|
||||
XCTAssertEqual(result.asObject(*rt).getArrayBuffer(*rt).size(*rt), 0u);
|
||||
}
|
||||
|
||||
- (void)testAsyncJSBackedArrayBufferIsCopied
|
||||
{
|
||||
auto hermesRuntime = createHermesRuntime();
|
||||
@@ -357,6 +226,55 @@ RCT_EXPORT_MODULE()
|
||||
XCTAssertEqual(receivedBytes[2], 3);
|
||||
}
|
||||
|
||||
- (void)testAsyncNestedJSBackedArrayBufferIsCopied
|
||||
{
|
||||
auto hermesRuntime = createHermesRuntime();
|
||||
facebook::jsi::Runtime *rt = hermesRuntime.get();
|
||||
auto nativeInvoker = std::make_shared<QueueingNativeMethodCallInvoker>();
|
||||
auto *instance = [RCTTestArrayBufferTurboModule new];
|
||||
|
||||
ObjCTurboModule::InitParams params = {
|
||||
.moduleName = "TestModule",
|
||||
.instance = instance,
|
||||
.jsInvoker = nullptr,
|
||||
.nativeMethodCallInvoker = nativeInvoker,
|
||||
.isSyncModule = false,
|
||||
};
|
||||
ObjCTurboModule module(params);
|
||||
|
||||
auto sourceObject = rt->global()
|
||||
.getPropertyAsFunction(*rt, "eval")
|
||||
.call(*rt, "({nested: {buffer: new Uint8Array([1, 2, 3]).buffer}})")
|
||||
.asObject(*rt);
|
||||
auto sourceBuffer = sourceObject.getProperty(*rt, "nested")
|
||||
.asObject(*rt)
|
||||
.getProperty(*rt, "buffer")
|
||||
.asObject(*rt)
|
||||
.getArrayBuffer(*rt);
|
||||
facebook::jsi::Value args[1] = {facebook::jsi::Value(*rt, sourceObject)};
|
||||
|
||||
module.invokeObjCMethod(
|
||||
*rt,
|
||||
VoidKind,
|
||||
"testMethodWhichStoresNestedArrayBuffer",
|
||||
@selector(testMethodWhichStoresNestedArrayBuffer:),
|
||||
args,
|
||||
1);
|
||||
|
||||
auto *sourceBytes = sourceBuffer.data(*rt);
|
||||
sourceBytes[0] = 9;
|
||||
sourceBytes[1] = 8;
|
||||
sourceBytes[2] = 7;
|
||||
|
||||
nativeInvoker->flushQueue();
|
||||
|
||||
auto receivedBytes = bytesFromData(instance.lastReceivedPayload);
|
||||
XCTAssertEqual(receivedBytes.size(), 3u);
|
||||
XCTAssertEqual(receivedBytes[0], 1);
|
||||
XCTAssertEqual(receivedBytes[1], 2);
|
||||
XCTAssertEqual(receivedBytes[2], 3);
|
||||
}
|
||||
|
||||
- (void)testAsyncNativeBackedArrayBufferRetainsBackingStore
|
||||
{
|
||||
auto hermesRuntime = createHermesRuntime();
|
||||
@@ -394,56 +312,6 @@ RCT_EXPORT_MODULE()
|
||||
XCTAssertEqual(receivedBytes[3], 7);
|
||||
}
|
||||
|
||||
// A buffer handed to a callback is delivered to JS after the native call has returned.
|
||||
- (void)testCallbackDeliversArrayBuffer
|
||||
{
|
||||
auto hermesRuntime = createHermesRuntime();
|
||||
facebook::jsi::Runtime *rt = hermesRuntime.get();
|
||||
auto jsInvoker = std::make_shared<TestCallInvoker>(*rt);
|
||||
auto *instance = [RCTTestArrayBufferTurboModule new];
|
||||
|
||||
ObjCTurboModule::InitParams params = {
|
||||
.moduleName = "TestModule",
|
||||
.instance = instance,
|
||||
.jsInvoker = jsInvoker,
|
||||
.nativeMethodCallInvoker = std::make_shared<ImmediateNativeMethodCallInvoker>(),
|
||||
.isSyncModule = false,
|
||||
};
|
||||
ObjCTurboModule module(params);
|
||||
|
||||
std::vector<uint8_t> callbackBytes;
|
||||
auto onCallback = facebook::jsi::Function::createFromHostFunction(
|
||||
*rt,
|
||||
facebook::jsi::PropNameID::forAscii(*rt, "onCallback"),
|
||||
1,
|
||||
[&callbackBytes](
|
||||
facebook::jsi::Runtime &runtime,
|
||||
const facebook::jsi::Value &,
|
||||
const facebook::jsi::Value *callbackArgs,
|
||||
size_t count) -> facebook::jsi::Value {
|
||||
if (count == 1 && callbackArgs[0].isObject() && callbackArgs[0].asObject(runtime).isArrayBuffer(runtime)) {
|
||||
callbackBytes = bytesFromArrayBuffer(runtime, callbackArgs[0].asObject(runtime).getArrayBuffer(runtime));
|
||||
}
|
||||
return facebook::jsi::Value::undefined();
|
||||
});
|
||||
facebook::jsi::Value args[2] = {facebook::jsi::Value(3.0), facebook::jsi::Value(*rt, onCallback)};
|
||||
|
||||
module.invokeObjCMethod(
|
||||
*rt,
|
||||
VoidKind,
|
||||
"testMethodWhichCallsBackWithArrayBuffer",
|
||||
@selector(testMethodWhichCallsBackWithArrayBuffer:callback:),
|
||||
args,
|
||||
2);
|
||||
|
||||
jsInvoker->flushQueue();
|
||||
|
||||
XCTAssertEqual(callbackBytes.size(), 3u);
|
||||
XCTAssertEqual(callbackBytes[0], 0);
|
||||
XCTAssertEqual(callbackBytes[1], 1);
|
||||
XCTAssertEqual(callbackBytes[2], 2);
|
||||
}
|
||||
|
||||
- (void)testPromiseResolvesArrayBuffer
|
||||
{
|
||||
auto hermesRuntime = createHermesRuntime(true);
|
||||
|
||||
@@ -654,16 +654,6 @@ interface RCTAppearance : public RCTEventEmitter <RCTBridgeModule> {
|
||||
public virtual instancetype init();
|
||||
}
|
||||
|
||||
interface RCTArrayBuffer : public NSObject {
|
||||
public @property (assign, readonly) BOOL owningBytes;
|
||||
public @property (assign, readonly) NSUInteger length;
|
||||
public @property (assign, readonly) void* mutableBytes NS_RETURNS_INNER_POINTER;
|
||||
public virtual static instancetype arrayBufferWithCopiedBytes:length:(const void* _Nullable bytes, NSUInteger length);
|
||||
public virtual static instancetype arrayBufferWithLength:(NSUInteger length);
|
||||
public virtual static instancetype arrayBufferWithOwnedBytes:length:cleanup:(_Nullable void* bytes, NSUInteger length, _Nullable void(^)(void) cleanup);
|
||||
public virtual static instancetype arrayBufferWithUnownedBytes:length:(_Nullable void* bytes, NSUInteger length);
|
||||
}
|
||||
|
||||
interface RCTBackedTextFieldDelegateAdapter : public NSObject {
|
||||
public virtual instancetype initWithTextField:(UITextField<RCTBackedTextInputViewProtocol>* backedTextInputView);
|
||||
public virtual void selectedTextRangeWasSet();
|
||||
@@ -2512,19 +2502,19 @@ protocol NativeSampleTurboModuleSpec : public NSObjectRCTBridgeModule, public RC
|
||||
public virtual NSDictionary* getObjectThrows:(NSDictionary* arg);
|
||||
public virtual NSDictionary* getUnsafeObject:(NSDictionary* arg);
|
||||
public virtual NSDictionary* getValue:y:z:(double x, NSString* y, NSDictionary* z);
|
||||
public virtual NSMutableData* createNativeBuffer:(double size);
|
||||
public virtual NSMutableData* getArrayBuffer:(NSData* buffer);
|
||||
public virtual NSNumber* getBool:(BOOL arg);
|
||||
public virtual NSNumber* getEnum:(double arg);
|
||||
public virtual NSNumber* getNumber:(double arg);
|
||||
public virtual NSNumber* getRootTag:(double arg);
|
||||
public virtual NSString* getString:(NSString* arg);
|
||||
public virtual RCTArrayBuffer* createNativeBuffer:(double size);
|
||||
public virtual RCTArrayBuffer* getArrayBuffer:(RCTArrayBuffer* buffer);
|
||||
public virtual facebook::react::ModuleConstants<JS::NativeSampleTurboModule::Constants> constantsToExport();
|
||||
public virtual facebook::react::ModuleConstants<JS::NativeSampleTurboModule::Constants> getConstants();
|
||||
public virtual void getImageUrl:reject:(RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void getValueWithCallback:(RCTResponseSenderBlock callback);
|
||||
public virtual void getValueWithPromise:resolve:reject:(BOOL error, RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void processAsyncBuffer:resolve:reject:(RCTArrayBuffer* payload, RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void processAsyncBuffer:resolve:reject:(NSData* payload, RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void promiseAssert:reject:(RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void promiseThrows:reject:(RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void voidFunc();
|
||||
@@ -6169,7 +6159,7 @@ class facebook::react::ObjCInteropTurboModule : public facebook::react::ObjCTurb
|
||||
protected virtual NSString* getArgumentTypeName(facebook::jsi::Runtime& runtime, NSString* methodName, int argIndex) override;
|
||||
protected virtual facebook::jsi::Value convertReturnIdToJSIValue(facebook::jsi::Runtime& runtime, const char* methodName, facebook::react::TurboModuleMethodValueKind returnType, id result) override;
|
||||
protected virtual facebook::jsi::Value create(facebook::jsi::Runtime& runtime, const facebook::jsi::PropNameID& propName) override;
|
||||
protected virtual void setInvocationArg(facebook::jsi::Runtime& runtime, const char* methodName, const std::string& objCArgType, const facebook::jsi::Value& arg, size_t i, NSInvocation* inv, NSMutableArray* retainedObjectsForInvocation, bool mustCopyBytes) override;
|
||||
protected virtual void setInvocationArg(facebook::jsi::Runtime& runtime, const char* methodName, const std::string& objCArgType, const facebook::jsi::Value& arg, size_t i, NSInvocation* inv, NSMutableArray* retainedObjectsForInvocation) override;
|
||||
public ObjCInteropTurboModule(const facebook::react::ObjCTurboModule::InitParams& params);
|
||||
public virtual std::vector<facebook::jsi::PropNameID> getPropertyNames(facebook::jsi::Runtime& runtime) override;
|
||||
}
|
||||
@@ -6184,7 +6174,7 @@ struct facebook::react::ObjCInteropTurboModule::MethodDescriptor {
|
||||
class facebook::react::ObjCTurboModule : public facebook::react::TurboModule {
|
||||
protected virtual NSString* getArgumentTypeName(facebook::jsi::Runtime& runtime, NSString* methodName, int argIndex);
|
||||
protected virtual facebook::jsi::Value convertReturnIdToJSIValue(facebook::jsi::Runtime& runtime, const char* methodName, facebook::react::TurboModuleMethodValueKind returnType, id result);
|
||||
protected virtual void setInvocationArg(facebook::jsi::Runtime& runtime, const char* methodName, const std::string& objCArgType, const facebook::jsi::Value& arg, size_t i, NSInvocation* inv, NSMutableArray* retainedObjectsForInvocation, bool mustCopyBytes);
|
||||
protected virtual void setInvocationArg(facebook::jsi::Runtime& runtime, const char* methodName, const std::string& objCArgType, const facebook::jsi::Value& arg, size_t i, NSInvocation* inv, NSMutableArray* retainedObjectsForInvocation);
|
||||
protected void setEventEmitterCallback(facebook::react::EventEmitterCallback eventEmitterCallback);
|
||||
protected void setMethodArgConversionSelector(NSString* methodName, size_t argIndex, NSString* fnName);
|
||||
public ObjCTurboModule(const facebook::react::ObjCTurboModule::InitParams& params);
|
||||
@@ -13661,7 +13651,7 @@ struct facebook::react::dom::RNMeasureRect {
|
||||
|
||||
|
||||
facebook::jsi::Value facebook::react::TurboModuleConvertUtils::convertObjCObjectToJSIValue(facebook::jsi::Runtime& runtime, id value);
|
||||
id facebook::react::TurboModuleConvertUtils::convertJSIValueToObjCObject(facebook::jsi::Runtime& runtime, const facebook::jsi::Value& value, const std::shared_ptr<facebook::react::CallInvoker>& jsInvoker, BOOL useNSNull = NO, BOOL mustCopyBytes = YES);
|
||||
id facebook::react::TurboModuleConvertUtils::convertJSIValueToObjCObject(facebook::jsi::Runtime& runtime, const facebook::jsi::Value& value, const std::shared_ptr<facebook::react::CallInvoker>& jsInvoker, BOOL useNSNull = NO);
|
||||
|
||||
|
||||
static const facebook::react::Color facebook::react::HostPlatformColor::UndefinedColor;
|
||||
|
||||
@@ -654,16 +654,6 @@ interface RCTAppearance : public RCTEventEmitter <RCTBridgeModule> {
|
||||
public virtual instancetype init();
|
||||
}
|
||||
|
||||
interface RCTArrayBuffer : public NSObject {
|
||||
public @property (assign, readonly) BOOL owningBytes;
|
||||
public @property (assign, readonly) NSUInteger length;
|
||||
public @property (assign, readonly) void* mutableBytes NS_RETURNS_INNER_POINTER;
|
||||
public virtual static instancetype arrayBufferWithCopiedBytes:length:(const void* _Nullable bytes, NSUInteger length);
|
||||
public virtual static instancetype arrayBufferWithLength:(NSUInteger length);
|
||||
public virtual static instancetype arrayBufferWithOwnedBytes:length:cleanup:(_Nullable void* bytes, NSUInteger length, _Nullable void(^)(void) cleanup);
|
||||
public virtual static instancetype arrayBufferWithUnownedBytes:length:(_Nullable void* bytes, NSUInteger length);
|
||||
}
|
||||
|
||||
interface RCTBackedTextFieldDelegateAdapter : public NSObject {
|
||||
public virtual instancetype initWithTextField:(UITextField<RCTBackedTextInputViewProtocol>* backedTextInputView);
|
||||
public virtual void selectedTextRangeWasSet();
|
||||
@@ -2505,19 +2495,19 @@ protocol NativeSampleTurboModuleSpec : public NSObjectRCTBridgeModule, public RC
|
||||
public virtual NSDictionary* getObjectThrows:(NSDictionary* arg);
|
||||
public virtual NSDictionary* getUnsafeObject:(NSDictionary* arg);
|
||||
public virtual NSDictionary* getValue:y:z:(double x, NSString* y, NSDictionary* z);
|
||||
public virtual NSMutableData* createNativeBuffer:(double size);
|
||||
public virtual NSMutableData* getArrayBuffer:(NSData* buffer);
|
||||
public virtual NSNumber* getBool:(BOOL arg);
|
||||
public virtual NSNumber* getEnum:(double arg);
|
||||
public virtual NSNumber* getNumber:(double arg);
|
||||
public virtual NSNumber* getRootTag:(double arg);
|
||||
public virtual NSString* getString:(NSString* arg);
|
||||
public virtual RCTArrayBuffer* createNativeBuffer:(double size);
|
||||
public virtual RCTArrayBuffer* getArrayBuffer:(RCTArrayBuffer* buffer);
|
||||
public virtual facebook::react::ModuleConstants<JS::NativeSampleTurboModule::Constants> constantsToExport();
|
||||
public virtual facebook::react::ModuleConstants<JS::NativeSampleTurboModule::Constants> getConstants();
|
||||
public virtual void getImageUrl:reject:(RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void getValueWithCallback:(RCTResponseSenderBlock callback);
|
||||
public virtual void getValueWithPromise:resolve:reject:(BOOL error, RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void processAsyncBuffer:resolve:reject:(RCTArrayBuffer* payload, RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void processAsyncBuffer:resolve:reject:(NSData* payload, RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void promiseAssert:reject:(RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void promiseThrows:reject:(RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void voidFunc();
|
||||
@@ -6055,7 +6045,7 @@ class facebook::react::ObjCInteropTurboModule : public facebook::react::ObjCTurb
|
||||
protected virtual NSString* getArgumentTypeName(facebook::jsi::Runtime& runtime, NSString* methodName, int argIndex) override;
|
||||
protected virtual facebook::jsi::Value convertReturnIdToJSIValue(facebook::jsi::Runtime& runtime, const char* methodName, facebook::react::TurboModuleMethodValueKind returnType, id result) override;
|
||||
protected virtual facebook::jsi::Value create(facebook::jsi::Runtime& runtime, const facebook::jsi::PropNameID& propName) override;
|
||||
protected virtual void setInvocationArg(facebook::jsi::Runtime& runtime, const char* methodName, const std::string& objCArgType, const facebook::jsi::Value& arg, size_t i, NSInvocation* inv, NSMutableArray* retainedObjectsForInvocation, bool mustCopyBytes) override;
|
||||
protected virtual void setInvocationArg(facebook::jsi::Runtime& runtime, const char* methodName, const std::string& objCArgType, const facebook::jsi::Value& arg, size_t i, NSInvocation* inv, NSMutableArray* retainedObjectsForInvocation) override;
|
||||
public ObjCInteropTurboModule(const facebook::react::ObjCTurboModule::InitParams& params);
|
||||
public virtual std::vector<facebook::jsi::PropNameID> getPropertyNames(facebook::jsi::Runtime& runtime) override;
|
||||
}
|
||||
@@ -6070,7 +6060,7 @@ struct facebook::react::ObjCInteropTurboModule::MethodDescriptor {
|
||||
class facebook::react::ObjCTurboModule : public facebook::react::TurboModule {
|
||||
protected virtual NSString* getArgumentTypeName(facebook::jsi::Runtime& runtime, NSString* methodName, int argIndex);
|
||||
protected virtual facebook::jsi::Value convertReturnIdToJSIValue(facebook::jsi::Runtime& runtime, const char* methodName, facebook::react::TurboModuleMethodValueKind returnType, id result);
|
||||
protected virtual void setInvocationArg(facebook::jsi::Runtime& runtime, const char* methodName, const std::string& objCArgType, const facebook::jsi::Value& arg, size_t i, NSInvocation* inv, NSMutableArray* retainedObjectsForInvocation, bool mustCopyBytes);
|
||||
protected virtual void setInvocationArg(facebook::jsi::Runtime& runtime, const char* methodName, const std::string& objCArgType, const facebook::jsi::Value& arg, size_t i, NSInvocation* inv, NSMutableArray* retainedObjectsForInvocation);
|
||||
protected void setEventEmitterCallback(facebook::react::EventEmitterCallback eventEmitterCallback);
|
||||
protected void setMethodArgConversionSelector(NSString* methodName, size_t argIndex, NSString* fnName);
|
||||
public ObjCTurboModule(const facebook::react::ObjCTurboModule::InitParams& params);
|
||||
@@ -13340,7 +13330,7 @@ struct facebook::react::dom::RNMeasureRect {
|
||||
|
||||
|
||||
facebook::jsi::Value facebook::react::TurboModuleConvertUtils::convertObjCObjectToJSIValue(facebook::jsi::Runtime& runtime, id value);
|
||||
id facebook::react::TurboModuleConvertUtils::convertJSIValueToObjCObject(facebook::jsi::Runtime& runtime, const facebook::jsi::Value& value, const std::shared_ptr<facebook::react::CallInvoker>& jsInvoker, BOOL useNSNull = NO, BOOL mustCopyBytes = YES);
|
||||
id facebook::react::TurboModuleConvertUtils::convertJSIValueToObjCObject(facebook::jsi::Runtime& runtime, const facebook::jsi::Value& value, const std::shared_ptr<facebook::react::CallInvoker>& jsInvoker, BOOL useNSNull = NO);
|
||||
|
||||
|
||||
static const facebook::react::Color facebook::react::HostPlatformColor::UndefinedColor;
|
||||
|
||||
@@ -654,16 +654,6 @@ interface RCTAppearance : public RCTEventEmitter <RCTBridgeModule> {
|
||||
public virtual instancetype init();
|
||||
}
|
||||
|
||||
interface RCTArrayBuffer : public NSObject {
|
||||
public @property (assign, readonly) BOOL owningBytes;
|
||||
public @property (assign, readonly) NSUInteger length;
|
||||
public @property (assign, readonly) void* mutableBytes NS_RETURNS_INNER_POINTER;
|
||||
public virtual static instancetype arrayBufferWithCopiedBytes:length:(const void* _Nullable bytes, NSUInteger length);
|
||||
public virtual static instancetype arrayBufferWithLength:(NSUInteger length);
|
||||
public virtual static instancetype arrayBufferWithOwnedBytes:length:cleanup:(_Nullable void* bytes, NSUInteger length, _Nullable void(^)(void) cleanup);
|
||||
public virtual static instancetype arrayBufferWithUnownedBytes:length:(_Nullable void* bytes, NSUInteger length);
|
||||
}
|
||||
|
||||
interface RCTBackedTextFieldDelegateAdapter : public NSObject {
|
||||
public virtual instancetype initWithTextField:(UITextField<RCTBackedTextInputViewProtocol>* backedTextInputView);
|
||||
public virtual void selectedTextRangeWasSet();
|
||||
@@ -2512,19 +2502,19 @@ protocol NativeSampleTurboModuleSpec : public NSObjectRCTBridgeModule, public RC
|
||||
public virtual NSDictionary* getObjectThrows:(NSDictionary* arg);
|
||||
public virtual NSDictionary* getUnsafeObject:(NSDictionary* arg);
|
||||
public virtual NSDictionary* getValue:y:z:(double x, NSString* y, NSDictionary* z);
|
||||
public virtual NSMutableData* createNativeBuffer:(double size);
|
||||
public virtual NSMutableData* getArrayBuffer:(NSData* buffer);
|
||||
public virtual NSNumber* getBool:(BOOL arg);
|
||||
public virtual NSNumber* getEnum:(double arg);
|
||||
public virtual NSNumber* getNumber:(double arg);
|
||||
public virtual NSNumber* getRootTag:(double arg);
|
||||
public virtual NSString* getString:(NSString* arg);
|
||||
public virtual RCTArrayBuffer* createNativeBuffer:(double size);
|
||||
public virtual RCTArrayBuffer* getArrayBuffer:(RCTArrayBuffer* buffer);
|
||||
public virtual facebook::react::ModuleConstants<JS::NativeSampleTurboModule::Constants> constantsToExport();
|
||||
public virtual facebook::react::ModuleConstants<JS::NativeSampleTurboModule::Constants> getConstants();
|
||||
public virtual void getImageUrl:reject:(RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void getValueWithCallback:(RCTResponseSenderBlock callback);
|
||||
public virtual void getValueWithPromise:resolve:reject:(BOOL error, RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void processAsyncBuffer:resolve:reject:(RCTArrayBuffer* payload, RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void processAsyncBuffer:resolve:reject:(NSData* payload, RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void promiseAssert:reject:(RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void promiseThrows:reject:(RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject);
|
||||
public virtual void voidFunc();
|
||||
@@ -6166,7 +6156,7 @@ class facebook::react::ObjCInteropTurboModule : public facebook::react::ObjCTurb
|
||||
protected virtual NSString* getArgumentTypeName(facebook::jsi::Runtime& runtime, NSString* methodName, int argIndex) override;
|
||||
protected virtual facebook::jsi::Value convertReturnIdToJSIValue(facebook::jsi::Runtime& runtime, const char* methodName, facebook::react::TurboModuleMethodValueKind returnType, id result) override;
|
||||
protected virtual facebook::jsi::Value create(facebook::jsi::Runtime& runtime, const facebook::jsi::PropNameID& propName) override;
|
||||
protected virtual void setInvocationArg(facebook::jsi::Runtime& runtime, const char* methodName, const std::string& objCArgType, const facebook::jsi::Value& arg, size_t i, NSInvocation* inv, NSMutableArray* retainedObjectsForInvocation, bool mustCopyBytes) override;
|
||||
protected virtual void setInvocationArg(facebook::jsi::Runtime& runtime, const char* methodName, const std::string& objCArgType, const facebook::jsi::Value& arg, size_t i, NSInvocation* inv, NSMutableArray* retainedObjectsForInvocation) override;
|
||||
public ObjCInteropTurboModule(const facebook::react::ObjCTurboModule::InitParams& params);
|
||||
public virtual std::vector<facebook::jsi::PropNameID> getPropertyNames(facebook::jsi::Runtime& runtime) override;
|
||||
}
|
||||
@@ -6181,7 +6171,7 @@ struct facebook::react::ObjCInteropTurboModule::MethodDescriptor {
|
||||
class facebook::react::ObjCTurboModule : public facebook::react::TurboModule {
|
||||
protected virtual NSString* getArgumentTypeName(facebook::jsi::Runtime& runtime, NSString* methodName, int argIndex);
|
||||
protected virtual facebook::jsi::Value convertReturnIdToJSIValue(facebook::jsi::Runtime& runtime, const char* methodName, facebook::react::TurboModuleMethodValueKind returnType, id result);
|
||||
protected virtual void setInvocationArg(facebook::jsi::Runtime& runtime, const char* methodName, const std::string& objCArgType, const facebook::jsi::Value& arg, size_t i, NSInvocation* inv, NSMutableArray* retainedObjectsForInvocation, bool mustCopyBytes);
|
||||
protected virtual void setInvocationArg(facebook::jsi::Runtime& runtime, const char* methodName, const std::string& objCArgType, const facebook::jsi::Value& arg, size_t i, NSInvocation* inv, NSMutableArray* retainedObjectsForInvocation);
|
||||
protected void setEventEmitterCallback(facebook::react::EventEmitterCallback eventEmitterCallback);
|
||||
protected void setMethodArgConversionSelector(NSString* methodName, size_t argIndex, NSString* fnName);
|
||||
public ObjCTurboModule(const facebook::react::ObjCTurboModule::InitParams& params);
|
||||
@@ -13515,7 +13505,7 @@ struct facebook::react::dom::RNMeasureRect {
|
||||
|
||||
|
||||
facebook::jsi::Value facebook::react::TurboModuleConvertUtils::convertObjCObjectToJSIValue(facebook::jsi::Runtime& runtime, id value);
|
||||
id facebook::react::TurboModuleConvertUtils::convertJSIValueToObjCObject(facebook::jsi::Runtime& runtime, const facebook::jsi::Value& value, const std::shared_ptr<facebook::react::CallInvoker>& jsInvoker, BOOL useNSNull = NO, BOOL mustCopyBytes = YES);
|
||||
id facebook::react::TurboModuleConvertUtils::convertJSIValueToObjCObject(facebook::jsi::Runtime& runtime, const facebook::jsi::Value& value, const std::shared_ptr<facebook::react::CallInvoker>& jsInvoker, BOOL useNSNull = NO);
|
||||
|
||||
|
||||
static const facebook::react::Color facebook::react::HostPlatformColor::UndefinedColor;
|
||||
|
||||
Reference in new issue
Block a user