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:
Sidharth Guglani 2019-10-22 10:45:20 -07:00 коммит произвёл Facebook Github Bot
Родитель 76ab5062e9
Коммит 25e4265fc7
2 изменённых файлов: 30 добавлений и 22 удалений

Просмотреть файл

@ -352,25 +352,29 @@ static void jni_YGNodeCalculateLayoutJNI(
jlongArray nativePointers, jlongArray nativePointers,
jobjectArray javaNodes) { jobjectArray javaNodes) {
void* layoutContext = nullptr; try {
auto map = PtrJNodeMapVanilla{}; void* layoutContext = nullptr;
if (nativePointers) { auto map = PtrJNodeMapVanilla{};
size_t nativePointersSize = env->GetArrayLength(nativePointers); if (nativePointers) {
jlong result[nativePointersSize]; size_t nativePointersSize = env->GetArrayLength(nativePointers);
env->GetLongArrayRegion(nativePointers, 0, nativePointersSize, result); jlong result[nativePointersSize];
env->GetLongArrayRegion(nativePointers, 0, nativePointersSize, result);
map = PtrJNodeMapVanilla{result, nativePointersSize, javaNodes}; map = PtrJNodeMapVanilla{result, nativePointersSize, javaNodes};
layoutContext = ↦ 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( static void jni_YGNodeMarkDirtyJNI(

Просмотреть файл

@ -62,12 +62,16 @@ void logErrorMessageAndDie(const char* message) {
} }
void assertNoPendingJniException(JNIEnv* env) { void assertNoPendingJniException(JNIEnv* env) {
// This method cannot call any other method of the library, since other if (env->ExceptionCheck() == JNI_FALSE) {
// methods of the library use it to check for exceptions too return;
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
logErrorMessageAndDie("Aborting due to pending Java exception in JNI");
} }
auto throwable = env->ExceptionOccurred();
if (!throwable) {
logErrorMessageAndDie("Unable to get pending JNI exception.");
}
env->ExceptionClear();
throw throwable;
} }
} // namespace vanillajni } // namespace vanillajni