}
};
+static JSObjectRef CYGetJavaClass(JSContextRef context, JNIEnv *jni, jclass _class);
+
struct CYJavaObject :
CYJavaValue<CYJavaObject, jobject>
{
- CYJavaObject(JNIEnv *jni, jobject value) :
- CYJavaValue(jni, value)
+ CYJavaClass *table_;
+
+ CYJavaObject(JNIEnv *jni, jobject value, JSContextRef context) :
+ CYJavaValue(jni, value),
+ table_(reinterpret_cast<CYJavaClass *>(JSObjectGetPrivate(CYGetJavaClass(context, jni, _envcall(jni, GetObjectClass(value))))))
{
}
JSValueRef GetPrototype(JSContextRef context) const;
};
+struct CYJavaInterior :
+ CYJavaValue<CYJavaInterior, jobject>
+{
+ CYJavaClass *table_;
+
+ CYJavaInterior(JNIEnv *jni, jobject value, CYJavaClass *table) :
+ CYJavaValue(jni, value),
+ table_(table)
+ {
+ }
+};
+
struct CYJavaPackage :
CYPrivate<CYJavaPackage>
{
}
};
-static JSObjectRef CYGetJavaClass(JSContextRef context, JNIEnv *jni, jclass _class);
-
JSValueRef CYJavaObject::GetPrototype(JSContextRef context) const {
JNIEnv *jni(value_);
return CYGetProperty(context, CYGetJavaClass(context, jni, _envcall(jni, GetObjectClass(value_))), prototype_s);
static JSValueRef CYCastJSValue(JSContextRef context, JNIEnv *jni, jobject value) {
if (value == NULL)
return CYJSNull(context);
-
- return CYJavaObject::Make(context, jni, value);
+ return CYJavaObject::Make(context, jni, value, context);
}
static jstring CYCastJavaString(JNIEnv *jni, CYUTF16String value) {
}
}
-CYJavaClass *CYGetJavaTable(JSContextRef context, JNIEnv *jni, jobject object) {
- // XXX: this implementation is absolutely unacceptable :/
- return reinterpret_cast<CYJavaClass *>(JSObjectGetPrivate(CYGetJavaClass(context, jni, _envcall(jni, GetObjectClass(object)))));
-}
-
static JSObjectRef CYGetJavaClass(JSContextRef context, JNIEnv *jni, jclass value) {
JSObjectRef global(CYGetGlobalObject(context));
JSObjectRef cy(CYCastJSObject(context, CYGetProperty(context, global, cy_s)));
return CYCastJSValue(context, table->value_, table->value_);
} CYCatch(NULL) }
-static bool JavaObject_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef property) {
- CYJavaObject *internal(reinterpret_cast<CYJavaObject *>(JSObjectGetPrivate(object)));
- JNIEnv *jni(internal->value_);
- CYJavaClass *table(CYGetJavaTable(context, jni, internal->value_));
+static bool JavaInterior_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef property) {
+ CYJavaInterior *internal(reinterpret_cast<CYJavaInterior *>(JSObjectGetPrivate(object)));
+ CYJavaClass *table(internal->table_);
CYPool pool;
auto name(CYPoolUTF8String(pool, context, property));
auto field(table->instance_.find(name));
return true;
}
-static JSValueRef JavaObject_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
- CYJavaObject *internal(reinterpret_cast<CYJavaObject *>(JSObjectGetPrivate(object)));
+static JSValueRef JavaInterior_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
+ CYJavaInterior *internal(reinterpret_cast<CYJavaInterior *>(JSObjectGetPrivate(object)));
JNIEnv *jni(internal->value_);
- CYJavaClass *table(CYGetJavaTable(context, jni, internal->value_));
+ CYJavaClass *table(internal->table_);
CYPool pool;
auto name(CYPoolUTF8String(pool, context, property));
auto field(table->instance_.find(name));
}
} CYCatch(NULL) }
-static bool JavaObject_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYTry {
- CYJavaObject *internal(reinterpret_cast<CYJavaObject *>(JSObjectGetPrivate(object)));
+static bool JavaInterior_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYTry {
+ CYJavaInterior *internal(reinterpret_cast<CYJavaInterior *>(JSObjectGetPrivate(object)));
JNIEnv *jni(internal->value_);
- CYJavaClass *table(CYGetJavaTable(context, jni, internal->value_));
+ CYJavaClass *table(internal->table_);
CYPool pool;
auto name(CYPoolUTF8String(pool, context, property));
auto field(table->instance_.find(name));
return true;
} CYCatch(false) }
-static void JavaObject_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef names) {
- CYJavaObject *internal(reinterpret_cast<CYJavaObject *>(JSObjectGetPrivate(object)));
- JNIEnv *jni(internal->value_);
- CYJavaClass *table(CYGetJavaTable(context, jni, internal->value_));
+static void JavaInterior_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef names) {
+ CYJavaInterior *internal(reinterpret_cast<CYJavaInterior *>(JSObjectGetPrivate(object)));
+ CYJavaClass *table(internal->table_);
for (const auto &field : table->instance_)
JSPropertyNameAccumulatorAddName(names, CYJSString(field.first));
}
return CYGetJavaClass(context, jni, _envcall(jni, GetObjectClass(internal->value_)));
} CYCatch(NULL) }
+static JSValueRef JavaObject_getProperty_$cyi(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
+ CYJavaObject *internal(reinterpret_cast<CYJavaObject *>(JSObjectGetPrivate(object)));
+ JNIEnv *jni(internal->value_);
+ return CYJavaInterior::Make(context, jni, internal->value_, internal->table_);
+} CYCatch(NULL) }
+
static bool CYJavaPackage_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef property) {
return true;
}
{NULL, NULL, NULL, 0}
};
-static JSStaticValue JavaObject_staticValues[2] = {
+static JSStaticValue JavaObject_staticValues[3] = {
{"constructor", &JavaObject_getProperty_constructor, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+ {"$cyi", &JavaObject_getProperty_$cyi, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{NULL, NULL, NULL, 0}
};
definition.finalize = &CYFinalize;
CYJavaClass::Class_ = JSClassCreate(&definition);
+ definition = kJSClassDefinitionEmpty;
+ definition.attributes = kJSClassAttributeNoAutomaticPrototype;
+ definition.className = "JavaInterior";
+ definition.hasProperty = &JavaInterior_hasProperty;
+ definition.getProperty = &JavaInterior_getProperty;
+ definition.setProperty = &JavaInterior_setProperty;
+ definition.getPropertyNames = &JavaInterior_getPropertyNames;
+ definition.finalize = &CYFinalize;
+ CYJavaInterior::Class_ = JSClassCreate(&definition);
+
definition = kJSClassDefinitionEmpty;
definition.className = "JavaMethod";
definition.callAsFunction = &JavaMethod_callAsFunction;
definition.attributes = kJSClassAttributeNoAutomaticPrototype;
definition.className = "JavaObject";
definition.staticValues = JavaObject_staticValues;
- definition.hasProperty = &JavaObject_hasProperty;
- definition.getProperty = &JavaObject_getProperty;
- definition.setProperty = &JavaObject_setProperty;
- definition.getPropertyNames = &JavaObject_getPropertyNames;
definition.finalize = &CYFinalize;
CYJavaObject::Class_ = JSClassCreate(&definition);
id self(internal->value_);
if (JSStringIsEqualToUTF8CString(property, "$cyi"))
- return Internal::Make(context, self, context, object);
+ return Interior::Make(context, self, context, object);
CYPool pool;
NSString *name(CYCastNSString(&pool, context, property));
return CYCastJSValue(context, [value cy$box]);
} CYCatch(NULL) }
-static bool Internal_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef property) {
- Internal *internal(reinterpret_cast<Internal *>(JSObjectGetPrivate(object)));
+static bool Interior_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef property) {
+ Interior *internal(reinterpret_cast<Interior *>(JSObjectGetPrivate(object)));
CYPool pool;
id self(internal->value_);
free(ivars);
}
-static JSValueRef Internal_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
- Internal *internal(reinterpret_cast<Internal *>(JSObjectGetPrivate(object)));
+static JSValueRef Interior_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
+ Interior *internal(reinterpret_cast<Interior *>(JSObjectGetPrivate(object)));
CYPool pool;
id self(internal->value_);
return NULL;
} CYCatch(NULL) }
-static bool Internal_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYTry {
- Internal *internal(reinterpret_cast<Internal *>(JSObjectGetPrivate(object)));
+static bool Interior_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYTry {
+ Interior *internal(reinterpret_cast<Interior *>(JSObjectGetPrivate(object)));
CYPool pool;
id self(internal->value_);
return false;
} CYCatch(false) }
-static void Internal_getPropertyNames_(Class _class, JSPropertyNameAccumulatorRef names) {
+static void Interior_getPropertyNames_(Class _class, JSPropertyNameAccumulatorRef names) {
if (Class super = class_getSuperclass(_class))
- Internal_getPropertyNames_(super, names);
+ Interior_getPropertyNames_(super, names);
unsigned int size;
objc_ivar **data(class_copyIvarList(_class, &size));
free(data);
}
-static void Internal_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef names) {
- Internal *internal(reinterpret_cast<Internal *>(JSObjectGetPrivate(object)));
+static void Interior_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef names) {
+ Interior *internal(reinterpret_cast<Interior *>(JSObjectGetPrivate(object)));
CYPool pool;
id self(internal->value_);
Class _class(object_getClass(self));
- Internal_getPropertyNames_(_class, names);
+ Interior_getPropertyNames_(_class, names);
}
-static JSValueRef Internal_callAsFunction_$cya(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
- Internal *internal(reinterpret_cast<Internal *>(JSObjectGetPrivate(object)));
+static JSValueRef Interior_callAsFunction_$cya(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
+ Interior *internal(reinterpret_cast<Interior *>(JSObjectGetPrivate(object)));
return internal->owner_;
} CYCatch(NULL) }
{NULL, NULL, 0}
};
-static JSStaticFunction Internal_staticFunctions[2] = {
- {"$cya", &Internal_callAsFunction_$cya, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+static JSStaticFunction Interior_staticFunctions[2] = {
+ {"$cya", &Interior_callAsFunction_$cya, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{NULL, NULL, 0}
};
ClassInstance_ = JSClassCreate(&definition);
definition = kJSClassDefinitionEmpty;
- definition.className = "Internal";
- definition.staticFunctions = Internal_staticFunctions;
- definition.hasProperty = &Internal_hasProperty;
- definition.getProperty = &Internal_getProperty;
- definition.setProperty = &Internal_setProperty;
- definition.getPropertyNames = &Internal_getPropertyNames;
+ definition.className = "Interior";
+ definition.staticFunctions = Interior_staticFunctions;
+ definition.hasProperty = &Interior_hasProperty;
+ definition.getProperty = &Interior_getProperty;
+ definition.setProperty = &Interior_setProperty;
+ definition.getPropertyNames = &Interior_getPropertyNames;
definition.finalize = &CYFinalize;
- Internal::Class_ = JSClassCreate(&definition);
+ Interior::Class_ = JSClassCreate(&definition);
definition = kJSClassDefinitionEmpty;
definition.className = "Message";