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
This commit is contained in:
Pieter De Baets
2025-05-16 08:47:55 -07:00
committed by Facebook GitHub Bot
parent 83ed4620d6
commit 05dee839d8
@@ -686,7 +686,7 @@ NSInvocation *ObjCTurboModule::createMethodInvocation(
NSMutableArray *retainedObjectsForInvocation)
{
const char *moduleName = name_.c_str();
const id<RCTBridgeModule> module = instance_;
const NSObject<RCTBridgeModule> *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];