X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/1850a470682f2bbbec1587adacfb1bb4320f30dc..0ced2e47fe333ec4a4b1222fa298561c5479696c:/Execute.cpp?ds=inline diff --git a/Execute.cpp b/Execute.cpp index 806fd39..e8ea4ae 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -165,6 +165,7 @@ JSStringRef push_s; JSStringRef splice_s; JSStringRef toCYON_s; JSStringRef toJSON_s; +JSStringRef toPointer_s; static JSStringRef Result_; @@ -514,12 +515,19 @@ void *CYCastPointer_(JSContextRef context, JSValueRef value) { switch (JSValueGetType(context, value)) { case kJSTypeNull: return NULL; - /*case kJSTypeObject: + case kJSTypeObject: { + JSObjectRef object((JSObjectRef) value); if (JSValueIsObjectOfClass(context, value, Pointer_)) { - Pointer *internal(reinterpret_cast(JSObjectGetPrivate((JSObjectRef) value))); + Pointer *internal(reinterpret_cast(JSObjectGetPrivate(object))); return internal->value_; - }*/ - default: + } + JSValueRef toPointer(CYGetProperty(context, object, toPointer_s)); + if (CYIsCallable(context, toPointer)) { + JSValueRef value(CYCallAsFunction(context, (JSObjectRef) toPointer, object, 0, NULL)); + _assert(value != NULL); + return CYCastPointer_(context, value); + } + } default: double number(CYCastDouble(context, value)); if (std::isnan(number)) throw CYJSError(context, "cannot convert value to pointer"); @@ -1191,7 +1199,7 @@ JSObjectRef CYGetGlobalObject(JSContextRef context) { return JSContextGetGlobalObject(context); } -const char *CYExecute(apr_pool_t *pool, const char *code) { +const char *CYExecute(apr_pool_t *pool, CYUTF8String code) { JSContextRef context(CYGetJSContext()); JSValueRef exception(NULL), result; @@ -1294,6 +1302,7 @@ void CYInitializeDynamic() { Type_privateData::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; + definition.className = "Global"; //definition.getProperty = &Global_getProperty; Global_ = JSClassCreate(&definition); @@ -1308,6 +1317,7 @@ void CYInitializeDynamic() { splice_s = JSStringCreateWithUTF8CString("splice"); toCYON_s = JSStringCreateWithUTF8CString("toCYON"); toJSON_s = JSStringCreateWithUTF8CString("toJSON"); + toPointer_s = JSStringCreateWithUTF8CString("toPointer"); Result_ = JSStringCreateWithUTF8CString("_"); @@ -1413,23 +1423,25 @@ extern "C" void CYSetupContext(JSGlobalContextRef context) { JSObjectRef all(JSObjectMake(context, All_, NULL)); CYSetProperty(context, cycript, CYJSString("all"), all); - JSObjectRef last(NULL), curr(global); + if (true) { + JSObjectRef last(NULL), curr(global); - goto next; for (JSValueRef next;;) { - if (JSValueIsNull(context, next)) - break; - last = curr; - curr = CYCastJSObject(context, next); - next: - next = JSObjectGetPrototype(context, curr); - } + goto next; for (JSValueRef next;;) { + if (JSValueIsNull(context, next)) + break; + last = curr; + curr = CYCastJSObject(context, next); + next: + next = JSObjectGetPrototype(context, curr); + } - JSObjectSetPrototype(context, last, all); + JSObjectSetPrototype(context, last, all); + } - CYSetProperty(context, global, CYJSString("$cyq"), &$cyq); + CYSetProperty(context, global, CYJSString("$cyq"), &$cyq, kJSPropertyAttributeDontEnum); JSObjectRef System(JSObjectMake(context, NULL, NULL)); - CYSetProperty(context, cy, CYJSString("System"), Function); + CYSetProperty(context, cy, CYJSString("System"), System); CYSetProperty(context, global, CYJSString("system"), System); CYSetProperty(context, System, CYJSString("args"), CYJSNull(context));