Fix boolean conversion in sync RN method calls.
Reviewed By: fromcelticpark Differential Revision: D6408182 fbshipit-source-id: 251ab0cfe3197e59de0cb86816d5f0b908433b43
This commit is contained in:
parent
f5becebc07
commit
dd888d3346
|
@ -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,6 +191,12 @@ 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(); \
|
||||
|
@ -198,6 +204,13 @@ MethodCallResult MethodInvoker::invoke(std::weak_ptr<Instance>& 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<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':
|
||||
|
|
Loading…
Reference in New Issue