From 63b6d3eab1d5990cb5983631c31c5c64f0b40afd Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Tue, 3 Oct 2023 10:49:20 -0700 Subject: [PATCH] lift isSyncModule_ check outside of isMethodSync (#39590) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39590 Changelog: [Internal] some cleanup! Reviewed By: javache Differential Revision: D49521863 fbshipit-source-id: 19e988dd7059db5f9721aa36a7f376593143e6c9 --- .../ios/ReactCommon/RCTTurboModule.mm | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 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 b9a0996bff3a0e..6717b9dc5eb93d 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 @@ -680,11 +680,15 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s bool ObjCTurboModule::isMethodSync(TurboModuleMethodValueKind returnType) { + if (isSyncModule_) { + return true; + } + if (returnType == VoidKind && shouldVoidMethodsExecuteSync_) { return true; } - return isSyncModule_ || !(returnType == VoidKind || returnType == PromiseKind); + return !(returnType == VoidKind || returnType == PromiseKind); } ObjCTurboModule::ObjCTurboModule(const InitParams ¶ms) @@ -707,7 +711,9 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s const char *moduleName = name_.c_str(); const char *methodName = methodNameStr.c_str(); - if (isMethodSync(returnType)) { + bool isSyncInvocation = isMethodSync(returnType); + + if (isSyncInvocation) { TurboModulePerfLogger::syncMethodCallStart(moduleName, methodName); } else { TurboModulePerfLogger::asyncMethodCallStart(moduleName, methodName); @@ -715,7 +721,7 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s NSMutableArray *retainedObjectsForInvocation = [NSMutableArray arrayWithCapacity:count + 2]; NSInvocation *inv = createMethodInvocation( - runtime, isMethodSync(returnType), methodName, selector, args, count, retainedObjectsForInvocation); + runtime, isSyncInvocation, methodName, selector, args, count, retainedObjectsForInvocation); jsi::Value returnValue = jsi::Value::undefined(); @@ -730,24 +736,23 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s [retainedObjectsForInvocation addObject:resolveCopy]; [retainedObjectsForInvocation addObject:rejectCopy]; // The return type becomes void in the ObjC side. - performMethodInvocation(runtime, isMethodSync(VoidKind), methodName, inv, retainedObjectsForInvocation); + performMethodInvocation(runtime, isSyncInvocation, methodName, inv, retainedObjectsForInvocation); }); } else { - id result = - performMethodInvocation(runtime, isMethodSync(returnType), methodName, inv, retainedObjectsForInvocation); + id result = performMethodInvocation(runtime, isSyncInvocation, methodName, inv, retainedObjectsForInvocation); - if (isMethodSync(returnType)) { + if (isSyncInvocation) { TurboModulePerfLogger::syncMethodCallReturnConversionStart(moduleName, methodName); } returnValue = convertReturnIdToJSIValue(runtime, methodName, returnType, result); - if (isMethodSync(returnType)) { + if (isSyncInvocation) { TurboModulePerfLogger::syncMethodCallReturnConversionEnd(moduleName, methodName); } } - if (isMethodSync(returnType)) { + if (isSyncInvocation) { TurboModulePerfLogger::syncMethodCallEnd(moduleName, methodName); } else { TurboModulePerfLogger::asyncMethodCallEnd(moduleName, methodName);