From 05dee839d82968dec421db6cdb2721dbb406d1f4 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 16 May 2025 08:47:55 -0700 Subject: [PATCH] Use methodSignatureForSelector instead of instanceMethodSignatureForSelector (#51366) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51366 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] Reviewed By: sammy-SC Differential Revision: D74817191 fbshipit-source-id: 6f3f741e9a78dea967a7654e6410ddacfad6d8a3 --- .../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 441a16f419f..e8ad078da5f 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 @@ NSInvocation *ObjCTurboModule::createMethodInvocation( 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 @@ NSInvocation *ObjCTurboModule::createMethodInvocation( 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];