From: Jay Freeman (saurik) Date: Sun, 3 Jan 2016 12:51:15 +0000 (-0800) Subject: Accept initializers when allocating Type with new. X-Git-Tag: v0.9.590~80 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/f472e52e4b5ee9147023ba4f22da8c18bed9a00a?hp=c9b965e40ad1ad73542865fb65990a8b59e3131b Accept initializers when allocating Type with new. --- diff --git a/Execute.cpp b/Execute.cpp index deafccb..cc47fd6 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -1536,10 +1536,11 @@ static JSValueRef Type_callAsFunction(JSContextRef context, JSObjectRef object, return CYMakeFunctor(context, arguments[0], function->variadic, function->signature); CYPool pool; + sig::Type *type(internal->type_); ffi_type *ffi(internal->GetFFI()); - void *data(pool.malloc(ffi->size, ffi->alignment)); + type->PoolFFI(&pool, context, ffi, data, arguments[0]); JSValueRef value(type->FromFFI(context, ffi, data)); @@ -1553,15 +1554,22 @@ static JSValueRef Type_callAsFunction(JSContextRef context, JSObjectRef object, } CYCatch(NULL) } static JSObjectRef Type_callAsConstructor(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { - if (count != 0) + if (count > 1) throw CYJSError(context, "incorrect number of arguments to Type allocator"); Type_privateData *internal(reinterpret_cast(JSObjectGetPrivate(object))); JSObjectRef pointer(CYMakePointer(context, NULL, *internal->type_, NULL, NULL)); Pointer *value(reinterpret_cast(JSObjectGetPrivate(pointer))); + + sig::Type *type(internal->type_); ffi_type *ffi(internal->GetFFI()); value->value_ = value->pool_->malloc(ffi->size, ffi->alignment); - memset(value->value_, 0, ffi->size); + + if (count == 0) + memset(value->value_, 0, ffi->size); + else + type->PoolFFI(value->pool_, context, ffi, value->value_, arguments[0]); + return pointer; } CYCatch(NULL) }