- * Cycript is free software: you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or (at your
- * option) any later version.
+ * Cycript is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
- * Cycript is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
+ * Cycript is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
JSValueRef CYCastJSValue(JSContextRef context, bool value) {
return JSValueMakeBoolean(context, value);
}
JSValueRef CYCastJSValue(JSContextRef context, bool value) {
return JSValueMakeBoolean(context, value);
}
const char *CYPoolCCYON(apr_pool_t *pool, JSContextRef context, JSValueRef value) {
JSValueRef exception(NULL);
const char *CYPoolCCYON(apr_pool_t *pool, JSContextRef context, JSValueRef value) {
JSValueRef exception(NULL);
std::string value(str.str());
return CYCastJSValue(context, CYJSString(CYUTF8String(value.c_str(), value.size())));
std::string value(str.str());
return CYCastJSValue(context, CYJSString(CYUTF8String(value.c_str(), value.size())));
static JSValueRef String_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
CYPool pool;
static JSValueRef String_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
CYPool pool;
std::string value(str.str());
return CYCastJSValue(context, CYJSString(CYUTF8String(value.c_str(), value.size())));
std::string value(str.str());
return CYCastJSValue(context, CYJSString(CYUTF8String(value.c_str(), value.size())));
JSObjectRef CYMakePointer(JSContextRef context, void *pointer, size_t length, sig::Type *type, ffi_type *ffi, JSObjectRef owner) {
Pointer *internal(new Pointer(pointer, context, owner, length, type));
return JSObjectMake(context, Pointer_, internal);
}
JSObjectRef CYMakePointer(JSContextRef context, void *pointer, size_t length, sig::Type *type, ffi_type *ffi, JSObjectRef owner) {
Pointer *internal(new Pointer(pointer, context, owner, length, type));
return JSObjectMake(context, Pointer_, internal);
}
-static JSObjectRef CYMakeFunctor(JSContextRef context, void (*function)(), const char *type, void **cache = NULL) {
- cy::Functor *internal;
+static JSObjectRef CYMakeFunctor(JSContextRef context, void (*function)(), const char *type) {
+ return JSObjectMake(context, Functor_, new cy::Functor(type, function));
+}
JSObjectRef owner(internal->GetOwner() ?: object);
return CYFromFFI(context, typical->type_, ffi, base, false, owner);
JSObjectRef owner(internal->GetOwner() ?: object);
return CYFromFFI(context, typical->type_, ffi, base, false, owner);
static bool Pointer_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYTry {
CYPool pool;
static bool Pointer_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYTry {
CYPool pool;
ssize_t offset;
if (JSStringIsEqualToUTF8CString(property, "$cyi"))
offset = 0;
else if (!CYGetOffset(pool, context, property, offset))
ssize_t offset;
if (JSStringIsEqualToUTF8CString(property, "$cyi"))
offset = 0;
else if (!CYGetOffset(pool, context, property, offset))
CYPoolFFI(NULL, context, typical->type_, ffi, base, value);
return true;
CYPoolFFI(NULL, context, typical->type_, ffi, base, value);
return true;
static JSValueRef Struct_callAsFunction_$cya(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
Struct_privateData *internal(reinterpret_cast<Struct_privateData *>(JSObjectGetPrivate(_this)));
static JSValueRef Struct_callAsFunction_$cya(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
Struct_privateData *internal(reinterpret_cast<Struct_privateData *>(JSObjectGetPrivate(_this)));
JSObjectRef owner(internal->GetOwner() ?: object);
return CYFromFFI(context, typical->type_->data.signature.elements[index].type, typical->GetFFI()->elements[index], base, false, owner);
JSObjectRef owner(internal->GetOwner() ?: object);
return CYFromFFI(context, typical->type_->data.signature.elements[index].type, typical->GetFFI()->elements[index], base, false, owner);
static bool Struct_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYTry {
CYPool pool;
static bool Struct_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYTry {
CYPool pool;
CYPoolFFI(NULL, context, typical->type_->data.signature.elements[index].type, typical->GetFFI()->elements[index], base, value);
return true;
CYPoolFFI(NULL, context, typical->type_->data.signature.elements[index].type, typical->GetFFI()->elements[index], base, value);
return true;
static void Struct_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef names) {
Struct_privateData *internal(reinterpret_cast<Struct_privateData *>(JSObjectGetPrivate(object)));
static void Struct_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef names) {
Struct_privateData *internal(reinterpret_cast<Struct_privateData *>(JSObjectGetPrivate(object)));
ffi_call(cif, function, value, values);
return CYFromFFI(context, signature->elements[0].type, cif->rtype, value, initialize);
ffi_call(cif, function, value, values);
return CYFromFFI(context, signature->elements[0].type, cif->rtype, value, initialize);
static JSValueRef Functor_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
CYPool pool;
static JSValueRef Functor_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
CYPool pool;
static JSValueRef All_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
JSObjectRef global(CYGetGlobalObject(context));
JSObjectRef cycript(CYCastJSObject(context, CYGetProperty(context, global, CYJSString("Cycript"))));
static JSValueRef All_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
JSObjectRef global(CYGetGlobalObject(context));
JSObjectRef cycript(CYCastJSObject(context, CYGetProperty(context, global, CYJSString("Cycript"))));
return JSEvaluateScript(CYGetJSContext(context), CYJSString(entry->value_), NULL, NULL, 0, NULL);
case '1':
return JSEvaluateScript(CYGetJSContext(context), CYJSString(entry->value_), NULL, NULL, 0, NULL);
case '1':
- if (void (*symbol)() = reinterpret_cast<void (*)()>(CYCastSymbol(name.data)))
- return CYMakeFunctor(context, symbol, entry->value_, &entry->cache_);
- else return NULL;
+ return CYMakeFunctor(context, name.data, entry->value_, &entry->cache_);
static void All_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef names) {
JSObjectRef global(CYGetGlobalObject(context));
static void All_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef names) {
JSObjectRef global(CYGetGlobalObject(context));
sig::Parse(pool, &signature, type, &Structor_);
return CYMakePointer(context, value, _not(size_t), signature.elements[0].type, NULL, NULL);
sig::Parse(pool, &signature, type, &Structor_);
return CYMakePointer(context, value, _not(size_t), signature.elements[0].type, NULL, NULL);
static JSObjectRef Type_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 1)
static JSObjectRef Type_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 1)
CYPool pool;
const char *type(CYPoolCString(pool, context, arguments[0]));
return CYMakeType(context, type);
CYPool pool;
const char *type(CYPoolCString(pool, context, arguments[0]));
return CYMakeType(context, type);
static JSValueRef Type_callAsFunction_arrayOf(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 1)
static JSValueRef Type_callAsFunction_arrayOf(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 1)
type.data.data.size = index;
return CYMakeType(context, &type);
type.data.data.size = index;
return CYMakeType(context, &type);
static JSValueRef Type_callAsFunction_constant(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 0)
static JSValueRef Type_callAsFunction_constant(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 0)
sig::Type type(*internal->type_);
type.flags |= JOC_TYPE_CONST;
return CYMakeType(context, &type);
sig::Type type(*internal->type_);
type.flags |= JOC_TYPE_CONST;
return CYMakeType(context, &type);
static JSValueRef Type_callAsFunction_pointerTo(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 0)
static JSValueRef Type_callAsFunction_pointerTo(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 0)
static JSValueRef Type_callAsFunction_withName(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 1)
static JSValueRef Type_callAsFunction_withName(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 1)
sig::Type type(*internal->type_);
type.name = name;
return CYMakeType(context, &type);
sig::Type type(*internal->type_);
type.name = name;
return CYMakeType(context, &type);
static JSValueRef Type_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 1)
static JSValueRef Type_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 1)
CYPool pool;
CYPoolFFI(pool, context, type, ffi, value, arguments[0]);
return CYFromFFI(context, type, ffi, value);
CYPool pool;
CYPoolFFI(pool, context, type, ffi, value, arguments[0]);
return CYFromFFI(context, type, ffi, value);
static JSObjectRef Type_callAsConstructor(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 0)
static JSObjectRef Type_callAsConstructor(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 0)
void *value(malloc(internal->GetFFI()->size));
return CYMakePointer(context, value, length, type, NULL, NULL);
void *value(malloc(internal->GetFFI()->size));
return CYMakePointer(context, value, length, type, NULL, NULL);
static JSObjectRef Functor_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 2)
static JSObjectRef Functor_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (count != 2)
CYPool pool;
const char *type(CYPoolCString(pool, context, arguments[1]));
return CYMakeFunctor(context, arguments[0], type);
CYPool pool;
const char *type(CYPoolCString(pool, context, arguments[1]));
return CYMakeFunctor(context, arguments[0], type);
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)));
return CYCastJSValue(context, reinterpret_cast<uintptr_t>(internal->value_));
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)));
return CYCastJSValue(context, reinterpret_cast<uintptr_t>(internal->value_));
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 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);
char string[32];
sprintf(string, "%p", internal->value_);
return CYCastJSValue(context, string);
char string[32];
sprintf(string, "%p", internal->value_);
return CYCastJSValue(context, string);
static JSValueRef Pointer_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
Pointer *internal(reinterpret_cast<Pointer *>(JSObjectGetPrivate(_this)));
if (internal->length_ != _not(size_t)) {
static JSValueRef Pointer_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
Pointer *internal(reinterpret_cast<Pointer *>(JSObjectGetPrivate(_this)));
if (internal->length_ != _not(size_t)) {
JSObjectRef toCYON(CYCastJSObject(context, CYGetProperty(context, Array, toCYON_s)));
return CYCallAsFunction(context, toCYON, _this, count, arguments);
} else {
JSObjectRef toCYON(CYCastJSObject(context, CYGetProperty(context, Array, toCYON_s)));
return CYCallAsFunction(context, toCYON, _this, count, arguments);
} else {
sprintf(string, "%p", internal->value_);
return CYCastJSValue(context, string);
}
sprintf(string, "%p", internal->value_);
return CYCastJSValue(context, string);
}
static JSValueRef Type_getProperty_alignment(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) {
Type_privateData *internal(reinterpret_cast<Type_privateData *>(JSObjectGetPrivate(object)));
static JSValueRef Type_getProperty_alignment(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) {
Type_privateData *internal(reinterpret_cast<Type_privateData *>(JSObjectGetPrivate(object)));
CYPool pool;
const char *type(sig::Unparse(pool, internal->type_));
return CYCastJSValue(context, CYJSString(type));
CYPool pool;
const char *type(sig::Unparse(pool, internal->type_));
return CYCastJSValue(context, CYJSString(type));
static JSValueRef Type_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
Type_privateData *internal(reinterpret_cast<Type_privateData *>(JSObjectGetPrivate(_this)));
static JSValueRef Type_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
Type_privateData *internal(reinterpret_cast<Type_privateData *>(JSObjectGetPrivate(_this)));
CYStringify(str, type, strlen(type));
char *cyon(apr_pstrcat(pool, "new Type(", str.str().c_str(), ")", NULL));
return CYCastJSValue(context, CYJSString(cyon));
CYStringify(str, type, strlen(type));
char *cyon(apr_pstrcat(pool, "new Type(", str.str().c_str(), ")", NULL));
return CYCastJSValue(context, CYJSString(cyon));
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 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);
//CYSetProperty(context, System, CYJSString("global"), global);
CYSetProperty(context, System, CYJSString("print"), &System_print);
//CYSetProperty(context, System, CYJSString("global"), global);
CYSetProperty(context, System, CYJSString("print"), &System_print);