From 993e8ed5a0c5d1c3402ac1034d905b3eb7bae9db Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Tue, 11 Sep 2012 09:42:52 -0700 Subject: [PATCH 1/1] Merge CYCastNSObject{,_}, an obsolete distinction. --- ObjectiveC/Library.mm | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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) { -- 2.45.2