Skip to content

Commit

Permalink
lift isSyncModule_ check outside of isMethodSync (facebook#39590)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#39590

Changelog: [Internal]

some cleanup!

Reviewed By: javache

Differential Revision: D49521863

fbshipit-source-id: ecba6c9e13b42c95d5074a14919d371420f9aee5
  • Loading branch information
philIip authored and facebook-github-bot committed Oct 3, 2023
1 parent 7e254a0 commit c2f910e
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 &params)
Expand All @@ -707,15 +711,17 @@ 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);
}

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();

Expand All @@ -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);
Expand Down

0 comments on commit c2f910e

Please sign in to comment.