X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/f1b5a47ffa92e12d17571d350a567e2035d75039..73fd6f57b6d5c6e7a1f0242016d04d232db58639:/Execute.cpp diff --git a/Execute.cpp b/Execute.cpp index 87e7de2..e118146 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -451,18 +451,21 @@ static JSValueRef Array_callAsFunction_toCYON(JSContextRef context, JSObjectRef bool comma(false); for (size_t index(0), count(CYCastDouble(context, length)); index != count; ++index) { - JSValueRef value(CYGetProperty(context, _this, index)); - if (comma) str << ','; else comma = true; - if (!JSValueIsUndefined(context, value)) - str << CYPoolCCYON(pool, context, value); - else { - str << ','; - comma = false; + try { + JSValueRef value(CYGetProperty(context, _this, index)); + if (!JSValueIsUndefined(context, value)) + str << CYPoolCCYON(pool, context, value); + else { + str << ','; + comma = false; + } + } catch (const CYException &error) { + str << "@error"; } } @@ -1293,7 +1296,7 @@ JSObjectRef CYGetGlobalObject(JSContextRef context) { const char *CYExecute(CYPool &pool, CYUTF8String code) { JSContextRef context(CYGetJSContext()); - JSValueRef exception(NULL), result; + JSValueRef exception(NULL); void *handle; if (hooks_ != NULL && hooks_->ExecuteStart != NULL) @@ -1301,8 +1304,9 @@ const char *CYExecute(CYPool &pool, CYUTF8String code) { else handle = NULL; - const char *json; + try { + JSValueRef result; try { result = JSEvaluateScript(context, CYJSString(code), NULL, NULL, 0, &exception); } catch (const char *error) { @@ -1315,6 +1319,7 @@ const char *CYExecute(CYPool &pool, CYUTF8String code) { if (JSValueIsUndefined(context, result)) return NULL; + const char *json; try { json = CYPoolCCYON(pool, context, result, &exception); } catch (const char *error) { @@ -1326,9 +1331,13 @@ const char *CYExecute(CYPool &pool, CYUTF8String code) { CYSetProperty(context, CYGetGlobalObject(context), Result_, result); - if (hooks_ != NULL && hooks_->ExecuteEnd != NULL) - (*hooks_->ExecuteEnd)(context, handle); return json; + + } catch (...) { + if (hooks_ != NULL && hooks_->ExecuteEnd != NULL) + (*hooks_->ExecuteEnd)(context, handle); + throw; + } } extern "C" void CydgetSetupContext(JSGlobalContextRef context) {