From dd888d3346ef9477eae2cd2d29cef867467cb503 Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Fri, 24 Nov 2017 12:28:56 -0800 Subject: [PATCH] Fix boolean conversion in sync RN method calls. Reviewed By: fromcelticpark Differential Revision: D6408182 fbshipit-source-id: 251ab0cfe3197e59de0cb86816d5f0b908433b43 --- .../src/main/jni/react/jni/MethodInvoker.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/jni/react/jni/MethodInvoker.cpp b/ReactAndroid/src/main/jni/react/jni/MethodInvoker.cpp index 405cf1fd6..deb289714 100644 --- a/ReactAndroid/src/main/jni/react/jni/MethodInvoker.cpp +++ b/ReactAndroid/src/main/jni/react/jni/MethodInvoker.cpp @@ -158,7 +158,7 @@ MethodInvoker::MethodInvoker(alias_ref method, std:: isSync_(isSync) { CHECK(signature_.at(1) == '.') << "Improper module method signature"; CHECK(isSync_ || signature_.at(0) == 'v') << "Non-sync hooks cannot have a non-void return type"; - } +} MethodCallResult MethodInvoker::invoke(std::weak_ptr& instance, alias_ref module, const folly::dynamic& params) { #ifdef WITH_FBSYSTRACE @@ -191,6 +191,12 @@ MethodCallResult MethodInvoker::invoke(std::weak_ptr& instance, alias_ return folly::dynamic(result); \ } +#define PRIMITIVE_CASE_CASTING(METHOD, RESULT_TYPE) { \ + auto result = env->Call ## METHOD ## MethodA(module.get(), method_, args); \ + throwPendingJniExceptionAsCppException(); \ + return folly::dynamic(static_cast(result)); \ +} + #define OBJECT_CASE(JNI_CLASS, ACTIONS) { \ auto jobject = env->CallObjectMethodA(module.get(), method_, args); \ throwPendingJniExceptionAsCppException(); \ @@ -198,6 +204,13 @@ MethodCallResult MethodInvoker::invoke(std::weak_ptr& instance, alias_ return folly::dynamic(result->ACTIONS()); \ } +#define OBJECT_CASE_CASTING(JNI_CLASS, ACTIONS, RESULT_TYPE) { \ + auto jobject = env->CallObjectMethodA(module.get(), method_, args); \ + throwPendingJniExceptionAsCppException(); \ + auto result = adopt_local(static_cast(jobject)); \ + return folly::dynamic(static_cast(result->ACTIONS())); \ +} + char returnType = signature_.at(0); switch (returnType) { case 'v': @@ -206,9 +219,9 @@ MethodCallResult MethodInvoker::invoke(std::weak_ptr& instance, alias_ return folly::none; case 'z': - PRIMITIVE_CASE(Boolean) + PRIMITIVE_CASE_CASTING(Boolean, bool) case 'Z': - OBJECT_CASE(JBoolean, value) + OBJECT_CASE_CASTING(JBoolean, value, bool) case 'i': PRIMITIVE_CASE(Int) case 'I':