CYSetProperty(context, object, name, JSObjectMakeFunctionWithCallback(context, name, callback), attributes);
}
+JSObjectRef CYGetPrototype(JSContextRef context, JSObjectRef object) {
+ return CYCastJSObject(context, JSObjectGetPrototype(context, object));
+}
+
void CYSetPrototype(JSContextRef context, JSObjectRef object, JSValueRef value) {
+ _assert(!JSValueIsUndefined(context, value));
JSObjectSetPrototype(context, object, value);
_assert(CYIsStrictEqual(context, JSObjectGetPrototype(context, object), value));
}
}
}
+JSStringRef CYCopyJSString(const std::string &value) {
+ return CYCopyJSString(CYUTF8String(value.c_str(), value.size()));
+}
+
JSStringRef CYCopyJSString(CYUTF16String value) {
return JSStringCreateWithCharacters(value.data, value.size);
}
return _jsccall(JSValueToStringCopy, context, value);
}
-static CYUTF16String CYCastUTF16String(JSStringRef value) {
+CYUTF16String CYCastUTF16String(JSStringRef value) {
return CYUTF16String(JSStringGetCharactersPtr(value), JSStringGetLength(value));
}
static JSObjectRef (*JSObjectMakeArray$)(JSContextRef, size_t, const JSValueRef[], JSValueRef *);
-static JSObjectRef CYObjectMakeArray(JSContextRef context, size_t length, const JSValueRef values[]) {
+JSObjectRef CYObjectMakeArray(JSContextRef context, size_t length, const JSValueRef values[]) {
if (JSObjectMakeArray$ != NULL)
return _jsccall(*JSObjectMakeArray$, context, length, values);
else {
}
static JSClassRef All_;
-static JSClassRef Context_;
JSClassRef Functor_;
static JSClassRef Global_;
return aggregate;
}
-JSClassRef Type_privateData::Class_;
-
struct Context :
- CYData
+ CYPrivate<Context>
{
JSGlobalContextRef context_;
};
struct CArray :
- CYValue_<CArray, void *>
+ CYValue<CArray, void *>
{
CYProtect owner_;
Type_privateData *type_;
size_t length_;
CArray(void *value, size_t length, const sig::Type &type, ffi_type *ffi, JSContextRef context, JSObjectRef owner) :
- CYValue_(value),
+ CYValue(value),
owner_(context, owner),
type_(new(*pool_) Type_privateData(type, ffi)),
length_(length)
if (owner == NULL) {
size_t size(ffi->size * length);
void *copy(pool_->malloc<void>(size, ffi->alignment));
- memcpy(copy, GetValue(), size);
+ memcpy(copy, value_, size);
value_ = copy;
}
}
};
struct CString :
- CYValue_<CString, char *>
+ CYValue<CString, char *>
{
CYProtect owner_;
CString(char *value, JSContextRef context, JSObjectRef owner) :
- CYValue_(value),
+ CYValue(value),
owner_(context, owner)
{
if (owner == NULL)
- value_ = pool_->strdup(GetValue());
+ value_ = pool_->strdup(value_);
}
};
struct Pointer :
- CYValue_<Pointer, void *>
+ CYValue<Pointer, void *>
{
CYProtect owner_;
Type_privateData *type_;
Pointer(void *value, const sig::Type &type, JSContextRef context, JSObjectRef owner) :
- CYValue_(value),
+ CYValue(value),
owner_(context, owner),
type_(new(*pool_) Type_privateData(type))
{
}
Pointer(void *value, const char *encoding, JSContextRef context, JSObjectRef owner) :
- CYValue_(value),
+ CYValue(value),
owner_(context, owner),
type_(new(*pool_) Type_privateData(encoding))
{
};
struct Struct_privateData :
- CYValue_<Struct_privateData, void *>
+ CYValue<Struct_privateData, void *>
{
CYProtect owner_;
Type_privateData *type_;
Struct_privateData(void *value, const sig::Type &type, ffi_type *ffi, JSContextRef context, JSObjectRef owner) :
- CYValue_(value),
+ CYValue(value),
owner_(context, owner),
type_(new(*pool_) Type_privateData(type, ffi))
{
if (owner == NULL) {
size_t size(ffi->size);
void *copy(pool_->malloc<void>(size, ffi->alignment));
- memcpy(copy, GetValue(), size);
+ memcpy(copy, value_, size);
value_ = copy;
}
}
return CYArrayPush(context, array, 1, &value);
}
-template <size_t Size_>
-class CYArrayBuilder {
- private:
- JSContextRef context_;
- JSObjectRef &array_;
- size_t size_;
- JSValueRef values_[Size_];
-
- void flush() {
- if (array_ == NULL)
- array_ = CYObjectMakeArray(context_, size_, values_);
- else
- CYArrayPush(context_, array_, size_, values_);
- }
-
- public:
- CYArrayBuilder(JSContextRef context, JSObjectRef &array) :
- context_(context),
- array_(array),
- size_(0)
- {
- }
-
- ~CYArrayBuilder() {
- flush();
- }
-
- void operator ()(JSValueRef value) {
- if (size_ == Size_) {
- flush();
- size_ = 0;
- }
-
- values_[size_++] = value;
- }
-};
-
static JSValueRef System_print(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
FILE *file(stdout);
return JSObjectMake(context, Functor_, internal);
}
-static bool CYGetOffset(CYPool &pool, JSContextRef context, JSStringRef value, ssize_t &index) {
+bool CYGetOffset(CYPool &pool, JSContextRef context, JSStringRef value, ssize_t &index) {
return CYGetOffset(CYPoolCString(pool, context, value), index);
}
void CYExecuteClosure(ffi_cif *cif, void *result, void **arguments, void *arg) {
Closure_privateData *internal(reinterpret_cast<Closure_privateData *>(arg));
- JSContextRef context(internal->context_);
+ JSContextRef context(internal->function_);
size_t count(internal->cif_.nargs);
JSValueRef values[count];
_assert(status == FFI_OK);
internal->pool_->atexit(&CYFreeFunctor, writable);
- internal->value_ = executable;
+ internal->value_ = reinterpret_cast<void (*)()>(executable);
#else
ffi_closure *closure((ffi_closure *) _syscall(mmap(
NULL, sizeof(ffi_closure),
_syscall(mprotect(closure, sizeof(*closure), PROT_READ | PROT_EXEC));
internal->pool_->atexit(&CYFreeFunctor, closure);
- internal->value_ = closure;
+ internal->value_ = reinterpret_cast<void (*)()>(closure);
#endif
return internal;
if (!CYGetOffset(pool, context, property, offset))
return NULL;
- return CYCastJSValue(context, CYJSString(CYUTF8String(&internal->GetValue()[offset], 1)));
+ return CYCastJSValue(context, CYJSString(CYUTF8String(&internal->value_[offset], 1)));
} CYCatch(NULL) }
static bool CString_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYTry {
return false;
const char *data(CYPoolCString(pool, context, value));
- internal->GetValue()[offset] = *data;
+ internal->value_[offset] = *data;
return true;
} CYCatch(false) }
static JSValueRef Functor_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
CYPool pool;
cy::Functor *internal(reinterpret_cast<cy::Functor *>(JSObjectGetPrivate(object)));
- return CYCallFunction(pool, context, 0, NULL, count, arguments, false, internal->variadic_, internal->signature_, &internal->cif_, internal->GetValue());
+ return CYCallFunction(pool, context, 0, NULL, count, arguments, false, internal->variadic_, internal->signature_, &internal->cif_, internal->value_);
} CYCatch(NULL) }
static JSValueRef Pointer_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
} CYCatch(NULL) }
JSObjectRef CYMakeType(JSContextRef context, const sig::Type &type) {
- Type_privateData *internal(new Type_privateData(type));
- return JSObjectMake(context, Type_privateData::Class_, internal);
+ return Type_privateData::Make(context, type);
}
extern "C" bool CYBridgeHash(CYPool &pool, CYUTF8String name, const char *&code, unsigned &flags) {
sig::Function type(internal->variadic_);
sig::Copy(pool, type.signature, internal->signature_);
- return CYMakePointer(context, internal->value_, type, NULL, NULL);
+ return CYMakePointer(context, reinterpret_cast<void *>(internal->value_), type, NULL, NULL);
} CYCatch(NULL) }
static JSValueRef Pointer_callAsFunction_toPointer(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
return _this;
} CYCatch(NULL) }
-static JSValueRef CYValue_callAsFunction_valueOf(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
- CYValue *internal(reinterpret_cast<CYValue *>(JSObjectGetPrivate(_this)));
+static JSValueRef CArray_callAsFunction_valueOf(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
+ CArray *internal(reinterpret_cast<CArray *>(JSObjectGetPrivate(_this)));
return CYCastJSValue(context, reinterpret_cast<uintptr_t>(internal->value_));
} CYCatch(NULL) }
-static JSValueRef CYValue_callAsFunction_toJSON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
- return CYValue_callAsFunction_valueOf(context, object, _this, count, arguments, exception);
-}
+static JSValueRef Pointer_callAsFunction_valueOf(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
+ Pointer *internal(reinterpret_cast<Pointer *>(JSObjectGetPrivate(_this)));
+ return CYCastJSValue(context, reinterpret_cast<uintptr_t>(internal->value_));
+} CYCatch(NULL) }
-static JSValueRef CYValue_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
- CYValue *internal(reinterpret_cast<CYValue *>(JSObjectGetPrivate(_this)));
+static JSValueRef Functor_callAsFunction_valueOf(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
+ cy::Functor *internal(reinterpret_cast<cy::Functor *>(JSObjectGetPrivate(_this)));
+ return CYCastJSValue(context, reinterpret_cast<uintptr_t>(internal->value_));
+} CYCatch(NULL) }
+
+static JSValueRef Functor_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
+ cy::Functor *internal(reinterpret_cast<cy::Functor *>(JSObjectGetPrivate(_this)));
+ uint8_t *value(reinterpret_cast<uint8_t *>(internal->value_));
std::ostringstream str;
Dl_info info;
if (internal->value_ == NULL)
str << "NULL";
- else if (dladdr(internal->value_, &info) == 0)
+ else if (dladdr(value, &info) == 0)
str << internal->value_;
else {
str << info.dli_sname;
- off_t offset(static_cast<char *>(internal->value_) - static_cast<char *>(info.dli_saddr));
+ off_t offset(value - reinterpret_cast<uint8_t *>(info.dli_saddr));
if (offset != 0)
str << "+0x" << std::hex << offset;
}
- std::string value(str.str());
- return CYCastJSValue(context, CYJSString(CYUTF8String(value.c_str(), value.size())));
+ return CYCastJSValue(context, CYJSString(str.str()));
} CYCatch(NULL) }
static JSValueRef Pointer_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
static JSValueRef CString_getProperty_length(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
CString *internal(reinterpret_cast<CString *>(JSObjectGetPrivate(object)));
- return CYCastJSValue(context, strlen(internal->GetValue()));
+ return CYCastJSValue(context, strlen(internal->value_));
} CYCatch(NULL) }
static JSValueRef CString_getProperty_$cyt(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
static JSValueRef CString_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
CString *internal(reinterpret_cast<CString *>(JSObjectGetPrivate(_this)));
- const char *string(internal->GetValue());
+ const char *string(internal->value_);
std::ostringstream str;
if (string == NULL)
str << "NULL";
static JSValueRef CString_callAsFunction_toString(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
CString *internal(reinterpret_cast<CString *>(JSObjectGetPrivate(_this)));
- return CYCastJSValue(context, internal->GetValue());
+ return CYCastJSValue(context, internal->value_);
} CYCatch(NULL) }
static JSValueRef Functor_getProperty_$cyt(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
return CYCastJSValue(context, CYJSString(out.str().c_str()));
} CYCatch(NULL) }
-static JSValueRef Type_callAsFunction_toJSON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
- return Type_callAsFunction_toString(context, object, _this, count, arguments, exception);
-}
-
static JSStaticFunction All_staticFunctions[2] = {
{"cy$complete", &All_complete_callAsFunction, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{NULL, NULL, 0}
};
-static JSStaticFunction CArray_staticFunctions[4] = {
- {"toJSON", &CYValue_callAsFunction_toJSON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+static JSStaticFunction CArray_staticFunctions[3] = {
{"toPointer", &CArray_callAsFunction_toPointer, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
- {"valueOf", &CYValue_callAsFunction_valueOf, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+ {"valueOf", &CArray_callAsFunction_valueOf, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{NULL, NULL, 0}
};
{NULL, NULL, NULL, 0}
};
-static JSStaticFunction CString_staticFunctions[6] = {
+static JSStaticFunction CString_staticFunctions[5] = {
{"toCYON", &CString_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
- {"toJSON", &CYValue_callAsFunction_toJSON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"toPointer", &CString_callAsFunction_toPointer, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"toString", &CString_callAsFunction_toString, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"valueOf", &CString_callAsFunction_toString, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{NULL, NULL, NULL, 0}
};
-static JSStaticFunction Pointer_staticFunctions[5] = {
+static JSStaticFunction Pointer_staticFunctions[4] = {
{"toCYON", &Pointer_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
- {"toJSON", &CYValue_callAsFunction_toJSON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"toPointer", &Pointer_callAsFunction_toPointer, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
- {"valueOf", &CYValue_callAsFunction_valueOf, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+ {"valueOf", &Pointer_callAsFunction_valueOf, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{NULL, NULL, 0}
};
{NULL, NULL, NULL, 0}
};
-static JSStaticFunction Functor_staticFunctions[5] = {
+static JSStaticFunction Functor_staticFunctions[4] = {
{"$cya", &Functor_callAsFunction_$cya, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
- {"toCYON", &CYValue_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
- {"toJSON", &CYValue_callAsFunction_toJSON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
- {"valueOf", &CYValue_callAsFunction_valueOf, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+ {"toCYON", &Functor_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+ {"valueOf", &Functor_callAsFunction_valueOf, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{NULL, NULL, 0}
};
{NULL, NULL, NULL, 0}
};
-static JSStaticFunction Type_staticFunctions[10] = {
+static JSStaticFunction Type_staticFunctions[9] = {
{"arrayOf", &Type_callAsFunction_arrayOf, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"blockWith", &Type_callAsFunction_blockWith, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"constant", &Type_callAsFunction_constant, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"pointerTo", &Type_callAsFunction_pointerTo, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"withName", &Type_callAsFunction_withName, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"toCYON", &Type_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
- {"toJSON", &Type_callAsFunction_toJSON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"toString", &Type_callAsFunction_toString, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{NULL, NULL, 0}
};
definition = kJSClassDefinitionEmpty;
definition.className = "Context";
definition.finalize = &CYFinalize;
- Context_ = JSClassCreate(&definition);
+ Context::Class_ = JSClassCreate(&definition);
definition = kJSClassDefinitionEmpty;
definition.className = "CArray";
JSObjectRef global(CYGetGlobalObject(context));
- JSObjectRef cy(JSObjectMake(context, Context_, new Context(context)));
+ JSObjectRef cy(Context::Make(context, context));
CYSetProperty(context, global, cy_s, cy, kJSPropertyAttributeDontEnum);
/* Cache Globals {{{ */