X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/554cd08dc5f6226ffd3eac34786b2c63bf17d9ad..0abb2a2f9d5b1c7fbe7a43619bab5291d7e55f87:/ObjectiveC/Library.mm diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index 79573a8..d0d824f 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -248,13 +248,6 @@ bool CYGetOffset(CYPool &pool, JSContextRef context, NSString *value, ssize_t &i return CYGetOffset(CYPoolCString(pool, context, value), index); } -static JSClassRef ArrayInstance_; -static JSClassRef BooleanInstance_; -static JSClassRef FunctionInstance_; -static JSClassRef NumberInstance_; -static JSClassRef ObjectInstance_; -static JSClassRef StringInstance_; - static JSClassRef ObjectiveC_Classes_; static JSClassRef ObjectiveC_Constants_; static JSClassRef ObjectiveC_Protocols_; @@ -284,7 +277,7 @@ static Class Object_; static JSValueRef Instance_callAsFunction_toString(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception); -JSValueRef Prototype::GetPrototype(JSContextRef context) const { +JSValueRef Messages::GetPrototype(JSContextRef context) const { #ifdef __APPLE__ if (value_ == NSCFBoolean_) #else @@ -303,14 +296,12 @@ JSValueRef Prototype::GetPrototype(JSContextRef context) const { return CYGetCachedObject(context, CYJSString("StringInstance_prototype")); if (Class super = class_getSuperclass(value_)) - return CYPrivate::Cache(context, super); - return CYGetCachedObject(context, CYJSString("Instance_prototype")); -} - -JSValueRef Constructor::GetPrototype(JSContextRef context) const { - if (Class super = class_getSuperclass(value_)) - return CYPrivate::Cache(context, super); - return CYGetCachedObject(context, CYJSString("Constructor_prototype")); + if (class_isMetaClass(value_) && !class_isMetaClass(super)) + return CYGetCachedObject(context, CYJSString("TypeInstance_prototype")); + else + return CYPrivate::Cache(context, super); + else + return CYGetCachedObject(context, CYJSString("Instance_prototype")); } bool CYIsKindOfClass(id object, Class _class) { @@ -321,11 +312,7 @@ bool CYIsKindOfClass(id object, Class _class) { } JSValueRef Instance::GetPrototype(JSContextRef context) const { - return CYPrivate::Cache(context, object_getClass(value_)); -} - -JSClassRef Instance::GetClass(id object, Flags flags) { - return CYIsKindOfClass(object, NSBlock_) ? FunctionInstance_ : Instance::Class_; + return CYPrivate::Cache(context, object_getClass(value_)); } Instance::Instance(id value, Flags flags) : @@ -357,6 +344,8 @@ struct Message_privateData : { } + virtual CYPropertyName *GetName(CYPool &pool) const; + static JSObjectRef Make(JSContextRef context, SEL sel, const char *type, IMP value); }; @@ -374,10 +363,13 @@ JSObjectRef CYMakeInstance(JSContextRef context, id object, Instance::Flags flag #endif JSObjectRef instance; - if (CYIsClass(object) && !class_isMetaClass(object)) - instance = CYPrivate::Cache(context, object); + if (false); + else if (CYIsKindOfClass(object, NSBlock_)) + instance = CYPrivate::Make(context, object, flags); + else if (CYIsClass(object)) + instance = CYPrivate::Make(context, object, flags); else - instance = Instance::Make(context, object, flags); + instance = CYPrivate::Make(context, object, flags); #ifdef __APPLE__ if (weak != NULL && &JSWeakObjectMapSet != NULL) @@ -594,7 +586,7 @@ struct PropertyAttributes { /* }}} */ _finline bool CYJSValueIsNSObject(JSContextRef context, JSValueRef value) { - return JSValueIsObjectOfClass(context, value, Instance::Class_) || JSValueIsObjectOfClass(context, value, FunctionInstance_) || JSValueIsObjectOfClass(context, value, CYPrivate::Class_); + return JSValueIsObjectOfClass(context, value, CYPrivate::Class_); } _finline bool CYJSValueIsInstanceOfCachedConstructor(JSContextRef context, JSValueRef value, JSStringRef cache) { @@ -650,6 +642,9 @@ NSObject *CYCastNSObject(CYPool *pool, JSContextRef context, JSObjectRef object) return internal->value_; } + if (NSObject *pointer = CYCastPointerEx(context, object)) + return pointer; + bool array(CYJSValueIsInstanceOfCachedConstructor(context, object, Array_s)); id value(array ? [CYJSArray alloc] : [CYJSObject alloc]); return CYPoolRelease(pool, [value initWithJSObject:object inContext:context]); @@ -1481,10 +1476,10 @@ static NSBlock *CYCastNSBlock(CYPool &pool, JSContextRef context, JSValueRef val return nil; JSObjectRef object(CYCastJSObject(context, value)); - if (JSValueIsObjectOfClass(context, object, FunctionInstance_)) + if (JSValueIsObjectOfClass(context, object, CYPrivate::Class_)) return reinterpret_cast(JSObjectGetPrivate(object))->value_; - if (JSValueIsObjectOfClass(context, object, Instance::Class_)) { + if (JSValueIsObjectOfClass(context, object, CYPrivate::Class_)) { _assert(reinterpret_cast(JSObjectGetPrivate(object))->value_ == nil); return nil; } @@ -1592,7 +1587,9 @@ static JSValueRef MessageAdapter_(JSContextRef context, size_t count, JSValueRef JSObjectRef Message_privateData::Make(JSContextRef context, SEL sel, const char *type, IMP value) { Message_privateData *internal(new Message_privateData(sel, type, value)); - return JSObjectMake(context, Message_privateData::Class_, internal); + JSObjectRef object(JSObjectMake(context, Message_privateData::Class_, internal)); + CYSetPrototype(context, object, CYGetCachedValue(context, CYJSString("Functor_prototype"))); + return object; } static IMP CYMakeMessage(JSContextRef context, JSValueRef value, const char *encoding) { @@ -1607,7 +1604,7 @@ static IMP CYMakeMessage(JSContextRef context, JSValueRef value, const char *enc static bool Messages_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef property) { auto internal(CYPrivate::Get(context, object)); - Class _class(internal->GetClass()); + Class _class(internal->value_); CYPool pool; const char *name(CYPoolCString(pool, context, property)); @@ -1621,7 +1618,7 @@ static bool Messages_hasProperty(JSContextRef context, JSObjectRef object, JSStr static JSValueRef Messages_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { auto internal(CYPrivate::Get(context, object)); - Class _class(internal->GetClass()); + Class _class(internal->value_); CYPool pool; const char *name(CYPoolCString(pool, context, property)); @@ -1635,7 +1632,7 @@ static JSValueRef Messages_getProperty(JSContextRef context, JSObjectRef object, static bool Messages_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYTry { auto internal(CYPrivate::Get(context, object)); - Class _class(internal->GetClass()); + Class _class(internal->value_); CYPool pool; const char *name(CYPoolCString(pool, context, property)); @@ -1684,7 +1681,7 @@ static JSValueRef Messages_complete_callAsFunction(JSContextRef context, JSObjec CYUTF8String prefix(CYPoolUTF8String(pool, context, CYJSString(context, arguments[0]))); auto internal(CYPrivate::Get(context, _this)); - Class _class(internal->GetClass()); + Class _class(internal->value_); unsigned int size; objc_method **data(class_copyMethodList(_class, &size)); @@ -1731,35 +1728,6 @@ static objc_property_t CYFindProperty(CYPool &pool, Class _class, const char *na return CYFindProperty(pool, class_getSuperclass(_class), name); */ } -static JSValueRef Constructor_getProperty_$cyi(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { - auto internal(CYPrivate::Get(context, object)); - return CYPrivate::Make(context, internal->value_, context, object); -} CYCatch(NULL) } - -static bool Constructor_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef property) { - auto internal(CYPrivate::Get(context, object)); - Class _class(object_getClass(internal->value_)); - if (!CYHasImplicitProperties(context, _class)) - return false; - CYPool pool; - if (SEL sel = sel_getUid(CYPoolCString(pool, context, property))) - if (CYImplements(internal->value_, _class, sel, true)) - return true; - return false; -} - -static JSValueRef Constructor_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { - auto internal(CYPrivate::Get(context, object)); - Class _class(object_getClass(internal->value_)); - if (!CYHasImplicitProperties(context, _class)) - return NULL; - CYPool pool; - if (SEL sel = sel_getUid(CYPoolCString(pool, context, property))) - if (CYImplements(internal->value_, _class, sel, true)) - return CYSendMessage(pool, context, internal->value_, NULL, sel, 0, NULL, false); - return NULL; -} CYCatch(NULL) } - static bool Instance_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef property) { Instance *internal(reinterpret_cast(JSObjectGetPrivate(object))); id self(internal->value_); @@ -1973,13 +1941,13 @@ static JSValueRef Instance_complete_callAsFunction(JSContextRef context, JSObjec values(CYCastJSValue(context, CYJSString(pool.strcat(name, "()", NULL)))); })); } return array; -} CYCatch(NULL) } +} CYCatchObject() } static JSObjectRef Constructor_callAsConstructor(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { auto internal(CYPrivate::Get(context, object)); JSObjectRef value(CYMakeInstance(context, [internal->value_ alloc], Instance::Uninitialized)); return value; -} CYCatch(NULL) } +} CYCatchObject() } static const char *CYBlockEncoding(NSBlock *self) { BlockLiteral *literal(reinterpret_cast(self)); @@ -2010,7 +1978,7 @@ static bool CYBlockSignature(CYPool &pool, NSBlock *self, sig::Signature &signat return true; } -static JSValueRef FunctionInstance_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { +static JSValueRef Block_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { Instance *internal(reinterpret_cast(JSObjectGetPrivate(object))); id self(internal->value_); @@ -2567,6 +2535,10 @@ static JSValueRef Message_callAsFunction(JSContextRef context, JSObjectRef objec return CYCallFunction(pool, context, 2, setup, count, arguments, false, true, internal->signature_, &internal->cif_, internal->value_); } CYCatch(NULL) } +CYPropertyName *Message_privateData::GetName(CYPool &pool) const { + return new(pool) CYString(pool.strcat(":", sel_getName(sel_), NULL)); +} + static JSObjectRef Super_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { if (count != 2) throw CYJSError(context, "incorrect number of arguments to objc_super constructor"); @@ -2574,7 +2546,7 @@ static JSObjectRef Super_new(JSContextRef context, JSObjectRef object, size_t co id self(CYCastNSObject(&pool, context, arguments[0])); Class _class(CYCastClass(pool, context, arguments[1])); return CYPrivate::Make(context, self, _class); -} CYCatch(NULL) } +} CYCatchObject() } static JSObjectRef Selector_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { if (count != 1) @@ -2582,13 +2554,13 @@ static JSObjectRef Selector_new(JSContextRef context, JSObjectRef object, size_t CYPool pool; const char *name(CYPoolCString(pool, context, arguments[0])); return CYPrivate::Make(context, sel_registerName(name)); -} CYCatch(NULL) } +} CYCatchObject() } static JSObjectRef Instance_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { if (count != 1) throw CYJSError(context, "incorrect number of arguments to Instance constructor"); return CYMakeInstance(context, CYCastPointer(context, arguments[0])); -} CYCatch(NULL) } +} CYCatchObject() } static JSValueRef Selector_getProperty_$cyt(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { return CYMakeType(context, sig::Selector()); @@ -2618,15 +2590,10 @@ static JSValueRef Instance_getProperty_constructor(JSContextRef context, JSObjec return CYMakeInstance(context, object_getClass(internal->value_), Instance::Permanent); } CYCatch(NULL) } -static JSValueRef Constructor_getProperty_constructor(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { - auto internal(CYPrivate::Get(context, object)); - return CYMakeInstance(context, object_getClass(internal->value_), Instance::Permanent); -} CYCatch(NULL) } - static JSValueRef Constructor_getProperty_prototype(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { Instance *internal(reinterpret_cast(JSObjectGetPrivate(object))); id self(internal->value_); - return CYPrivate::Cache(context, self); + return CYPrivate::Cache(context, self); } CYCatch(NULL) } static JSValueRef Instance_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { @@ -2639,11 +2606,6 @@ static JSValueRef Instance_callAsFunction_toCYON(JSContextRef context, JSObjectR return CYCastJSValue(context, CYJSString(context, CYCastNSCYON(internal->value_, false, objects))); } CYCatch(NULL) } -static JSValueRef Constructor_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { - auto internal(CYPrivate::Get(context, _this)); - return CYCastJSValue(context, CYJSString(class_getName(internal->value_))); -} CYCatch(NULL) } - static JSValueRef Instance_callAsFunction_toJSON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { if (!CYJSValueIsNSObject(context, _this)) return NULL; @@ -2689,11 +2651,6 @@ static JSValueRef Instance_callAsFunction_toPointer(JSContextRef context, JSObje return NULL; Instance *internal(reinterpret_cast(JSObjectGetPrivate(_this))); // XXX: return CYMakePointer(context, internal->value_, sig::Object(class_getName(object_getClass(internal->value_))), NULL, object); - return CYCastJSValue(context, reinterpret_cast(internal->value_)); -} CYCatch(NULL) return /*XXX*/ NULL; } - -static JSValueRef Constructor_callAsFunction_toPointer(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { - auto internal(CYPrivate::Get(context, object)); // XXX: return CYMakePointer(context, internal->value_, sig::Meta(), NULL, object); return CYCastJSValue(context, reinterpret_cast(internal->value_)); } CYCatch(NULL) return /*XXX*/ NULL; } @@ -2768,20 +2725,21 @@ static JSStaticValue Selector_staticValues[2] = { static JSStaticValue Instance_staticValues[3] = { {"$cyt", &Instance_getProperty_$cyt, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, - // XXX: this is sadly duplicated in FunctionInstance_staticValues {"constructor", &Instance_getProperty_constructor, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {NULL, NULL, NULL, 0} }; -static JSStaticValue FunctionInstance_staticValues[3] = { +static JSStaticValue Block_staticValues[3] = { {"$cyt", &FunctionInstance_getProperty_$cyt, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, - // XXX: this is sadly a duplicate of Instance_staticValues - {"constructor", &Instance_getProperty_constructor, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {NULL, NULL, NULL, 0} }; static JSStaticFunction Instance_staticFunctions[7] = { {"cy$complete", &Instance_complete_callAsFunction, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, + {NULL, NULL, 0} +}; + +static JSStaticFunction Prototype_staticFunctions[6] = { {"toCYON", &Instance_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"toJSON", &Instance_callAsFunction_toJSON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"valueOf", &Instance_callAsFunction_valueOf, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, @@ -2795,18 +2753,14 @@ static JSStaticFunction Messages_staticFunctions[2] = { {NULL, NULL, 0} }; -static JSStaticValue Constructor_staticValues[5] = { - {"$cyi", &Constructor_getProperty_$cyi, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, +static JSStaticValue Constructor_staticValues[3] = { {"$cyt", &Constructor_getProperty_$cyt, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, - {"constructor", &Constructor_getProperty_constructor, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"prototype", &Constructor_getProperty_prototype, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {NULL, NULL, NULL, 0} }; -static JSStaticFunction Constructor_staticFunctions[5] = { +static JSStaticFunction Constructor_staticFunctions[2] = { {"pointerTo", &Class_callAsFunction_pointerTo, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, - {"toCYON", &Constructor_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, - {"toPointer", &Constructor_callAsFunction_toPointer, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {NULL, NULL, 0} }; @@ -2866,18 +2820,7 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry { CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; - definition.className = "Constructor"; - definition.parentClass = CYPrivate::Class_; - definition.staticValues = Constructor_staticValues; - definition.staticFunctions = Constructor_staticFunctions; - definition.hasInstance = &Constructor_hasInstance; - definition.hasProperty = &Constructor_hasProperty; - definition.getProperty = &Constructor_getProperty; - definition.callAsConstructor = &Constructor_callAsConstructor; - definition.finalize = &CYFinalize; - CYPrivate::Class_ = JSClassCreate(&definition); - - definition = kJSClassDefinitionEmpty; + definition.attributes = kJSClassAttributeNoAutomaticPrototype; definition.className = "Instance"; definition.staticValues = Instance_staticValues; definition.staticFunctions = Instance_staticFunctions; @@ -2887,29 +2830,28 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry { definition.deleteProperty = &Instance_deleteProperty; definition.getPropertyNames = &Instance_getPropertyNames; definition.finalize = &CYFinalize; - Instance::Class_ = JSClassCreate(&definition); - - definition.className = "ArrayInstance"; - ArrayInstance_ = JSClassCreate(&definition); - - definition.className = "BooleanInstance"; - BooleanInstance_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); - definition.className = "NumberInstance"; - NumberInstance_ = JSClassCreate(&definition); - - definition.className = "ObjectInstance"; - ObjectInstance_ = JSClassCreate(&definition); - - definition.className = "StringInstance"; - StringInstance_ = JSClassCreate(&definition); + definition = kJSClassDefinitionEmpty; + definition.attributes = kJSClassAttributeNoAutomaticPrototype; + definition.className = "Block"; + definition.parentClass = CYPrivate::Class_; + definition.staticValues = Block_staticValues; + definition.callAsFunction = &Block_callAsFunction; + CYPrivate::Class_ = JSClassCreate(&definition); - definition.className = "FunctionInstance"; - definition.staticValues = FunctionInstance_staticValues; - definition.callAsFunction = &FunctionInstance_callAsFunction; - FunctionInstance_ = JSClassCreate(&definition); + definition = kJSClassDefinitionEmpty; + definition.attributes = kJSClassAttributeNoAutomaticPrototype; + definition.className = "Constructor"; + definition.parentClass = CYPrivate::Class_; + definition.staticValues = Constructor_staticValues; + definition.staticFunctions = Constructor_staticFunctions; + definition.hasInstance = &Constructor_hasInstance; + definition.callAsConstructor = &Constructor_callAsConstructor; + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; + definition.attributes = kJSClassAttributeNoAutomaticPrototype; definition.className = "Interior"; definition.staticFunctions = Interior_staticFunctions; definition.hasProperty = &Interior_hasProperty; @@ -2921,8 +2863,7 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry { definition = kJSClassDefinitionEmpty; definition.className = "Message"; - definition.staticFunctions = cy::Functor::StaticFunctions; - definition.staticValues = cy::Functor::StaticValues; + definition.parentClass = cy::Functor::Class_; definition.callAsFunction = &Message_callAsFunction; definition.finalize = &CYFinalize; Message_privateData::Class_ = JSClassCreate(&definition); @@ -2930,7 +2871,7 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry { definition = kJSClassDefinitionEmpty; definition.attributes = kJSClassAttributeNoAutomaticPrototype; definition.className = "Prototype"; - definition.parentClass = CYPrivate::Class_; + definition.staticFunctions = Prototype_staticFunctions; definition.finalize = &CYFinalize; CYPrivate::Class_ = JSClassCreate(&definition); @@ -2943,11 +2884,13 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry { CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; + definition.attributes = kJSClassAttributeNoAutomaticPrototype; definition.className = "Super"; definition.finalize = &CYFinalize; CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; + definition.attributes = kJSClassAttributeNoAutomaticPrototype; definition.className = "ObjectiveC::Classes"; definition.hasProperty = &ObjectiveC_Classes_hasProperty; definition.getProperty = &ObjectiveC_Classes_getProperty; @@ -2955,6 +2898,7 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry { ObjectiveC_Classes_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; + definition.attributes = kJSClassAttributeNoAutomaticPrototype; definition.className = "ObjectiveC::Constants"; definition.getProperty = &ObjectiveC_Constants_getProperty; definition.getPropertyNames = &ObjectiveC_Constants_getPropertyNames; @@ -2962,12 +2906,14 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry { #ifdef __APPLE__ definition = kJSClassDefinitionEmpty; + definition.attributes = kJSClassAttributeNoAutomaticPrototype; definition.className = "ObjectiveC::Images"; definition.getProperty = &ObjectiveC_Images_getProperty; definition.getPropertyNames = &ObjectiveC_Images_getPropertyNames; ObjectiveC_Images_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; + definition.attributes = kJSClassAttributeNoAutomaticPrototype; definition.className = "ObjectiveC::Image::Classes"; definition.getProperty = &ObjectiveC_Image_Classes_getProperty; definition.getPropertyNames = &ObjectiveC_Image_Classes_getPropertyNames; @@ -2975,6 +2921,7 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry { #endif definition = kJSClassDefinitionEmpty; + definition.attributes = kJSClassAttributeNoAutomaticPrototype; definition.className = "ObjectiveC::Protocols"; definition.getProperty = &ObjectiveC_Protocols_getProperty; definition.getPropertyNames = &ObjectiveC_Protocols_getPropertyNames; @@ -3022,50 +2969,45 @@ void CYObjectiveC_SetupContext(JSContextRef context) { CYPoolTry { JSObjectRef Selector(JSObjectMakeConstructor(context, CYPrivate::Class_, &Selector_new)); JSObjectRef Super(JSObjectMakeConstructor(context, CYPrivate::Class_, &Super_new)); - JSObjectRef Instance(JSObjectMakeConstructor(context, Instance::Class_, &Instance_new)); - JSObjectRef Instance_prototype(CYCastJSObject(context, CYGetProperty(context, Instance, prototype_s))); + JSObjectRef Instance(JSObjectMakeConstructor(context, CYPrivate<::Instance>::Class_, &Instance_new)); + JSObjectRef Instance_prototype(JSObjectMake(context, CYPrivate::Class_, NULL)); CYSetProperty(context, cy, CYJSString("Instance_prototype"), Instance_prototype); + CYSetProperty(context, Instance, prototype_s, Instance_prototype); - JSObjectRef Constructor(JSObjectMakeConstructor(context, CYPrivate<::Constructor>::Class_, NULL)); - JSObjectRef Constructor_prototype(CYCastJSObject(context, CYGetProperty(context, Constructor, prototype_s))); - CYSetProperty(context, cy, CYJSString("Constructor_prototype"), Constructor_prototype); - - JSObjectRef ArrayInstance(JSObjectMakeConstructor(context, ArrayInstance_, NULL)); - JSObjectRef ArrayInstance_prototype(CYCastJSObject(context, CYGetProperty(context, ArrayInstance, prototype_s))); + JSObjectRef ArrayInstance_prototype(JSObjectMake(context, CYPrivate::Class_, NULL)); CYSetProperty(context, cy, CYJSString("ArrayInstance_prototype"), ArrayInstance_prototype); JSObjectRef Array_prototype(CYGetCachedObject(context, CYJSString("Array_prototype"))); CYSetPrototype(context, ArrayInstance_prototype, Array_prototype); - JSObjectRef BooleanInstance(JSObjectMakeConstructor(context, BooleanInstance_, NULL)); - JSObjectRef BooleanInstance_prototype(CYCastJSObject(context, CYGetProperty(context, BooleanInstance, prototype_s))); + JSObjectRef BooleanInstance_prototype(JSObjectMake(context, CYPrivate::Class_, NULL)); CYSetProperty(context, cy, CYJSString("BooleanInstance_prototype"), BooleanInstance_prototype); JSObjectRef Boolean_prototype(CYGetCachedObject(context, CYJSString("Boolean_prototype"))); CYSetPrototype(context, BooleanInstance_prototype, Boolean_prototype); - JSObjectRef FunctionInstance(JSObjectMakeConstructor(context, FunctionInstance_, NULL)); - JSObjectRef FunctionInstance_prototype(CYCastJSObject(context, CYGetProperty(context, FunctionInstance, prototype_s))); + JSObjectRef FunctionInstance_prototype(JSObjectMake(context, CYPrivate::Class_, NULL)); CYSetProperty(context, cy, CYJSString("FunctionInstance_prototype"), FunctionInstance_prototype); JSObjectRef Function_prototype(CYGetCachedObject(context, CYJSString("Function_prototype"))); CYSetPrototype(context, FunctionInstance_prototype, Function_prototype); - JSObjectRef NumberInstance(JSObjectMakeConstructor(context, NumberInstance_, NULL)); - JSObjectRef NumberInstance_prototype(CYCastJSObject(context, CYGetProperty(context, NumberInstance, prototype_s))); + JSObjectRef NumberInstance_prototype(JSObjectMake(context, CYPrivate::Class_, NULL)); CYSetProperty(context, cy, CYJSString("NumberInstance_prototype"), NumberInstance_prototype); JSObjectRef Number_prototype(CYGetCachedObject(context, CYJSString("Number_prototype"))); CYSetPrototype(context, NumberInstance_prototype, Number_prototype); - JSObjectRef ObjectInstance(JSObjectMakeConstructor(context, ObjectInstance_, NULL)); - JSObjectRef ObjectInstance_prototype(CYCastJSObject(context, CYGetProperty(context, ObjectInstance, prototype_s))); + JSObjectRef ObjectInstance_prototype(JSObjectMake(context, CYPrivate::Class_, NULL)); CYSetProperty(context, cy, CYJSString("ObjectInstance_prototype"), ObjectInstance_prototype); JSObjectRef Object_prototype(CYGetCachedObject(context, CYJSString("Object_prototype"))); CYSetPrototype(context, ObjectInstance_prototype, Object_prototype); - JSObjectRef StringInstance(JSObjectMakeConstructor(context, StringInstance_, NULL)); - JSObjectRef StringInstance_prototype(CYCastJSObject(context, CYGetProperty(context, StringInstance, prototype_s))); + JSObjectRef StringInstance_prototype(JSObjectMake(context, CYPrivate::Class_, NULL)); CYSetProperty(context, cy, CYJSString("StringInstance_prototype"), StringInstance_prototype); JSObjectRef String_prototype(CYGetCachedObject(context, CYJSString("String_prototype"))); CYSetPrototype(context, StringInstance_prototype, String_prototype); + JSObjectRef TypeInstance_prototype(JSObjectMake(context, CYPrivate::Class_, NULL)); + CYSetProperty(context, cy, CYJSString("TypeInstance_prototype"), TypeInstance_prototype); + // XXX: maybe TypeInstance should have Type as its prototype? FWIW, that's why I named it like this ;P + CYSetProperty(context, cycript, CYJSString("Instance"), Instance); CYSetProperty(context, cycript, CYJSString("Message"), Message); CYSetProperty(context, cycript, CYJSString("Selector"), Selector);