X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/98735bfe852adb9e5421e5c04bb2e0119af443bd..79492f212da2fcaa4ce44d00fc08530e1630d05b:/ObjectiveC/Library.mm?ds=sidebyside
diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm
index bb7acf3..cb95509 100644
--- a/ObjectiveC/Library.mm
+++ b/ObjectiveC/Library.mm
@@ -1,21 +1,21 @@
/* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2013 Jay Freeman (saurik)
+ * Copyright (C) 2009-2014 Jay Freeman (saurik)
*/
-/* GNU General Public License, Version 3 {{{ */
+/* GNU Affero General Public License, Version 3 {{{ */
/*
- * Cycript is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation, either version 3 of the License,
- * or (at your option) any later version.
- *
- * Cycript is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Cycript. If not, see .
+ * GNU Affero General Public License for more details.
+
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
**/
/* }}} */
@@ -308,8 +308,6 @@ static Class NSCFBoolean_;
static Class NSCFType_;
static Class NSGenericDeallocHandler_;
static Class NSZombie_;
-
-static std::set banned_;
#else
static Class NSBoolNumber_;
#endif
@@ -481,7 +479,13 @@ NSString *CYCastNSCYON(id value, bool objective, std::set &objects) {
Class _class(object_getClass(value));
SEL sel(@selector(cy$toCYON:inSet:));
- if (objc_method *toCYON = class_getInstanceMethod(_class, sel))
+ if (class_isMetaClass(_class)) {
+ const char *name(class_getName(value));
+ if (class_isMetaClass(value))
+ string = [NSString stringWithFormat:@"object_getClass(%s)", name];
+ else
+ string = [NSString stringWithUTF8String:name];
+ } else if (objc_method *toCYON = class_getInstanceMethod(_class, sel))
string = reinterpret_cast &)>(method_getImplementation(toCYON))(value, sel, objective, objects);
else if (objc_method *methodSignatureForSelector = class_getInstanceMethod(_class, @selector(methodSignatureForSelector:))) {
if (reinterpret_cast(method_getImplementation(methodSignatureForSelector))(value, @selector(methodSignatureForSelector:), sel) != nil)
@@ -490,13 +494,8 @@ NSString *CYCastNSCYON(id value, bool objective, std::set &objects) {
} else fail: {
if (false);
#ifdef __APPLE__
- else if (value == NSZombie_)
- string = @"_NSZombie_";
else if (_class == NSZombie_)
string = [NSString stringWithFormat:@"<_NSZombie_: %p>", value];
- // XXX: frowny /in/ the pants
- else if (banned_.find(value) != banned_.end())
- string = nil;
#endif
else
string = [NSString stringWithFormat:@"%@", value];
@@ -2100,8 +2099,8 @@ static JSValueRef Internal_getProperty(JSContextRef context, JSObjectRef object,
uintptr_t mask((1 << length) - 1);
return CYCastJSValue(context, (field >> shift) & mask);
} else {
- Type_privateData type(pool, ivar_getTypeEncoding(ivar));
- return CYFromFFI(context, type.type_, type.GetFFI(), data);
+ auto type(new(pool) Type_privateData(ivar_getTypeEncoding(ivar)));
+ return CYFromFFI(context, type->type_, type->GetFFI(), data);
}
}
@@ -2129,8 +2128,8 @@ static bool Internal_setProperty(JSContextRef context, JSObjectRef object, JSStr
uintptr_t mask((1 << length) - 1);
field = field & ~(mask << shift) | (uintptr_t(CYCastDouble(context, value)) & mask) << shift;
} else {
- Type_privateData type(pool, ivar_getTypeEncoding(ivar));
- CYPoolFFI(&pool, context, type.type_, type.GetFFI(), reinterpret_cast(self) + ivar_getOffset(ivar), value);
+ auto type(new(pool) Type_privateData(ivar_getTypeEncoding(ivar)));
+ CYPoolFFI(&pool, context, type->type_, type->GetFFI(), reinterpret_cast(self) + ivar_getOffset(ivar), value);
return true;
}
}
@@ -2733,16 +2732,11 @@ static JSValueRef Class_callAsFunction_pointerTo(JSContextRef context, JSObjectR
if (!CYIsClass(value))
CYThrow("non-Class object cannot be used as Type");
- // XXX: this is a very silly implementation
-
- std::ostringstream type;
- type << "@\"";
- type << class_getName(value);
- type << "\"";
-
- CYPoolTry {
- return CYMakeType(context, type.str().c_str());
- } CYPoolCatch(NULL)
+ sig::Type type;
+ memset(&type, 0, sizeof(type));
+ type.primitive = sig::object_P;
+ type.name = class_getName(value);
+ return CYMakeType(context, &type);
} CYCatch(NULL) return /*XXX*/ NULL; }
static JSValueRef Selector_callAsFunction_toString(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
@@ -2846,8 +2840,8 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry {
CYPool &pool(CYGetGlobalPool());
- Object_type = new(pool) Type_privateData("@");
- Selector_type = new(pool) Type_privateData(":");
+ Object_type = new(pool) Type_privateData(sig::object_P);
+ Selector_type = new(pool) Type_privateData(sig::selector_P);
NSArray_ = objc_getClass("NSArray");
NSBlock_ = objc_getClass("NSBlock");
@@ -2867,12 +2861,6 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry {
NSCFType_ = objc_getClass("NSCFType");
NSZombie_ = objc_getClass("_NSZombie_");
-
- banned_.insert(Object_);
- banned_.insert(objc_getClass("__NSAtom"));
- banned_.insert(objc_getClass("__NSGenericDeallocHandler"));
- banned_.insert(objc_getClass("NSMessageBuilder"));
- banned_.insert(objc_getClass("__NSMessageBuilder"));
#else
NSBoolNumber_ = objc_getClass("NSBoolNumber");
#endif
@@ -3099,7 +3087,7 @@ void CYObjectiveC_SetupContext(JSContextRef context) { CYPoolTry {
CYSetPrototype(context, CYCastJSObject(context, CYGetProperty(context, Selector, prototype_s)), Function_prototype);
} CYPoolCatch() }
-static CYHooks CYObjectiveCHooks = {
+static CYHook CYObjectiveCHook = {
&CYObjectiveC_ExecuteStart,
&CYObjectiveC_ExecuteEnd,
&CYObjectiveC_CallFunction,
@@ -3109,13 +3097,7 @@ static CYHooks CYObjectiveCHooks = {
&CYObjectiveC_FromFFI,
};
-struct CYObjectiveC {
- CYObjectiveC() {
- hooks_ = &CYObjectiveCHooks;
- // XXX: evil magic juju to make this actually take effect on a Mac when compiled with autoconf/libtool doom!
- _assert(hooks_ != NULL);
- }
-} CYObjectiveC;
+CYRegisterHook CYObjectiveC(&CYObjectiveCHook);
extern "C" void CydgetSetupContext(JSGlobalContextRef context) { CYObjectiveTry_ {
CYSetupContext(context);