Add exception handling in vanilla jni
Summary: Exception handling in vanilla jni ## Changelog: [Internal] [Added] Added exception handling for vanilla jni implementation in yoga Reviewed By: amir-shalem Differential Revision: D18036134 fbshipit-source-id: 965eaa2fddbc00b9ac0120b79678608e280d03db
This commit is contained in:
Родитель
76ab5062e9
Коммит
25e4265fc7
|
@ -352,25 +352,29 @@ static void jni_YGNodeCalculateLayoutJNI(
|
|||
jlongArray nativePointers,
|
||||
jobjectArray javaNodes) {
|
||||
|
||||
void* layoutContext = nullptr;
|
||||
auto map = PtrJNodeMapVanilla{};
|
||||
if (nativePointers) {
|
||||
size_t nativePointersSize = env->GetArrayLength(nativePointers);
|
||||
jlong result[nativePointersSize];
|
||||
env->GetLongArrayRegion(nativePointers, 0, nativePointersSize, result);
|
||||
try {
|
||||
void* layoutContext = nullptr;
|
||||
auto map = PtrJNodeMapVanilla{};
|
||||
if (nativePointers) {
|
||||
size_t nativePointersSize = env->GetArrayLength(nativePointers);
|
||||
jlong result[nativePointersSize];
|
||||
env->GetLongArrayRegion(nativePointers, 0, nativePointersSize, result);
|
||||
|
||||
map = PtrJNodeMapVanilla{result, nativePointersSize, javaNodes};
|
||||
layoutContext = ↦
|
||||
map = PtrJNodeMapVanilla{result, nativePointersSize, javaNodes};
|
||||
layoutContext = ↦
|
||||
}
|
||||
|
||||
const YGNodeRef root = _jlong2YGNodeRef(nativePointer);
|
||||
YGNodeCalculateLayoutWithContext(
|
||||
root,
|
||||
static_cast<float>(width),
|
||||
static_cast<float>(height),
|
||||
YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer)),
|
||||
layoutContext);
|
||||
YGTransferLayoutOutputsRecursive(env, obj, root, layoutContext);
|
||||
} catch (jthrowable throwable) {
|
||||
env->Throw(throwable);
|
||||
}
|
||||
|
||||
const YGNodeRef root = _jlong2YGNodeRef(nativePointer);
|
||||
YGNodeCalculateLayoutWithContext(
|
||||
root,
|
||||
static_cast<float>(width),
|
||||
static_cast<float>(height),
|
||||
YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer)),
|
||||
layoutContext);
|
||||
YGTransferLayoutOutputsRecursive(env, obj, root, layoutContext);
|
||||
}
|
||||
|
||||
static void jni_YGNodeMarkDirtyJNI(
|
||||
|
|
|
@ -62,12 +62,16 @@ void logErrorMessageAndDie(const char* message) {
|
|||
}
|
||||
|
||||
void assertNoPendingJniException(JNIEnv* env) {
|
||||
// This method cannot call any other method of the library, since other
|
||||
// methods of the library use it to check for exceptions too
|
||||
if (env->ExceptionCheck()) {
|
||||
env->ExceptionDescribe();
|
||||
logErrorMessageAndDie("Aborting due to pending Java exception in JNI");
|
||||
if (env->ExceptionCheck() == JNI_FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto throwable = env->ExceptionOccurred();
|
||||
if (!throwable) {
|
||||
logErrorMessageAndDie("Unable to get pending JNI exception.");
|
||||
}
|
||||
env->ExceptionClear();
|
||||
throw throwable;
|
||||
}
|
||||
|
||||
} // namespace vanillajni
|
||||
|
|
Загрузка…
Ссылка в новой задаче