From c9c8f8d5b33716da50060dc23a591cb813157098 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Mon, 22 Apr 2019 15:28:43 -0700 Subject: [PATCH] Remove jClassName_ member Summary: `jClassName_` is unnecessary because you can use `JNIEnv::GetObjectClass` to get the TurboModule's Java class. Reviewed By: fkgozali Differential Revision: D14937480 fbshipit-source-id: 2c1c9be53217331152270dbac3d13f372a2ed818 --- .../core/platform/android/JavaTurboModule.cpp | 13 ++++++++----- .../core/platform/android/JavaTurboModule.h | 4 ---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.cpp b/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.cpp index fa54312c483..988b82dfd28 100644 --- a/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.cpp +++ b/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.cpp @@ -129,7 +129,8 @@ jsi::Value JavaTurboModule::get(jsi::Runtime& runtime, const jsi::PropNameID& pr 0, [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) { JNIEnv *env = jni::Environment::current(); - jclass cls = env->FindClass(jClassName_.c_str()); + auto instance = instance_.get(); + jclass cls = env->GetObjectClass(instance); static jmethodID methodID = env->GetMethodID(cls, "getConstants", "()Ljava/util/Map;"); auto constantsMap = (jobject) env->CallObjectMethod(instance_.get(), methodID); if (constantsMap == nullptr) { @@ -170,15 +171,15 @@ jsi::Value JavaTurboModule::invokeJavaMethod( // We are using JNI directly instead of fbjni since we don't want template functiosn // when finding methods. JNIEnv *env = jni::Environment::current(); - // TODO (axe) Memoize this class, so that we don't have to find it for every calls - jclass cls = env->FindClass(jClassName_.c_str()); + auto instance = instance_.get(); + + jclass cls = env->GetObjectClass(instance); // TODO (axe) Memoize method call, so we don't look it up each time the method is called jmethodID methodID = env->GetMethodID(cls, methodName.c_str(), methodSignature.c_str()); std::vector jargs = convertJSIArgsToJNIArgs(env, runtime, args, count, jsInvoker_, valueKind); - auto instance = instance_.get(); switch (valueKind) { case VoidKind: { @@ -290,7 +291,9 @@ jsi::Value JavaTurboModule::invokeJavaMethod( return promise; } default: - throw std::runtime_error("Unable to find method module: " + methodName + "(" + methodSignature + ")" + "in module " + jClassName_); + throw std::runtime_error( + "Unable to find method module: " + methodName + "(" + + methodSignature + ")"); } } diff --git a/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.h b/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.h index 38837618e54..ce4fd0f5ee7 100644 --- a/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.h +++ b/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.h @@ -32,10 +32,6 @@ public: size_t count); virtual facebook::jsi::Value get(facebook::jsi::Runtime& runtime, const facebook::jsi::PropNameID& propName) override; - -protected: - // TODO (axe) Specify class name as kJavaDescriptor instead of a class variable - std::string jClassName_; private: jni::global_ref instance_; jclass findClass(JNIEnv *env) const;