create global ref properly in YogaJNIException

Summary:
##Changelog:
[Internal][Yoga] create global ref properly in YogaJNIException

Reviewed By: astreet

Differential Revision: D18775982

fbshipit-source-id: ee529d6178d40b5f887fa1327fe156fa466f154f
This commit is contained in:
Sidharth Guglani
2019-12-03 15:57:51 -08:00
committed by Facebook Github Bot
parent ac8eb111a9
commit 089095f532
3 changed files with 19 additions and 4 deletions

View File

@@ -19,18 +19,19 @@ YogaJniException::YogaJniException() {
static const jmethodID methodId = facebook::yoga::vanillajni::getMethodId(
getCurrentEnv(), cl, "<init>", "()V");
auto throwable = getCurrentEnv()->NewObject(cl, methodId);
throwable_ = make_global_ref(static_cast<jthrowable>(throwable));
throwable_ =
newGlobalRef(getCurrentEnv(), static_cast<jthrowable>(throwable));
}
YogaJniException::YogaJniException(jthrowable throwable) {
throwable_ = make_global_ref(throwable);
throwable_ = newGlobalRef(getCurrentEnv(), throwable);
}
YogaJniException::YogaJniException(YogaJniException&& rhs)
: throwable_(std::move(rhs.throwable_)) {}
YogaJniException::YogaJniException(const YogaJniException& rhs) {
throwable_ = make_global_ref(rhs.throwable_.get());
throwable_ = newGlobalRef(getCurrentEnv(), rhs.throwable_.get());
}
YogaJniException::~YogaJniException() {
@@ -42,7 +43,9 @@ YogaJniException::~YogaJniException() {
}
ScopedLocalRef<jthrowable> YogaJniException::getThrowable() const noexcept {
return make_local_ref(getCurrentEnv(), throwable_.get());
return make_local_ref(
getCurrentEnv(),
static_cast<jthrowable>(getCurrentEnv()->NewLocalRef(throwable_.get())));
}
} // namespace vanillajni
} // namespace yoga