]> git.saurik.com Git - cycript.git/blobdiff - ObjectiveC/Library.mm
Fixed the GC crash of doom that kennytm reported: apparently local contexts come...
[cycript.git] / ObjectiveC / Library.mm
index 5059300e645ca44c266a631d14fdc9c33d195a49..a3c1d66b9b784af87a6995630a59e016a231669c 100644 (file)
@@ -1053,13 +1053,15 @@ JSValueRef CYCastJSValue(JSContextRef context, NSObject *value) { CYPoolTry {
 - (id) initWithJSObject:(JSObjectRef)object inContext:(JSContextRef)context { CYObjectiveTry {
     if ((self = [super init]) != nil) {
         object_ = object;
-        context_ = context;
+        context_ = CYGetJSContext(context);
+        //XXX:JSGlobalContextRetain(context_);
         JSValueProtect(context_, object_);
     } return self;
 } CYObjectiveCatch }
 
 - (void) dealloc { CYObjectiveTry {
     JSValueUnprotect(context_, object_);
+    //XXX:JSGlobalContextRelease(context_);
     [super dealloc];
 } CYObjectiveCatch }
 
@@ -1127,13 +1129,15 @@ JSValueRef CYCastJSValue(JSContextRef context, NSObject *value) { CYPoolTry {
 - (id) initWithJSObject:(JSObjectRef)object inContext:(JSContextRef)context { CYObjectiveTry {
     if ((self = [super init]) != nil) {
         object_ = object;
-        context_ = context;
+        context_ = CYGetJSContext(context);
+        //XXX:JSGlobalContextRetain(context_);
         JSValueProtect(context_, object_);
     } return self;
 } CYObjectiveCatch }
 
 - (void) dealloc { CYObjectiveTry {
     JSValueUnprotect(context_, object_);
+    //XXX:JSGlobalContextRelease(context_);
     [super dealloc];
 } CYObjectiveCatch }
 
@@ -1287,9 +1291,11 @@ JSValueRef CYObjectiveC_RuntimeProperty(JSContextRef context, CYUTF8String name)
     return NULL;
 } CYPoolCatch(NULL) return /*XXX*/ NULL; }
 
-static void CYObjectiveC_CallFunction(JSContextRef context, ffi_cif *cif, void (*function)(), uint8_t *value, void **values) { CYPoolTry {
+static void CYObjectiveC_CallFunction(JSContextRef context, ffi_cif *cif, void (*function)(), uint8_t *value, void **values) { @try {
     ffi_call(cif, function, value, values);
-} CYPoolCatch() }
+} @catch (NSException *error ) {
+    throw CYJSError(context, CYCastJSValue(context, error));
+} }
 
 static bool CYObjectiveC_PoolFFI(apr_pool_t *pool, JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, JSValueRef value) { CYPoolTry  {
     switch (type->primitive) {
@@ -1731,6 +1737,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<uint8_t *>(self) + ivar_getOffset(ivar));
     }
 
@@ -2098,7 +2105,7 @@ static JSValueRef CYValue_callAsFunction_$cya(JSContextRef context, JSObjectRef
         ffi = typical->ffi_;
     }
 
-    return CYMakePointer(context, &internal->value_, type, ffi, object);
+    return CYMakePointer(context, &internal->value_, _not(size_t), type, ffi, object);
 }
 
 static JSValueRef Instance_getProperty_constructor(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) {
@@ -2236,8 +2243,8 @@ void CYObjectiveC_SetupContext(JSContextRef context) {
     JSObjectRef global(CYGetGlobalObject(context));
     apr_pool_t *pool(CYGetGlobalPool());
 
-    Object_type = new(pool) Type_privateData(pool, "@");
-    Selector_type = new(pool) Type_privateData(pool, ":");
+    Object_type = new(pool) Type_privateData("@");
+    Selector_type = new(pool) Type_privateData(":");
 
 #ifdef __APPLE__
     NSCFBoolean_ = objc_getClass("NSCFBoolean");