X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/1fb9f0d07a48fea34e0e7bb03572b9507ec7722d..97343f3189a3ad66364ec26c35716f6894237fb9:/ObjectiveC/Library.mm?ds=sidebyside diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index 5b679cb..bb1eb86 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -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; } @@ -399,7 +385,6 @@ JSObjectRef CYMakeInstance(JSContextRef context, id object, bool transient) { - (NSObject *) cy$toJSON:(NSString *)key; - (NSString *) cy$toCYON; -- (NSString *) cy$toKey; - (bool) cy$hasProperty:(NSString *)name; - (NSObject *) cy$getProperty:(NSString *)name; @@ -616,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(JSObjectGetPrivate(object))); @@ -821,7 +806,7 @@ NSObject *CYCopyNSObject(apr_pool_t *pool, JSContextRef context, JSValueRef valu [json appendString:@","]; else comma = true; - [json appendString:[key cy$toKey]]; + [json appendString:CYCastNSCYON(key)]; [json appendString:@":"]; NSObject *object([self objectForKey:key]); [json appendString:CYCastNSCYON(object)]; @@ -998,10 +983,6 @@ NSObject *CYCopyNSObject(apr_pool_t *pool, JSContextRef context, JSValueRef valu return [[self cy$toJSON:@""] cy$toCYON]; } -- (NSString *) cy$toKey { - return [self cy$toCYON]; -} - - (bool) cy$hasProperty:(NSString *)name { return false; } @@ -1064,12 +1045,6 @@ NSObject *CYCopyNSObject(apr_pool_t *pool, JSContextRef context, JSValueRef valu return CYCastNSString(NULL, CYUTF8String(value.c_str(), value.size())); } -- (NSString *) cy$toKey { - if (CYIsKey(CYCastUTF8String(self))) - return self; - return [self cy$toCYON]; -} - - (bool) cy$hasProperty:(NSString *)name { if ([name isEqualToString:@"length"]) return true; @@ -1852,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(JSObjectGetPrivate((JSObjectRef) instance))); // XXX: this isn't always safe return [linternal->GetValue() isKindOfClass:_class]; @@ -2170,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(JSObjectGetPrivate((JSObjectRef) arguments[0]))); self = internal->GetValue(); _class = nil; @@ -2318,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(JSObjectGetPrivate(_this))); @@ -2326,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(JSObjectGetPrivate(_this))); @@ -2343,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(JSObjectGetPrivate(_this))); @@ -2359,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(JSObjectGetPrivate(_this))); @@ -2368,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(JSObjectGetPrivate(_this)));