From ec18fc0ee15ed0b8303b70608bd58181fc9c691e Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Tue, 27 Apr 2010 11:44:23 +0000 Subject: [PATCH] Support enumeration of implicit properties. --- ObjectiveC/Library.mm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index 9d5289f..0df87c6 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -1623,6 +1623,7 @@ static JSValueRef Instance_getProperty(JSContextRef context, JSObjectRef object, } #endif + // XXX: maybe this should only be messages that return something? if (SEL sel = sel_getUid(string)) if (CYImplements(self, _class, sel, true)) return CYSendMessage(pool, context, self, NULL, sel, 0, NULL, false, exception); @@ -1699,6 +1700,18 @@ static bool Instance_deleteProperty(JSContextRef context, JSObjectRef object, JS } CYPoolCatch(NULL) } CYCatch return /*XXX*/ NULL; } +static void Instance_getPropertyNames_message(JSPropertyNameAccumulatorRef names, objc_method *method) { + const char *name(sel_getName(method_getName(method))); + if (strchr(name, ':') != NULL) + return; + + const char *type(method_getTypeEncoding(method)); + if (type == NULL || *type == '\0' || *type == 'v') + return; + + JSPropertyNameAccumulatorAddName(names, CYJSString(name)); +} + static void Instance_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef names) { Instance *internal(reinterpret_cast(JSObjectGetPrivate(object))); id self(internal->GetValue()); @@ -1716,6 +1729,18 @@ static void Instance_getPropertyNames(JSContextRef context, JSObjectRef object, } #endif +#if OBJC_API_VERSION >= 2 + unsigned int size; + objc_method **data(class_copyMethodList(_class, &size)); + for (size_t i(0); i != size; ++i) + Instance_getPropertyNames_message(names, data[i]); + free(data); +#else + for (objc_method_list *methods(_class->methods); methods != NULL; methods = methods->method_next) + for (int i(0); i != methods->method_count; ++i) + Instance_getPropertyNames_message(names, &methods->method_list[i]); +#endif + CYPoolTry { // XXX: this is an evil hack to deal with NSProxy; fix elsewhere if (CYImplements(self, _class, @selector(cy$getPropertyNames:inContext:), false)) -- 2.47.2