From 217f652fdefefc86d562d49f9815001653f99075 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sat, 9 Jan 2016 08:36:47 -0800 Subject: [PATCH] Pointer needs a special case to pull off functors. --- Execute.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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); -- 2.49.0