Permalink
Browse files

Fix boolean conversion in sync RN method calls.

Reviewed By: fromcelticpark

Differential Revision: D6408182

fbshipit-source-id: 251ab0cfe3197e59de0cb86816d5f0b908433b43
  • Loading branch information...
Dmitry Zakharov authored and facebook-github-bot committed Nov 24, 2017
1 parent f5beceb commit dd888d3346ef9477eae2cd2d29cef867467cb503
Showing with 16 additions and 3 deletions.
  1. +16 −3 ReactAndroid/src/main/jni/react/jni/MethodInvoker.cpp
@@ -158,7 +158,7 @@ MethodInvoker::MethodInvoker(alias_ref<JReflectMethod::javaobject> 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>& instance, alias_ref<JBaseJavaModule::javaobject> module, const folly::dynamic& params) {
#ifdef WITH_FBSYSTRACE
@@ -191,13 +191,26 @@ MethodCallResult MethodInvoker::invoke(std::weak_ptr<Instance>& 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_TYPE>(result)); \
}
#define OBJECT_CASE(JNI_CLASS, ACTIONS) { \
auto jobject = env->CallObjectMethodA(module.get(), method_, args); \
throwPendingJniExceptionAsCppException(); \
auto result = adopt_local(static_cast<JNI_CLASS::javaobject>(jobject)); \
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<JNI_CLASS::javaobject>(jobject)); \
return folly::dynamic(static_cast<RESULT_TYPE>(result->ACTIONS())); \
}
char returnType = signature_.at(0);
switch (returnType) {
case 'v':
@@ -206,9 +219,9 @@ MethodCallResult MethodInvoker::invoke(std::weak_ptr<Instance>& 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':

0 comments on commit dd888d3

Please sign in to comment.