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: 1caabea207d84e02644a80ea736d7b51a7becca8
This commit is contained in:
Phillip Pan 2023-10-03 12:14:15 -07:00 коммит произвёл Facebook GitHub Bot
Родитель c41cddf150
Коммит 36a202b0e5
1 изменённых файлов: 14 добавлений и 9 удалений

Просмотреть файл

@ -680,11 +680,15 @@ NSInvocation *ObjCTurboModule::createMethodInvocation(
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 &params)
@ -707,7 +711,9 @@ jsi::Value ObjCTurboModule::invokeObjCMethod(
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 @@ jsi::Value ObjCTurboModule::invokeObjCMethod(
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 @@ jsi::Value ObjCTurboModule::invokeObjCMethod(
[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);