1 #ifndef CYCRIPT_INTERNAL_HPP
2 #define CYCRIPT_INTERNAL_HPP
6 #include <JavaScriptCore/JSBase.h>
7 #include <JavaScriptCore/JSObjectRef.h>
8 #include <JavaScriptCore/JSValueRef.h>
10 #include <sig/parse.hpp>
11 #include <sig/ffi_type.hpp>
13 void Structor_(apr_pool_t *pool, const char *name, const char *types, sig::Type *&type);
15 struct Type_privateData :
18 static JSClassRef Class_;
23 void Set(sig::Type *type) {
24 type_ = new(pool_) sig::Type;
25 sig::Copy(pool_, *type_, *type);
28 Type_privateData(apr_pool_t *pool, const char *type) :
34 sig::Signature signature;
35 sig::Parse(pool_, &signature, type, &Structor_);
36 type_ = signature.elements[0].type;
39 Type_privateData(sig::Type *type) :
46 Type_privateData(sig::Type *type, ffi_type *ffi) {
47 ffi_ = new(pool_) ffi_type;
48 sig::Copy(pool_, *ffi_, *ffi);
54 ffi_ = new(pool_) ffi_type;
61 sig::Signature signature;
62 signature.elements = &element;
66 sig::sig_ffi_cif(pool_, &sig::ObjectiveC, &signature, &cif);
82 CYValue(const void *value) :
83 value_(const_cast<void *>(value))
87 CYValue(const CYValue &rhs) :
92 virtual Type_privateData *GetType() const {
101 JSContextRef context_;
105 CYOwned(void *value, JSContextRef context, JSObjectRef owner) :
111 JSValueProtect(context_, owner_);
116 JSValueUnprotect(context_, owner_);
119 JSObjectRef GetOwner() const {
128 sig::Signature signature_;
131 Functor(const char *type, void (*value)()) :
132 CYValue(reinterpret_cast<void *>(value))
134 sig::Parse(pool_, &signature_, type, &Structor_);
135 sig::sig_ffi_cif(pool_, &sig::ObjectiveC, &signature_, &cif_);
138 void (*GetValue())() const {
139 return reinterpret_cast<void (*)()>(value_);
142 static JSStaticFunction const * const StaticFunctions;
145 struct Closure_privateData :
148 JSContextRef context_;
149 JSObjectRef function_;
151 Closure_privateData(JSContextRef context, JSObjectRef function, const char *type) :
152 cy::Functor(type, NULL),
156 JSValueProtect(context_, function_);
159 virtual ~Closure_privateData() {
160 JSValueUnprotect(context_, function_);
164 Closure_privateData *CYMakeFunctor_(JSContextRef context, JSObjectRef function, const char *type, void (*callback)(ffi_cif *, void *, void **, void *));
166 #endif/*CYCRIPT_INTERNAL_HPP*/