From 8150077d0a10c34bcc4ffd1df89a21028b98a7c9 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 13 Sep 2012 12:12:48 -0700 Subject: [PATCH] Factor checks for Instance_ as CYJSValueIsNSObject. --- ObjectiveC/Internal.hpp | 2 +- ObjectiveC/Library.mm | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ObjectiveC/Internal.hpp b/ObjectiveC/Internal.hpp index 2e3f40c..0c3646e 100644 --- a/ObjectiveC/Internal.hpp +++ b/ObjectiveC/Internal.hpp @@ -95,7 +95,7 @@ struct Messages : { } - static JSObjectRef Make(JSContextRef context, Class _class, bool array = false); + static JSObjectRef Make(JSContextRef context, Class _class); _finline Class GetValue() const { return reinterpret_cast(value_); diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index e3b8917..3a422ed 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -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(JSObjectGetPrivate(object))); return internal->GetValue(); } @@ -1918,7 +1918,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(JSObjectGetPrivate((JSObjectRef) instance))); // XXX: this isn't always safe return [linternal->GetValue() isKindOfClass:_class]; @@ -2236,7 +2236,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(JSObjectGetPrivate((JSObjectRef) arguments[0]))); self = internal->GetValue(); _class = nil; @@ -2348,7 +2348,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(JSObjectGetPrivate(_this))); @@ -2356,7 +2356,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(JSObjectGetPrivate(_this))); @@ -2379,7 +2379,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(JSObjectGetPrivate(_this))); @@ -2395,7 +2395,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(JSObjectGetPrivate(_this))); @@ -2404,7 +2404,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(JSObjectGetPrivate(_this))); -- 2.45.2