]> git.saurik.com Git - cycript.git/commitdiff
Do not check against classes that are not instanced.
authorJay Freeman (saurik) <saurik@saurik.com>
Mon, 4 Jun 2012 05:19:17 +0000 (22:19 -0700)
committerJay Freeman (saurik) <saurik@saurik.com>
Mon, 4 Jun 2012 05:19:17 +0000 (22:19 -0700)
ObjectiveC/Library.mm

index 414024754ceaf8886ae71630adb1c353c97e7772..bb1eb86cd76fb373f888a20e924e77566c4c20b1 100644 (file)
@@ -238,13 +238,6 @@ static JSClassRef ArrayInstance_;
 static JSClassRef ObjectInstance_;
 static JSClassRef StringInstance_;
 
-static JSClassRef *Instances_[] = {
-    &Instance_,
-    &ArrayInstance_,
-    &ObjectInstance_,
-    &StringInstance_,
-};
-
 static JSClassRef Internal_;
 static JSClassRef Message_;
 static JSClassRef Messages_;
@@ -278,13 +271,6 @@ static Class Object_;
 static Type_privateData *Object_type;
 static Type_privateData *Selector_type;
 
-static bool CYValueIsObjectOfClassInstance(JSContextRef context, JSValueRef value) {
-    for (size_t i(0); i != sizeof(Instances_) / sizeof(Instances_[0]); ++i)
-        if (JSValueIsObjectOfClass(context, value, *Instances_[i]))
-            return true;
-    return false;
-}
-
 Type_privateData *Instance::GetType() const {
     return Object_type;
 }
@@ -615,7 +601,7 @@ NSObject *CYCastNSObject_(apr_pool_t *pool, JSContextRef context, JSObjectRef ob
 }
 
 NSObject *CYCastNSObject(apr_pool_t *pool, JSContextRef context, JSObjectRef object) {
-    if (!CYValueIsObjectOfClassInstance(context, object))
+    if (!JSValueIsObjectOfClass(context, object, Instance_))
         return CYCastNSObject_(pool, context, object);
     else {
         Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(object)));
@@ -1841,7 +1827,7 @@ static bool Instance_hasInstance(JSContextRef context, JSObjectRef constructor,
     if (!CYIsClass(_class))
         return false;
 
-    if (CYValueIsObjectOfClassInstance(context, instance)) {
+    if (JSValueIsObjectOfClass(context, instance, Instance_)) {
         Instance *linternal(reinterpret_cast<Instance *>(JSObjectGetPrivate((JSObjectRef) instance)));
         // XXX: this isn't always safe
         return [linternal->GetValue() isKindOfClass:_class];
@@ -2159,7 +2145,7 @@ static JSValueRef $objc_msgSend(JSContextRef context, JSObjectRef object, JSObje
         self = internal->GetValue();
         _class = internal->class_;;
         uninitialized = false;
-    } else if (CYValueIsObjectOfClassInstance(context, arguments[0])) {
+    } else if (JSValueIsObjectOfClass(context, arguments[0], Instance_)) {
         Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate((JSObjectRef) arguments[0])));
         self = internal->GetValue();
         _class = nil;
@@ -2307,7 +2293,7 @@ static JSValueRef Instance_getProperty_messages(JSContextRef context, JSObjectRe
 }
 
 static JSValueRef Instance_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
-    if (!CYValueIsObjectOfClassInstance(context, _this))
+    if (!JSValueIsObjectOfClass(context, _this, Instance_))
         return NULL;
 
     Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
@@ -2315,7 +2301,7 @@ static JSValueRef Instance_callAsFunction_toCYON(JSContextRef context, JSObjectR
 } CYCatch }
 
 static JSValueRef Instance_callAsFunction_toJSON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
-    if (!CYValueIsObjectOfClassInstance(context, _this))
+    if (!JSValueIsObjectOfClass(context, _this, Instance_))
         return NULL;
 
     Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
@@ -2332,7 +2318,7 @@ static JSValueRef Instance_callAsFunction_toJSON(JSContextRef context, JSObjectR
 } CYCatch return /*XXX*/ NULL; }
 
 static JSValueRef Instance_callAsFunction_valueOf(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
-    if (!CYValueIsObjectOfClassInstance(context, _this))
+    if (!JSValueIsObjectOfClass(context, _this, Instance_))
         return NULL;
 
     Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
@@ -2348,7 +2334,7 @@ static JSValueRef Instance_callAsFunction_valueOf(JSContextRef context, JSObject
 } CYCatch return /*XXX*/ NULL; }
 
 static JSValueRef Instance_callAsFunction_toPointer(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
-    if (!CYValueIsObjectOfClassInstance(context, _this))
+    if (!JSValueIsObjectOfClass(context, _this, Instance_))
         return NULL;
 
     Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
@@ -2357,7 +2343,7 @@ static JSValueRef Instance_callAsFunction_toPointer(JSContextRef context, JSObje
 } CYCatch return /*XXX*/ NULL; }
 
 static JSValueRef Instance_callAsFunction_toString(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
-    if (!CYValueIsObjectOfClassInstance(context, _this))
+    if (!JSValueIsObjectOfClass(context, _this, Instance_))
         return NULL;
 
     Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));