Skip to content

Commit f85e590

Browse files
r-barnesfacebook-github-bot
authored andcommitted
Throw on unexpected return types for number TurboModule methods on Android
Summary: In `JavaTurboModule::invokeJavaMethod`, the `NumberKind` case only handled boxed `Double`/`Float`/`Integer` and primitive `D`/`F`/`I` return types. Any other return type fell through into the `StringKind` case, which called the method as an object-returning method and converted the result as a string. Throw a `std::runtime_error` naming the method and its return type instead, matching how the `default` case reports an unknown method kind. Changelog: [Android][Fixed] - Throw an error instead of treating the result as a string when a number TurboModule method has an unexpected return type Differential Revision: D131835371
1 parent 70f655a commit f85e590

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

  • packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon

‎packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,9 @@ jsi::Value JavaTurboModule::invokeJavaMethod(
864864
TMPL::syncMethodCallEnd(moduleName, methodName);
865865
return returnValue;
866866
}
867+
throw std::runtime_error(
868+
"Unexpected return type " + returnType +
869+
" for number method: " + std::string(methodName));
867870
}
868871
case StringKind: {
869872
auto returnString =

0 commit comments

Comments
 (0)