From: Jay Freeman (saurik) Date: Sat, 2 Jan 2016 07:46:57 +0000 (-0800) Subject: Got exceptions bridged, back and forth, with Java. X-Git-Tag: v0.9.590~97 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/824bc1ec28c62ea1d63622c46e1edfd911c38b64?ds=sidebyside Got exceptions bridged, back and forth, with Java. --- diff --git a/Java/Cycript.java b/Java/Cycript.java index d234956..02805cb 100644 --- a/Java/Cycript.java +++ b/Java/Cycript.java @@ -43,6 +43,7 @@ public static native Object handle(long protect, String property, Object[] argum throws Throwable; public static class Wrapper + extends RuntimeException implements InvocationHandler { private long protect_; diff --git a/Java/Execute.cpp b/Java/Execute.cpp index fe6d5a9..95c517a 100644 --- a/Java/Execute.cpp +++ b/Java/Execute.cpp @@ -59,11 +59,13 @@ _value; }) } while (false) #define CYJavaTry \ + auto &protect(*reinterpret_cast(jprotect)); \ + _disused JSContextRef context(protect); \ + _disused JSObjectRef object(protect); \ try #define CYJavaCatch(value) \ catch (const CYException &error) { \ - CYPool pool; \ - jni->ThrowNew(jni->FindClass("java/lang/RuntimeException"), error.PoolCString(pool)); \ + jni->Throw(static_cast(CYCastJavaObject(jni, context, error.CastJSValue(context, "Error")))); \ return value; \ } @@ -1024,13 +1026,11 @@ static JSValueRef CYJavaPackage_getProperty(JSContextRef context, JSObjectRef ob } CYCatch(NULL) } static void Cycript_delete(JNIEnv *jni, jclass api, jlong jprotect) { CYJavaTry { - delete reinterpret_cast(jprotect); + delete &protect; } CYJavaCatch() } static jobject Cycript_handle(JNIEnv *jni, jclass api, jlong jprotect, jstring property, jobjectArray jarguments) { CYJavaTry { - auto &protect(*reinterpret_cast(jprotect)); - JSContextRef context(protect); - JSValueRef function(CYGetProperty(context, protect, CYJSString(jni, property))); + JSValueRef function(CYGetProperty(context, object, CYJSString(jni, property))); if (JSValueIsUndefined(context, function)) return NULL; @@ -1039,7 +1039,7 @@ static jobject Cycript_handle(JNIEnv *jni, jclass api, jlong jprotect, jstring p for (size_t index(0); index != count; ++index) arguments[index] = CYCastJSValue(context, jni, _envcall(jni, GetObjectArrayElement(jarguments, index))); - return CYCastJavaObject(jni, context, CYCallAsFunction(context, CYCastJSObject(context, function), protect, count, arguments)); + return CYCastJavaObject(jni, context, CYCallAsFunction(context, CYCastJSObject(context, function), object, count, arguments)); } CYJavaCatch(NULL) } static JNINativeMethod Cycript_[] = {