From b81e7fb6237425dcdc657869f7516ecdf2c93161 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 2 Nov 2009 01:30:41 +0000 Subject: [PATCH] Fixed the exception throwing mechanism to throw real JavaScript Error objects. --- Library.cpp | 18 ++++++++++++------ ObjectiveC/Library.mm | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Library.cpp b/Library.cpp index 0f91128..383008a 100644 --- a/Library.cpp +++ b/Library.cpp @@ -1448,8 +1448,18 @@ CYPoolError::CYPoolError(const char *format, va_list args) { message_ = apr_pvsprintf(pool_, format, args); } +JSValueRef CYCastJSError(JSContextRef context, const char *message) { + JSValueRef arguments[1] = {CYCastJSValue(context, message)}; + + JSValueRef exception(NULL); + JSValueRef value(JSObjectCallAsConstructor(context, Error_, 1, arguments, &exception)); + CYThrow(context, exception); + + return value; +} + JSValueRef CYPoolError::CastJSValue(JSContextRef context) const { - return CYCastJSValue(context, message_); + return CYCastJSError(context, message_); } CYJSError::CYJSError(JSContextRef context, const char *format, ...) { @@ -1463,11 +1473,7 @@ CYJSError::CYJSError(JSContextRef context, const char *format, ...) { const char *message(apr_pvsprintf(pool, format, args)); va_end (args); - JSValueRef arguments[1] = {CYCastJSValue(context, CYJSString(message))}; - - JSValueRef exception(NULL); - value_ = JSObjectCallAsConstructor(context, Error_, 1, arguments, &exception); - CYThrow(context, exception); + value_ = CYCastJSError(context, message); } JSGlobalContextRef CYGetJSContext() { diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index 5059300..1de5595 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -1731,6 +1731,7 @@ static JSValueRef Internal_getProperty(JSContextRef context, JSObjectRef object, if (objc_ivar *ivar = object_getInstanceVariable(self, name, NULL)) { Type_privateData type(pool, ivar_getTypeEncoding(ivar)); + // XXX: if this fails and throws an exception the person we are throwing it to gets the wrong exception return CYFromFFI(context, type.type_, type.GetFFI(), reinterpret_cast(self) + ivar_getOffset(ivar)); } -- 2.47.2