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 6268f7610054c0..2d6aa7df8b61a0 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 @@ -725,32 +725,43 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s jsi::Value returnValue = jsi::Value::undefined(); - if (returnType == PromiseKind) { - returnValue = createPromise( - runtime, methodNameStr, ^(RCTPromiseResolveBlock resolveBlock, RCTPromiseRejectBlock rejectBlock) { - RCTPromiseResolveBlock resolveCopy = [resolveBlock copy]; - RCTPromiseRejectBlock rejectCopy = [rejectBlock copy]; - - [inv setArgument:(void *)&resolveCopy atIndex:count + 2]; - [inv setArgument:(void *)&rejectCopy atIndex:count + 3]; - [retainedObjectsForInvocation addObject:resolveCopy]; - [retainedObjectsForInvocation addObject:rejectCopy]; - // The return type becomes void in the ObjC side. - performMethodInvocation(runtime, isSyncInvocation, methodName, inv, retainedObjectsForInvocation); - }); - } else { - id result = - performMethodInvocation(runtime, isSyncInvocation, methodName, inv, retainedObjectsForInvocation); - - if (isSyncInvocation) { - TurboModulePerfLogger::syncMethodCallReturnConversionStart(moduleName, methodName); + switch (returnType) { + case PromiseKind: { + returnValue = createPromise( + runtime, methodNameStr, ^(RCTPromiseResolveBlock resolveBlock, RCTPromiseRejectBlock rejectBlock) { + RCTPromiseResolveBlock resolveCopy = [resolveBlock copy]; + RCTPromiseRejectBlock rejectCopy = [rejectBlock copy]; + [inv setArgument:(void *)&resolveCopy atIndex:count + 2]; + [inv setArgument:(void *)&rejectCopy atIndex:count + 3]; + [retainedObjectsForInvocation addObject:resolveCopy]; + [retainedObjectsForInvocation addObject:rejectCopy]; + // The return type becomes void in the ObjC side. + performMethodInvocation(runtime, isSyncInvocation, methodName, inv, retainedObjectsForInvocation); + }); + break; } - - returnValue = convertReturnIdToJSIValue(runtime, methodName, returnType, result); - - if (isSyncInvocation) { - TurboModulePerfLogger::syncMethodCallReturnConversionEnd(moduleName, methodName); + case VoidKind: { + id result = performMethodInvocation(runtime, isSyncInvocation, methodName, inv, retainedObjectsForInvocation); + if (isSyncInvocation) { + TurboModulePerfLogger::syncMethodCallReturnConversionStart(moduleName, methodName); + } + returnValue = convertReturnIdToJSIValue(runtime, methodName, returnType, result); + if (isSyncInvocation) { + TurboModulePerfLogger::syncMethodCallReturnConversionEnd(moduleName, methodName); + } + break; } + case BooleanKind: + case NumberKind: + case StringKind: + case ObjectKind: + case ArrayKind: + case FunctionKind: { + id result = performMethodInvocation(runtime, true, methodName, inv, retainedObjectsForInvocation); + TurboModulePerfLogger::syncMethodCallReturnConversionStart(moduleName, methodName); + returnValue = convertReturnIdToJSIValue(runtime, methodName, returnType, result); + TurboModulePerfLogger::syncMethodCallReturnConversionEnd(moduleName, methodName); + } break; } if (isSyncInvocation) {