X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/c30687a7155e8c96310eaddd8213f6d3a69cab0e..20ded97a3fd17e970ee44a9a2ae273098e27c3cb:/Execute.cpp diff --git a/Execute.cpp b/Execute.cpp index b781a39..8ac1b14 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"); @@ -1308,6 +1316,7 @@ void CYInitializeDynamic() { splice_s = JSStringCreateWithUTF8CString("splice"); toCYON_s = JSStringCreateWithUTF8CString("toCYON"); toJSON_s = JSStringCreateWithUTF8CString("toJSON"); + toPointer_s = JSStringCreateWithUTF8CString("toPointer"); Result_ = JSStringCreateWithUTF8CString("_");