From 2e7bdb04c0fcf3a55ba768d0e7f2b6e4b1ca54f1 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Thu, 15 May 2025 08:43:12 -0700 Subject: [PATCH] Use methodSignatureForSelector instead of instanceMethodSignatureForSelector Summary: We inherited this from the legacy native module infra, where we didn't have access to the module instance. Instead we can use the simpler `methodSignatureForSelector` which works correctly with OCMock (needed in D74815079). Changelog: [Internal] Differential Revision: D74817191 --- .../core/platform/ios/ReactCommon/RCTTurboModule.mm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm index 441a16f419f3..e8ad078da5f0 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm @@ -686,7 +686,7 @@ TraceSection s( NSMutableArray *retainedObjectsForInvocation) { const char *moduleName = name_.c_str(); - const id module = instance_; + const NSObject *module = instance_; if (isSync) { TurboModulePerfLogger::syncMethodCallArgConversionStart(moduleName, methodName); @@ -694,12 +694,10 @@ TraceSection s( TurboModulePerfLogger::asyncMethodCallArgConversionStart(moduleName, methodName); } - NSInvocation *inv = - [NSInvocation invocationWithMethodSignature:[[module class] instanceMethodSignatureForSelector:selector]]; + NSMethodSignature *methodSignature = [module methodSignatureForSelector:selector]; + NSInvocation *inv = [NSInvocation invocationWithMethodSignature:methodSignature]; [inv setSelector:selector]; - NSMethodSignature *methodSignature = [[module class] instanceMethodSignatureForSelector:selector]; - for (size_t i = 0; i < count; i++) { const jsi::Value &arg = args[i]; const std::string objCArgType = [methodSignature getArgumentTypeAtIndex:i + 2];