Skip to content

Commit

Permalink
Fix boolean conversion in sync RN method calls.
Browse files Browse the repository at this point in the history
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 dd888d3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions ReactAndroid/src/main/jni/react/jni/MethodInvoker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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':
Expand All @@ -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':
Expand Down

0 comments on commit dd888d3

Please sign in to comment.