From: Jay Freeman (saurik) Date: Sat, 9 Jan 2016 16:36:47 +0000 (-0800) Subject: Pointer needs a special case to pull off functors. X-Git-Tag: v0.9.590~18 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/217f652fdefefc86d562d49f9815001653f99075?ds=sidebyside Pointer needs a special case to pull off functors. --- diff --git a/Execute.cpp b/Execute.cpp index 0378d0b..6ded65e 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -703,6 +703,8 @@ void *CYCastPointer_(JSContextRef context, JSValueRef value, bool *guess) { } } +static JSValueRef FunctionAdapter_(JSContextRef context, size_t count, JSValueRef values[], JSObjectRef function); + namespace sig { // XXX: this is somehow not quite a template :/ @@ -786,8 +788,15 @@ void Pointer::PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *d *reinterpret_cast(data) = CYCastPointer(context, value, &guess); if (!guess || pool == NULL || !JSValueIsObject(context, value)) return; + JSObjectRef object(CYCastJSObject(context, value)); - if (CYHasProperty(context, object, length_s)) { + + if (sig::Function *function = dynamic_cast(&type)) { + _assert(!function->variadic); + auto internal(CYMakeFunctor_(context, object, function->signature, &FunctionAdapter_)); + // XXX: see notes in Library.cpp about needing to leak + *reinterpret_cast(data) = internal->value_; + } else if (CYHasProperty(context, object, length_s)) { size_t length(CYArrayLength(context, object)); ffi_type *element(type.GetFFI(*pool)); size_t size(element->size * length);