Skip to content

Commit d6c5772

Browse files
javachemeta-codesync[bot]
authored andcommitted
Improve error when calling TM with too many args (#54691)
Summary: Pull Request resolved: #54691 Improve error message for incorrect TurboModule invocations to avoid HostFunction: <unknown error> Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D87868433 fbshipit-source-id: f351a6e7ea59c56fcb0991eb799c4217382fdb4e
1 parent 336042c commit d6c5772

File tree

1 file changed

+7
-1
lines changed
  • packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon

1 file changed

+7
-1
lines changed

packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,19 @@ TraceSection s(
732732
}
733733

734734
NSMethodSignature *methodSignature = [module methodSignatureForSelector:selector];
735+
if (count > methodSignature.numberOfArguments - 2) {
736+
throw jsi::JSError(
737+
runtime,
738+
name_ + "." + methodName + " called with too many arguments, expected up to " +
739+
std::to_string(methodSignature.numberOfArguments - 2) + ", got " + std::to_string(count));
740+
}
741+
735742
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:methodSignature];
736743
[inv setSelector:selector];
737744

738745
for (size_t i = 0; i < count; i++) {
739746
const jsi::Value &arg = args[i];
740747
const std::string objCArgType = [methodSignature getArgumentTypeAtIndex:i + 2];
741-
742748
setInvocationArg(runtime, methodName, objCArgType, arg, i, inv, retainedObjectsForInvocation);
743749
}
744750

0 commit comments

Comments
 (0)