fix: Unwrap boxed JNI types directly (#2337)

* fix: Unwrap boxed JNI types directly

* Update JSIJNIConversion.cpp
This commit is contained in:
Marc Rousavy 2024-01-02 14:13:47 +01:00 committed by GitHub
parent 3dc75112ae
commit ef4e9fabf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -103,21 +103,20 @@ jsi::Value JSIJNIConversion::convertJNIObjectToJSIValue(jsi::Runtime& runtime, c
} else if (object->isInstanceOf(jni::JBoolean::javaClassStatic())) {
// Boolean
static const auto getBooleanFunc = jni::findClassLocal("java/lang/Boolean")->getMethod<jboolean()>("booleanValue");
auto boolean = getBooleanFunc(object.get());
return jsi::Value(boolean == true);
auto boxed = static_ref_cast<JBoolean>(object);
bool value = boxed->value();
return jsi::Value(value);
} else if (object->isInstanceOf(jni::JDouble::javaClassStatic())) {
// Double
static const auto getDoubleFunc = jni::findClassLocal("java/lang/Double")->getMethod<jdouble()>("doubleValue");
auto d = getDoubleFunc(object.get());
return jsi::Value(d);
auto boxed = static_ref_cast<JDouble>(object);
double value = boxed->value();
return jsi::Value(value);
} else if (object->isInstanceOf(jni::JInteger::javaClassStatic())) {
// Integer
static const auto getIntegerFunc = jni::findClassLocal("java/lang/Integer")->getMethod<jint()>("intValue");
auto i = getIntegerFunc(object.get());
return jsi::Value(i);
auto boxed = static_ref_cast<JInteger>(object);
return jsi::Value(boxed->value());
} else if (object->isInstanceOf(jni::JString::javaClassStatic())) {
// String