From: Jay Freeman (saurik) Date: Tue, 11 Sep 2012 16:42:52 +0000 (-0700) Subject: Merge CYCastNSObject{,_}, an obsolete distinction. X-Git-Tag: v0.9.459~27 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/993e8ed5a0c5d1c3402ac1034d905b3eb7bae9db?hp=5d422750fa7d2b7f4b70dc8a58e1426bc5557c20 Merge CYCastNSObject{,_}, an obsolete distinction. --- diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index 2b494db..4d51f29 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -602,22 +602,23 @@ NSObject *NSCFType$cy$toJSON(id self, SEL sel, NSString *key) { @end /* }}} */ -NSObject *CYCastNSObject_(apr_pool_t *pool, JSContextRef context, JSObjectRef object) { - JSObjectRef Array(CYGetCachedObject(context, Array_s)); +_finline bool CYJSValueIsInstanceOfCachedConstructor(JSContextRef context, JSValueRef value, JSStringRef cache) { JSValueRef exception(NULL); - bool array(JSValueIsInstanceOfConstructor(context, object, Array, &exception)); + JSObjectRef constructor(CYGetCachedObject(context, cache)); + bool is(JSValueIsInstanceOfConstructor(context, value, constructor, &exception)); CYThrow(context, exception); - id value(array ? [CYJSArray alloc] : [CYJSObject alloc]); - return CYPoolRelease(pool, [value initWithJSObject:object inContext:context]); + return is; } NSObject *CYCastNSObject(apr_pool_t *pool, JSContextRef context, JSObjectRef object) { - if (!JSValueIsObjectOfClass(context, object, Instance_)) - return CYCastNSObject_(pool, context, object); - else { + if (JSValueIsObjectOfClass(context, object, Instance_)) { Instance *internal(reinterpret_cast(JSObjectGetPrivate(object))); return internal->GetValue(); } + + bool array(CYJSValueIsInstanceOfCachedConstructor(context, object, Array_s)); + id value(array ? [CYJSArray alloc] : [CYJSObject alloc]); + return CYPoolRelease(pool, [value initWithJSObject:object inContext:context]); } NSNumber *CYCopyNSNumber(JSContextRef context, JSValueRef value) {