From 10e728bb967b8f052c07480275400d631fb6f531 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 23 Jan 2014 12:41:10 -0800 Subject: [PATCH] Setting to .messages should only affect that Class. --- ObjectiveC/Library.mm | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index 7ac3bb0..00ea5df 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -1648,11 +1648,8 @@ static bool Messages_setProperty(JSContextRef context, JSObjectRef object, JSStr CYPool pool; const char *name(CYPoolCString(pool, context, property)); - SEL sel(sel_registerName(name)); - objc_method *method(class_getInstanceMethod(_class, sel)); - const char *type; IMP imp; @@ -1661,10 +1658,30 @@ static bool Messages_setProperty(JSContextRef context, JSObjectRef object, JSStr type = sig::Unparse(pool, &message->signature_); imp = reinterpret_cast(message->GetValue()); } else { + objc_method *method(class_getInstanceMethod(_class, sel)); type = CYPoolTypeEncoding(pool, context, sel, method); imp = CYMakeMessage(context, value, type); } + objc_method *method(NULL); +#if OBJC_API_VERSION >= 2 + unsigned int size; + objc_method **methods(class_copyMethodList(_class, &size)); + for (size_t i(0); i != size; ++i) + if (sel_isEqual(method_getName(methods[i]), sel)) { + method = methods[i]; + break; + } + free(methods); +#else + for (objc_method_list *methods(_class->methods); methods != NULL; methods = methods->method_next) + for (int i(0); i != methods->method_count; ++i) + if (sel_isEqual(method_getName(&methods->method_list[i]), sel)) { + method = &methods->method_list[i]; + break; + } +#endif + if (method != NULL) method_setImplementation(method, imp); else { -- 2.45.2