Skip to content

Commit 7a8de7d

Browse files
RSNarafacebook-github-bot
authored andcommitted
Replace throwIfJNIReportsPendingException
Summary: Looks like FBJNI exports a C Macro that does exactly what `throwIfJNIReportsPendingException` does. Therefore, I'm replacing `throwIfJNIReportsPendingException` with calls to `FACEBOOK_JNI_THROW_PENDING_EXCEPTION()`. Reviewed By: mdvacca Differential Revision: D15174820 fbshipit-source-id: 9dfb519352cbd5f37527675323cbabad05e31d4a
1 parent a965070 commit 7a8de7d

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

ReactCommon/turbomodule/core/platform/android/JavaTurboModule.cpp

+8-25
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,6 @@ jsi::Value convertFromJMapToValue(JNIEnv *env, jsi::Runtime &rt, jobject arg) {
117117
return jsi::valueFromDynamic(rt, result->cthis()->consume());
118118
}
119119

120-
static void throwIfJNIReportsPendingException() {
121-
JNIEnv *env = jni::Environment::current();
122-
if (env->ExceptionCheck()) {
123-
jthrowable ex = env->ExceptionOccurred();
124-
125-
// There should be no pending exceptions before we call into JNI
126-
env->ExceptionClear();
127-
128-
auto exception = jni::adopt_local(ex);
129-
auto getMessage =
130-
exception->getClass()->getMethod<std::string()>("getMessage");
131-
auto message = getMessage(exception)->toStdString();
132-
133-
throw std::runtime_error(message);
134-
}
135-
}
136-
137120
jsi::Value JavaTurboModule::invokeJavaMethod(
138121
jsi::Runtime &runtime,
139122
TurboModuleMethodValueKind valueKind,
@@ -151,7 +134,7 @@ jsi::Value JavaTurboModule::invokeJavaMethod(
151134
// TODO(T43933641): Refactor to remove this special-casing
152135
if (methodName == "getConstants") {
153136
auto constantsMap = (jobject)env->CallObjectMethod(instance, methodID);
154-
throwIfJNIReportsPendingException();
137+
FACEBOOK_JNI_THROW_PENDING_EXCEPTION();
155138

156139
if (constantsMap == nullptr) {
157140
return jsi::Value::undefined();
@@ -166,28 +149,28 @@ jsi::Value JavaTurboModule::invokeJavaMethod(
166149
switch (valueKind) {
167150
case VoidKind: {
168151
env->CallVoidMethodA(instance, methodID, jargs.data());
169-
throwIfJNIReportsPendingException();
152+
FACEBOOK_JNI_THROW_PENDING_EXCEPTION();
170153

171154
return jsi::Value::undefined();
172155
}
173156
case BooleanKind: {
174157
bool returnBoolean =
175158
(bool)env->CallBooleanMethodA(instance, methodID, jargs.data());
176-
throwIfJNIReportsPendingException();
159+
FACEBOOK_JNI_THROW_PENDING_EXCEPTION();
177160

178161
return jsi::Value(returnBoolean);
179162
}
180163
case NumberKind: {
181164
double returnDouble =
182165
(double)env->CallDoubleMethodA(instance, methodID, jargs.data());
183-
throwIfJNIReportsPendingException();
166+
FACEBOOK_JNI_THROW_PENDING_EXCEPTION();
184167

185168
return jsi::Value(returnDouble);
186169
}
187170
case StringKind: {
188171
auto returnString =
189172
(jstring)env->CallObjectMethodA(instance, methodID, jargs.data());
190-
throwIfJNIReportsPendingException();
173+
FACEBOOK_JNI_THROW_PENDING_EXCEPTION();
191174

192175
if (returnString == nullptr) {
193176
return jsi::Value::null();
@@ -200,7 +183,7 @@ jsi::Value JavaTurboModule::invokeJavaMethod(
200183
case ObjectKind: {
201184
auto returnObject =
202185
(jobject)env->CallObjectMethodA(instance, methodID, jargs.data());
203-
throwIfJNIReportsPendingException();
186+
FACEBOOK_JNI_THROW_PENDING_EXCEPTION();
204187

205188
if (returnObject == nullptr) {
206189
return jsi::Value::null();
@@ -212,7 +195,7 @@ jsi::Value JavaTurboModule::invokeJavaMethod(
212195
case ArrayKind: {
213196
auto returnObject =
214197
(jobject)env->CallObjectMethodA(instance, methodID, jargs.data());
215-
throwIfJNIReportsPendingException();
198+
FACEBOOK_JNI_THROW_PENDING_EXCEPTION();
216199

217200
if (returnObject == nullptr) {
218201
return jsi::Value::null();
@@ -268,7 +251,7 @@ jsi::Value JavaTurboModule::invokeJavaMethod(
268251

269252
jsi::Value promise =
270253
Promise.callAsConstructor(runtime, promiseConstructorArg);
271-
throwIfJNIReportsPendingException();
254+
FACEBOOK_JNI_THROW_PENDING_EXCEPTION();
272255

273256
return promise;
274257
}

0 commit comments

Comments
 (0)