X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/0b5f88f67491643e48cfb14b28a4e894296ae98f..0a4d6bce78c5cd6fa45e62365bdf22e9edde61bf:/Internal.hpp diff --git a/Internal.hpp b/Internal.hpp index 464fe93..e019312 100644 --- a/Internal.hpp +++ b/Internal.hpp @@ -39,15 +39,19 @@ sig::Type *Structor_(CYPool &pool, sig::Aggregate *aggregate); extern JSClassRef Functor_; -template -struct CYPrivate : +struct CYRoot : CYData { - static JSClassRef Class_; - _finline JSValueRef GetPrototype(JSContextRef context) const { return NULL; } +}; + +template +struct CYPrivateOld : + Base_ +{ + static JSClassRef Class_; template _finline static JSClassRef GetClass(Args_ &&... args) { @@ -69,8 +73,33 @@ struct CYPrivate : } }; +template +JSClassRef CYPrivateOld::Class_; + +template +struct CYPrivate { + static JSClassRef Class_; + + template + static JSObjectRef Make(JSContextRef context, Args_ &&... args) { + Internal_ *internal(new Internal_(cy::Forward(args)...)); + JSObjectRef object(JSObjectMake(context, Class_, internal)); + if (JSValueRef prototype = internal->GetPrototype(context)) + CYSetPrototype(context, object, prototype); + return object; + } + + static Internal_ *Get(JSContextRef context, JSObjectRef object) { + _assert(JSValueIsObjectOfClass(context, object, Class_)); + return static_cast(JSObjectGetPrivate(object)); + } +}; + +template +JSClassRef CYPrivate::Class_; + struct Type_privateData : - CYPrivate + CYRoot { ffi_type *ffi_; sig::Type *type_; @@ -117,29 +146,6 @@ struct Type_privateData : } }; -template -struct CYValue : - CYPrivate -{ - Value_ value_; - - CYValue() { - } - - CYValue(const Value_ &value) : - value_(value) - { - } - - CYValue(const CYValue &rhs) : - value_(rhs.value_) - { - } -}; - -template -JSClassRef CYPrivate::Class_; - struct CYProtect { private: JSGlobalContextRef context_; @@ -176,7 +182,7 @@ struct CYProtect { namespace cy { struct Functor : - CYValue + CYRoot { private: void set() { @@ -184,12 +190,13 @@ struct Functor : } public: + void (*value_)(); bool variadic_; sig::Signature signature_; ffi_cif cif_; Functor(void (*value)(), bool variadic, const sig::Signature &signature) : - CYValue(value), + value_(value), variadic_(variadic) { sig::Copy(*pool_, signature_, signature); @@ -197,7 +204,7 @@ struct Functor : } Functor(void (*value)(), const char *encoding) : - CYValue(value), + value_(value), variadic_(false) { sig::Parse(*pool_, &signature_, encoding, &Structor_);