}
static JSClassRef Instance_;
+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_;
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;
}
}
NSObject *CYCastNSObject(apr_pool_t *pool, JSContextRef context, JSObjectRef object) {
- if (!JSValueIsObjectOfClass(context, object, Instance_))
+ if (!CYValueIsObjectOfClassInstance(context, object))
return CYCastNSObject_(pool, context, object);
else {
Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(object)));
if (!CYIsClass(_class))
return false;
- if (JSValueIsObjectOfClass(context, instance, Instance_)) {
+ if (CYValueIsObjectOfClassInstance(context, instance)) {
Instance *linternal(reinterpret_cast<Instance *>(JSObjectGetPrivate((JSObjectRef) instance)));
// XXX: this isn't always safe
return [linternal->GetValue() isKindOfClass:_class];
self = internal->GetValue();
_class = internal->class_;;
uninitialized = false;
- } else if (JSValueIsObjectOfClass(context, arguments[0], Instance_)) {
+ } else if (CYValueIsObjectOfClassInstance(context, arguments[0])) {
Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate((JSObjectRef) arguments[0])));
self = internal->GetValue();
_class = nil;
}
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 (!CYValueIsObjectOfClassInstance(context, _this))
return NULL;
Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
} 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 (!CYValueIsObjectOfClassInstance(context, _this))
return NULL;
Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
} 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 (!CYValueIsObjectOfClassInstance(context, _this))
return NULL;
Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
} 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 (!CYValueIsObjectOfClassInstance(context, _this))
return NULL;
Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
} 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 (!CYValueIsObjectOfClassInstance(context, _this))
return NULL;
Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
definition.finalize = &CYFinalize;
Instance_ = JSClassCreate(&definition);
+ definition.className = "ArrayInstance";
+ ArrayInstance_ = JSClassCreate(&definition);
+
+ definition.className = "ObjectInstance";
+ ObjectInstance_ = JSClassCreate(&definition);
+
+ definition.className = "StringInstance";
+ StringInstance_ = JSClassCreate(&definition);
+
definition = kJSClassDefinitionEmpty;
definition.className = "Internal";
definition.staticFunctions = Internal_staticFunctions;
JSObjectRef Instance_prototype(CYCastJSObject(context, CYGetProperty(context, Instance, prototype_s)));
CYSetProperty(context, cy, CYJSString("Instance_prototype"), Instance_prototype);
- JSObjectRef ArrayInstance(JSObjectMakeConstructor(context, Instance_, NULL));
+ JSObjectRef ArrayInstance(JSObjectMakeConstructor(context, ArrayInstance_, NULL));
JSObjectRef ArrayInstance_prototype(CYCastJSObject(context, CYGetProperty(context, ArrayInstance, prototype_s)));
CYSetProperty(context, cy, CYJSString("ArrayInstance_prototype"), ArrayInstance_prototype);
JSObjectRef Array_prototype(CYGetCachedObject(context, CYJSString("Array_prototype")));
JSObjectSetPrototype(context, ArrayInstance_prototype, Array_prototype);
- JSObjectRef ObjectInstance(JSObjectMakeConstructor(context, Instance_, NULL));
+ JSObjectRef ObjectInstance(JSObjectMakeConstructor(context, ObjectInstance_, NULL));
JSObjectRef ObjectInstance_prototype(CYCastJSObject(context, CYGetProperty(context, ObjectInstance, prototype_s)));
CYSetProperty(context, cy, CYJSString("ObjectInstance_prototype"), ObjectInstance_prototype);
JSObjectRef Object_prototype(CYGetCachedObject(context, CYJSString("Object_prototype")));
JSObjectSetPrototype(context, ObjectInstance_prototype, Object_prototype);
- JSObjectRef StringInstance(JSObjectMakeConstructor(context, Instance_, NULL));
+ JSObjectRef StringInstance(JSObjectMakeConstructor(context, StringInstance_, NULL));
JSObjectRef StringInstance_prototype(CYCastJSObject(context, CYGetProperty(context, StringInstance, prototype_s)));
CYSetProperty(context, cy, CYJSString("StringInstance_prototype"), StringInstance_prototype);
JSObjectRef String_prototype(CYGetCachedObject(context, CYJSString("String_prototype")));