- Type_privateData(CYPool &pool, const char *type) :
- CYData(pool),
- ffi_(NULL)
- {
- sig::Signature signature;
- sig::Parse(*pool_, &signature, type, &Structor_);
- type_ = signature.elements[0].type;
+ static Internal_ *Get(JSContextRef context, JSObjectRef object) {
+ _assert(JSValueIsObjectOfClass(context, object, Class_));
+ return static_cast<Internal_ *>(JSObjectGetPrivate(object));
+ }
+};
+
+template <typename Internal_, typename Base_>
+JSClassRef CYPrivateOld<Internal_, Base_>::Class_;
+
+template <typename Internal_>
+struct CYPrivate {
+ static JSClassRef Class_;
+
+ template <typename... Args_>
+ static JSObjectRef Make(JSContextRef context, Args_ &&... args) {
+ Internal_ *internal(new Internal_(cy::Forward<Args_>(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<Internal_ *>(JSObjectGetPrivate(object));