]> git.saurik.com Git - cycript.git/blobdiff - ObjectiveC/Library.mm
Remove redundant implicit NSString length property.
[cycript.git] / ObjectiveC / Library.mm
index e3b8917ea6d914140b6d16ea67014087d54f6b09..0c7712e9878dc60c3263c32176b7f319a2942404 100644 (file)
@@ -326,14 +326,10 @@ JSValueRef CYGetClassPrototype(JSContextRef context, id self) {
     return object;
 }
 
-JSObjectRef Messages::Make(JSContextRef context, Class _class, bool array) {
+JSObjectRef Messages::Make(JSContextRef context, Class _class) {
     JSObjectRef value(JSObjectMake(context, Messages_, new Messages(_class)));
-    if (_class == NSArray_)
-        array = true;
     if (Class super = class_getSuperclass(_class))
-        JSObjectSetPrototype(context, value, Messages::Make(context, super, array));
-    /*else if (array)
-        JSObjectSetPrototype(context, value, Array_prototype_);*/
+        JSObjectSetPrototype(context, value, Messages::Make(context, super));
     return value;
 }
 
@@ -594,6 +590,10 @@ struct PropertyAttributes {
 @end
 /* }}} */
 
+_finline bool CYJSValueIsNSObject(JSContextRef context, JSValueRef value) {
+    return JSValueIsObjectOfClass(context, value, Instance_);
+}
+
 _finline bool CYJSValueIsInstanceOfCachedConstructor(JSContextRef context, JSValueRef value, JSStringRef cache) {
     JSValueRef exception(NULL);
     JSObjectRef constructor(CYGetCachedObject(context, cache));
@@ -603,7 +603,7 @@ _finline bool CYJSValueIsInstanceOfCachedConstructor(JSContextRef context, JSVal
 }
 
 NSObject *CYCastNSObject(apr_pool_t *pool, JSContextRef context, JSObjectRef object) {
-    if (JSValueIsObjectOfClass(context, object, Instance_)) {
+    if (CYJSValueIsNSObject(context, object)) {
         Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(object)));
         return internal->GetValue();
     }
@@ -1045,9 +1045,6 @@ NSObject *CYCopyNSObject(apr_pool_t *pool, JSContextRef context, JSValueRef valu
 }
 
 - (bool) cy$hasProperty:(NSString *)name {
-    if ([name isEqualToString:@"length"])
-        return true;
-
     size_t index(CYGetIndex(name));
     if (index == _not(size_t) || index >= [self length])
         return [super cy$hasProperty:name];
@@ -1056,15 +1053,6 @@ NSObject *CYCopyNSObject(apr_pool_t *pool, JSContextRef context, JSValueRef valu
 }
 
 - (NSObject *) cy$getProperty:(NSString *)name {
-    if ([name isEqualToString:@"length"]) {
-        NSUInteger count([self length]);
-#ifdef __APPLE__
-        return [NSNumber numberWithUnsignedInteger:count];
-#else
-        return [NSNumber numberWithUnsignedInt:count];
-#endif
-    }
-
     size_t index(CYGetIndex(name));
     if (index == _not(size_t) || index >= [self length])
         return [super cy$getProperty:name];
@@ -1082,11 +1070,6 @@ NSObject *CYCopyNSObject(apr_pool_t *pool, JSContextRef context, JSValueRef valu
     }
 }
 
-// XXX: this might be overly restrictive for NSString; I think I need a half-way between /injecting/ implicit properties and /accepting/ implicit properties
-+ (bool) cy$hasImplicitProperties {
-    return false;
-}
-
 - (JSValueRef) cy$valueOfInContext:(JSContextRef)context { CYObjectiveTry_(context) {
     return CYCastJSValue(context, CYJSString(context, self));
 } CYObjectiveCatch }
@@ -1100,7 +1083,7 @@ NSObject *CYCopyNSObject(apr_pool_t *pool, JSContextRef context, JSValueRef valu
     return kJSTypeUndefined;
 }
 
-- (NSString *) cy$toCYON {
+- (NSString *) cy$toCYON:(bool)objective {
     NSString *value(@"undefined");
     return value; // XXX: maybe use the below code, adding @undefined?
     //return objective ? value : [NSString stringWithFormat:@"@%@", value];
@@ -1115,8 +1098,7 @@ NSObject *CYCopyNSObject(apr_pool_t *pool, JSContextRef context, JSValueRef valu
 
 static bool CYIsClass(id self) {
 #ifdef __APPLE__
-    // XXX: this is a lame object_isClass
-    return class_getInstanceMethod(object_getClass(self), @selector(alloc)) != NULL;
+    return class_isMetaClass(object_getClass(self));
 #else
     return GSObjCIsClass(self);
 #endif
@@ -1918,7 +1900,7 @@ static bool Instance_hasInstance(JSContextRef context, JSObjectRef constructor,
     if (!CYIsClass(_class))
         return false;
 
-    if (JSValueIsObjectOfClass(context, instance, Instance_)) {
+    if (CYJSValueIsNSObject(context, instance)) {
         Instance *linternal(reinterpret_cast<Instance *>(JSObjectGetPrivate((JSObjectRef) instance)));
         // XXX: this isn't always safe
         return [linternal->GetValue() isKindOfClass:_class];
@@ -2236,7 +2218,7 @@ static JSValueRef $objc_msgSend(JSContextRef context, JSObjectRef object, JSObje
         self = internal->GetValue();
         _class = internal->class_;;
         uninitialized = false;
-    } else if (JSValueIsObjectOfClass(context, arguments[0], Instance_)) {
+    } else if (CYJSValueIsNSObject(context, arguments[0])) {
         Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate((JSObjectRef) arguments[0])));
         self = internal->GetValue();
         _class = nil;
@@ -2348,7 +2330,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 (!JSValueIsObjectOfClass(context, _this, Instance_))
+    if (!CYJSValueIsNSObject(context, _this))
         return NULL;
 
     Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
@@ -2356,7 +2338,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 (!JSValueIsObjectOfClass(context, _this, Instance_))
+    if (!CYJSValueIsNSObject(context, _this))
         return NULL;
 
     Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
@@ -2379,7 +2361,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 (!JSValueIsObjectOfClass(context, _this, Instance_))
+    if (!CYJSValueIsNSObject(context, _this))
         return NULL;
 
     Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
@@ -2395,7 +2377,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 (!JSValueIsObjectOfClass(context, _this, Instance_))
+    if (!CYJSValueIsNSObject(context, _this))
         return NULL;
 
     Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
@@ -2404,7 +2386,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 (!JSValueIsObjectOfClass(context, _this, Instance_))
+    if (!CYJSValueIsNSObject(context, _this))
         return NULL;
 
     Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));