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())) { } else if (object->isInstanceOf(jni::JBoolean::javaClassStatic())) {
// Boolean // Boolean
static const auto getBooleanFunc = jni::findClassLocal("java/lang/Boolean")->getMethod<jboolean()>("booleanValue"); auto boxed = static_ref_cast<JBoolean>(object);
auto boolean = getBooleanFunc(object.get()); bool value = boxed->value();
return jsi::Value(boolean == true); return jsi::Value(value);
} else if (object->isInstanceOf(jni::JDouble::javaClassStatic())) { } else if (object->isInstanceOf(jni::JDouble::javaClassStatic())) {
// Double // Double
static const auto getDoubleFunc = jni::findClassLocal("java/lang/Double")->getMethod<jdouble()>("doubleValue"); auto boxed = static_ref_cast<JDouble>(object);
auto d = getDoubleFunc(object.get()); double value = boxed->value();
return jsi::Value(d); return jsi::Value(value);
} else if (object->isInstanceOf(jni::JInteger::javaClassStatic())) { } else if (object->isInstanceOf(jni::JInteger::javaClassStatic())) {
// Integer // Integer
static const auto getIntegerFunc = jni::findClassLocal("java/lang/Integer")->getMethod<jint()>("intValue"); auto boxed = static_ref_cast<JInteger>(object);
auto i = getIntegerFunc(object.get()); return jsi::Value(boxed->value());
return jsi::Value(i);
} else if (object->isInstanceOf(jni::JString::javaClassStatic())) { } else if (object->isInstanceOf(jni::JString::javaClassStatic())) {
// String // String