react-native-macos/ReactCommon
Ramanpreet Nara ff9323a0b0 Type-check JS args when converting them to Java args
Summary:
When you call a TurboModule method with JS arguments, we necessarily convert these JS args to Java objects/primitives before passing them to the Java implementation of the method. The problem is that we let the type of the JS arg dictate the type of the Java object/primitive to convert said arg to. This means that if a JS developer passes in an `number` to a function that expects an `Array`, we'll convert the number to a `double` and try to call the Java method with that `double`, when it actually expects a `ReadableArray`. This will trigger a JNI error, and crash the program. Ideally, we should be able to catch these type mismatches early on.

In this diff, on every TurboModule method call, I parse the method signature to determine the Java type of each JS argument. Then, for any argument, if the JS arg and the Java arg types aren't compatible, I raise an exception, which gets displayed as a RedBox in development. This diff also implements support for `?number` and `?boolean` argument and return types in TurboModules.

Reviewed By: mdvacca

Differential Revision: D16214814

fbshipit-source-id: 4399bb88c5344cff50aa8fe8d54eb2000990a852
2019-07-12 22:54:55 -07:00
..
better Fabric: Enable CXX (aka Default) platfrom fravour for all C++ Fabric targets 2019-06-04 15:34:34 -07:00
config Fabric: Enable CXX (aka Default) platfrom fravour for all C++ Fabric targets 2019-06-04 15:34:34 -07:00
cxxreact CocoaPods frameworks compatibility: Step 1 (#25496) 2019-07-10 10:21:38 -07:00
fabric Fabric: Removing `SharedAccessibilityProps` and some code style changes 2019-07-10 19:26:50 -07:00
jscallinvoker TM iOS: move jscallinvoker under ReactCommon podspec 2019-07-12 22:44:20 -07:00
jsi CocoaPods frameworks compatibility: Step 1 (#25496) 2019-07-10 10:21:38 -07:00
jsiexecutor CocoaPods frameworks compatibility: Step 1 (#25496) 2019-07-10 10:21:38 -07:00
jsinspector Split React.podspec into separate podspecs for each Xcode project (#23559) 2019-02-21 18:35:44 -08:00
microprofiler Upgrade mobile BUCK and .bzl files to use C++14 2019-03-16 02:25:33 -07:00
turbomodule Type-check JS args when converting them to Java args 2019-07-12 22:54:55 -07:00
utils Fabric: New names for ContextContainer methods 2019-06-07 12:03:57 -07:00
yoga CocoaPods frameworks compatibility: Step 1 (#25496) 2019-07-10 10:21:38 -07:00
React-Fabric.podspec Excluded tests file from JSI pod (#25151) 2019-06-05 05:12:19 -07:00
ReactCommon.podspec TM iOS: move jscallinvoker under ReactCommon podspec 2019-07-12 22:44:20 -07:00