From: Jay Freeman (saurik) Date: Fri, 8 Jan 2016 12:12:36 +0000 (-0800) Subject: new operator must return JSObject even for errors. X-Git-Tag: v0.9.590~31 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/77dd5db92b788d747c11ee9c78d79df5b88e7a1d?ds=inline new operator must return JSObject even for errors. --- diff --git a/Exception.hpp b/Exception.hpp index cd4bd08..1efaf3f 100644 --- a/Exception.hpp +++ b/Exception.hpp @@ -56,13 +56,17 @@ void CYThrow(JSContextRef context, JSValueRef value); #define CYCatch_(value, name) \ catch (const CYException &error) { \ *exception = error.CastJSValue(context, name); \ + _assert(*exception != NULL); \ return value; \ } catch (...) { \ *exception = CYCastJSValue(context, "catch(...)"); \ + _assert(*exception != NULL); \ return value; \ } #define CYCatch(value) \ CYCatch_(value, "Error") +#define CYCatchObject() \ + CYCatch(JSObjectMake(context, NULL, NULL)) #define _assert_(mode, test, code, format, ...) do \ if (!(test)) \ diff --git a/Execute.cpp b/Execute.cpp index ac2fac1..c068780 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -1477,15 +1477,15 @@ static void All_getPropertyNames(JSContextRef context, JSObjectRef object, JSPro static JSObjectRef CArray_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { _assert(false); -} CYCatch(NULL) } +} CYCatchObject() } static JSObjectRef CString_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { _assert(false); -} CYCatch(NULL) } +} CYCatchObject() } static JSObjectRef Pointer_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { _assert(false); -} CYCatch(NULL) } +} CYCatchObject() } static JSObjectRef Type_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { CYPool pool; @@ -1539,7 +1539,7 @@ static JSObjectRef Type_new(JSContextRef context, JSObjectRef object, size_t cou } else { throw CYJSError(context, "incorrect number of arguments to Type constructor"); } -} CYCatch(NULL) } +} CYCatchObject() } static JSValueRef Type_callAsFunction_$With(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], sig::Callable &type, JSValueRef *exception) { CYTry { Type_privateData *internal(reinterpret_cast(JSObjectGetPrivate(_this))); @@ -1703,7 +1703,7 @@ static JSObjectRef Type_callAsConstructor(JSContextRef context, JSObjectRef obje type->PoolFFI(value->pool_, context, ffi, value->value_, arguments[0]); return pointer; -} CYCatch(NULL) } +} CYCatchObject() } // XXX: I don't even think the user should be allowed to do this static JSObjectRef Functor_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { @@ -1715,7 +1715,7 @@ static JSObjectRef Functor_new(JSContextRef context, JSObjectRef object, size_t sig::Parse(pool, &signature, encoding, &Structor_); // XXX: this can try to return null, and I guess then it just fails return CYCastJSObject(context, CYMakeFunctor(context, arguments[0], false, signature)); -} CYCatch(NULL) } +} CYCatchObject() } static JSValueRef CArray_callAsFunction_toPointer(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { CArray *internal(reinterpret_cast(JSObjectGetPrivate(_this))); diff --git a/Java/Execute.cpp b/Java/Execute.cpp index c7ecbb1..1a227ab 100644 --- a/Java/Execute.cpp +++ b/Java/Execute.cpp @@ -1015,7 +1015,7 @@ static JSObjectRef JavaClass_callAsConstructor(JSContextRef context, JSObjectRef } CYThrow("invalid constructor call"); -} CYCatch(NULL) } +} CYCatchObject() } static bool JavaStaticInterior_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef property) { auto internal(CYPrivate::Get(context, object)); diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index 79573a8..431da0d 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -1973,13 +1973,13 @@ static JSValueRef Instance_complete_callAsFunction(JSContextRef context, JSObjec values(CYCastJSValue(context, CYJSString(pool.strcat(name, "()", NULL)))); })); } return array; -} CYCatch(NULL) } +} CYCatchObject() } static JSObjectRef Constructor_callAsConstructor(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { auto internal(CYPrivate::Get(context, object)); JSObjectRef value(CYMakeInstance(context, [internal->value_ alloc], Instance::Uninitialized)); return value; -} CYCatch(NULL) } +} CYCatchObject() } static const char *CYBlockEncoding(NSBlock *self) { BlockLiteral *literal(reinterpret_cast(self)); @@ -2574,7 +2574,7 @@ static JSObjectRef Super_new(JSContextRef context, JSObjectRef object, size_t co id self(CYCastNSObject(&pool, context, arguments[0])); Class _class(CYCastClass(pool, context, arguments[1])); return CYPrivate::Make(context, self, _class); -} CYCatch(NULL) } +} CYCatchObject() } static JSObjectRef Selector_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { if (count != 1) @@ -2582,13 +2582,13 @@ static JSObjectRef Selector_new(JSContextRef context, JSObjectRef object, size_t CYPool pool; const char *name(CYPoolCString(pool, context, arguments[0])); return CYPrivate::Make(context, sel_registerName(name)); -} CYCatch(NULL) } +} CYCatchObject() } static JSObjectRef Instance_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { if (count != 1) throw CYJSError(context, "incorrect number of arguments to Instance constructor"); return CYMakeInstance(context, CYCastPointer(context, arguments[0])); -} CYCatch(NULL) } +} CYCatchObject() } static JSValueRef Selector_getProperty_$cyt(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { return CYMakeType(context, sig::Selector());