From 3ab1cc0f7f74535484ca7d6b0d81833477d74d10 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Tue, 25 Nov 2025 09:43:37 -0800 Subject: [PATCH] Improve error when calling TM with too many args Summary: Improve error message for incorrect TurboModule invocations to avoid HostFunction: Changelog: [Internal] Differential Revision: D87868433 --- .../core/platform/ios/ReactCommon/RCTTurboModule.mm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 664657021cc0..792801a5a686 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 @@ -732,13 +732,19 @@ TraceSection s( } NSMethodSignature *methodSignature = [module methodSignatureForSelector:selector]; + if (count > methodSignature.numberOfArguments - 2) { + throw jsi::JSError( + runtime, + name_ + "." + methodName + " called with too many arguments, expected up to " + + std::to_string(methodSignature.numberOfArguments - 2) + ", got " + std::to_string(count)); + } + NSInvocation *inv = [NSInvocation invocationWithMethodSignature:methodSignature]; [inv setSelector:selector]; for (size_t i = 0; i < count; i++) { const jsi::Value &arg = args[i]; const std::string objCArgType = [methodSignature getArgumentTypeAtIndex:i + 2]; - setInvocationArg(runtime, methodName, objCArgType, arg, i, inv, retainedObjectsForInvocation); }