X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/c9c16dde5f5c8469610e727748875806a29906a6..7341eedbaf526ef2f0986b576c656906050e270a:/Java/Execute.cpp diff --git a/Java/Execute.cpp b/Java/Execute.cpp index fe6d5a9..5e449fe 100644 --- a/Java/Execute.cpp +++ b/Java/Execute.cpp @@ -1,5 +1,5 @@ -/* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2015 Jay Freeman (saurik) +/* Cycript - The Truly Universal Scripting Language + * Copyright (C) 2009-2016 Jay Freeman (saurik) */ /* GNU Affero General Public License, Version 3 {{{ */ @@ -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_[] = {