From: Jay Freeman (saurik) Date: Thu, 7 Jan 2016 03:36:12 +0000 (-0800) Subject: Remove CYJavaValue and (almost) CYPrivate as base. X-Git-Tag: v0.9.590~44 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/d4222ffb92c744b8ebfca3914267df58f6f2a5ec Remove CYJavaValue and (almost) CYPrivate as base. --- diff --git a/Execute.cpp b/Execute.cpp index f620f38..db6c5ba 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -227,7 +227,7 @@ sig::Type *Structor_(CYPool &pool, sig::Aggregate *aggregate) { } struct Context : - CYPrivate + CYRoot { JSGlobalContextRef context_; @@ -238,7 +238,7 @@ struct Context : }; struct CArray : - CYPrivate + CYRoot { void *value_; CYProtect owner_; @@ -261,7 +261,7 @@ struct CArray : }; struct CString : - CYPrivate + CYRoot { char *value_; CYProtect owner_; @@ -276,7 +276,7 @@ struct CString : }; struct Pointer : - CYPrivate + CYRoot { void *value_; CYProtect owner_; @@ -298,7 +298,7 @@ struct Pointer : }; struct Struct_privateData : - CYPrivate + CYRoot { void *value_; CYProtect owner_; @@ -635,7 +635,7 @@ static JSValueRef String_callAsFunction_toCYON(JSContextRef context, JSObjectRef } CYCatch(NULL) } JSObjectRef CYMakePointer(JSContextRef context, void *pointer, const sig::Type &type, ffi_type *ffi, JSObjectRef owner) { - return Pointer::Make(context, pointer, type, context, owner); + return CYPrivate::Make(context, pointer, type, context, owner); } static JSValueRef CYMakeFunctor(JSContextRef context, void (*function)(), bool variadic, const sig::Signature &signature) { @@ -667,7 +667,7 @@ void *CYCastPointer_(JSContextRef context, JSValueRef value, bool *guess) { return NULL; case kJSTypeObject: { JSObjectRef object((JSObjectRef) value); - if (JSValueIsObjectOfClass(context, value, Pointer::Class_)) { + if (JSValueIsObjectOfClass(context, value, CYPrivate::Class_)) { Pointer *internal(reinterpret_cast(JSObjectGetPrivate(object))); return internal->value_; } @@ -862,7 +862,7 @@ JSValueRef Unknown::FromFFI(JSContextRef context, ffi_type *ffi, void *data, boo JSValueRef String::FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const { if (char *value = *reinterpret_cast(data)) - return CString::Make(context, value, context, owner); + return CYPrivate::Make(context, value, context, owner); return CYJSNull(context); } @@ -877,7 +877,7 @@ JSValueRef Pointer::FromFFI(JSContextRef context, ffi_type *ffi, void *data, boo } JSValueRef Array::FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const { - return CArray::Make(context, data, size, type, ffi->elements[0], context, owner); + return CYPrivate::Make(context, data, size, type, ffi->elements[0], context, owner); } JSValueRef Enum::FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const { @@ -887,7 +887,7 @@ JSValueRef Enum::FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool i JSValueRef Aggregate::FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const { _assert(!overlap); _assert(signature.count != _not(size_t)); - return Struct_privateData::Make(context, data, *this, ffi, context, owner); + return CYPrivate::Make(context, data, *this, ffi, context, owner); } JSValueRef Function::FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const { @@ -1206,7 +1206,7 @@ static sig::Type *CYGetType(CYPool &pool, JSContextRef context, JSValueRef value return &PointerToVoid_; JSObjectRef object(CYCastJSObject(context, value)); JSObjectRef type(CYCastJSObject(context, CYGetProperty(context, object, cyt_s))); - _assert(JSValueIsObjectOfClass(context, type, Type_privateData::Class_)); + _assert(JSValueIsObjectOfClass(context, type, CYPrivate::Class_)); Type_privateData *internal(reinterpret_cast(JSObjectGetPrivate(type))); return internal->type_; } @@ -1283,7 +1283,7 @@ static JSValueRef Pointer_callAsFunction(JSContextRef context, JSObjectRef objec } CYCatch(NULL) } JSObjectRef CYMakeType(JSContextRef context, const sig::Type &type) { - return Type_privateData::Make(context, type); + return CYPrivate::Make(context, type); } extern "C" bool CYBridgeHash(CYPool &pool, CYUTF8String name, const char *&code, unsigned &flags) { @@ -1513,7 +1513,7 @@ static JSObjectRef Type_new(JSContextRef context, JSObjectRef object, size_t cou element.name = CYPoolCString(pool, context, name); JSObjectRef object(CYCastJSObject(context, CYArrayGet(context, types, i))); - _assert(JSValueIsObjectOfClass(context, object, Type_privateData::Class_)); + _assert(JSValueIsObjectOfClass(context, object, CYPrivate::Class_)); Type_privateData *internal(reinterpret_cast(JSObjectGetPrivate(object))); element.type = internal->type_; _assert(element.type != NULL); @@ -1543,7 +1543,7 @@ static JSValueRef Type_callAsFunction_$With(JSContextRef context, JSObjectRef ob element.offset = _not(size_t); JSObjectRef object(CYCastJSObject(context, arguments[i])); - _assert(JSValueIsObjectOfClass(context, object, Type_privateData::Class_)); + _assert(JSValueIsObjectOfClass(context, object, CYPrivate::Class_)); Type_privateData *internal(reinterpret_cast(JSObjectGetPrivate(object))); element.type = internal->type_; @@ -2091,7 +2091,7 @@ void CYInitializeDynamic() { definition = kJSClassDefinitionEmpty; definition.className = "Context"; definition.finalize = &CYFinalize; - Context::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.className = "CArray"; @@ -2100,7 +2100,7 @@ void CYInitializeDynamic() { definition.getProperty = &CArray_getProperty; definition.setProperty = &CArray_setProperty; definition.finalize = &CYFinalize; - CArray::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.className = "CString"; @@ -2109,7 +2109,7 @@ void CYInitializeDynamic() { definition.getProperty = &CString_getProperty; definition.setProperty = &CString_setProperty; definition.finalize = &CYFinalize; - CString::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.className = "Functor"; @@ -2127,7 +2127,7 @@ void CYInitializeDynamic() { definition.getProperty = &Pointer_getProperty; definition.setProperty = &Pointer_setProperty; definition.finalize = &CYFinalize; - Pointer::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.className = "Struct"; @@ -2137,7 +2137,7 @@ void CYInitializeDynamic() { definition.setProperty = &Struct_setProperty; definition.getPropertyNames = &Struct_getPropertyNames; definition.finalize = &CYFinalize; - Struct_privateData::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.className = "Type"; @@ -2146,7 +2146,7 @@ void CYInitializeDynamic() { definition.callAsFunction = &Type_callAsFunction; definition.callAsConstructor = &Type_callAsConstructor; definition.finalize = &CYFinalize; - Type_privateData::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.className = "Global"; @@ -2372,7 +2372,7 @@ extern "C" void CYSetupContext(JSGlobalContextRef context) { JSObjectRef global(CYGetGlobalObject(context)); - JSObjectRef cy(Context::Make(context, context)); + JSObjectRef cy(CYPrivate::Make(context, context)); CYSetProperty(context, global, cy_s, cy, kJSPropertyAttributeDontEnum); /* Cache Globals {{{ */ @@ -2430,11 +2430,11 @@ extern "C" void CYSetupContext(JSGlobalContextRef context) { CYSetProperty(context, cycript, CYJSString("compile"), &Cycript_compile_callAsFunction); CYSetProperty(context, cycript, CYJSString("gc"), &Cycript_gc_callAsFunction); - JSObjectRef CArray(JSObjectMakeConstructor(context, CArray::Class_, &CArray_new)); + JSObjectRef CArray(JSObjectMakeConstructor(context, CYPrivate<::CArray>::Class_, &CArray_new)); CYSetPrototype(context, CYCastJSObject(context, CYGetProperty(context, CArray, prototype_s)), Array_prototype); CYSetProperty(context, cycript, CYJSString("CArray"), CArray); - JSObjectRef CString(JSObjectMakeConstructor(context, CString::Class_, &CString_new)); + JSObjectRef CString(JSObjectMakeConstructor(context, CYPrivate<::CString>::Class_, &CString_new)); CYSetPrototype(context, CYCastJSObject(context, CYGetProperty(context, CString, prototype_s)), String_prototype); CYSetProperty(context, cycript, CYJSString("CString"), CString); @@ -2442,8 +2442,8 @@ extern "C" void CYSetupContext(JSGlobalContextRef context) { CYSetPrototype(context, CYCastJSObject(context, CYGetProperty(context, Functor, prototype_s)), Function_prototype); CYSetProperty(context, cycript, CYJSString("Functor"), Functor); - CYSetProperty(context, cycript, CYJSString("Pointer"), JSObjectMakeConstructor(context, Pointer::Class_, &Pointer_new)); - CYSetProperty(context, cycript, CYJSString("Type"), JSObjectMakeConstructor(context, Type_privateData::Class_, &Type_new)); + CYSetProperty(context, cycript, CYJSString("Pointer"), JSObjectMakeConstructor(context, CYPrivate::Class_, &Pointer_new)); + CYSetProperty(context, cycript, CYJSString("Type"), JSObjectMakeConstructor(context, CYPrivate::Class_, &Type_new)); JSObjectRef modules(JSObjectMake(context, NULL, NULL)); CYSetProperty(context, cy, CYJSString("modules"), modules); diff --git a/Internal.hpp b/Internal.hpp index b4acd18..e019312 100644 --- a/Internal.hpp +++ b/Internal.hpp @@ -39,15 +39,19 @@ sig::Type *Structor_(CYPool &pool, sig::Aggregate *aggregate); extern JSClassRef Functor_; -template -struct CYPrivate : +struct CYRoot : CYData { - static JSClassRef Class_; - _finline JSValueRef GetPrototype(JSContextRef context) const { return NULL; } +}; + +template +struct CYPrivateOld : + Base_ +{ + static JSClassRef Class_; template _finline static JSClassRef GetClass(Args_ &&... args) { @@ -69,8 +73,33 @@ struct CYPrivate : } }; +template +JSClassRef CYPrivateOld::Class_; + +template +struct CYPrivate { + static JSClassRef Class_; + + template + static JSObjectRef Make(JSContextRef context, Args_ &&... args) { + Internal_ *internal(new Internal_(cy::Forward(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(JSObjectGetPrivate(object)); + } +}; + +template +JSClassRef CYPrivate::Class_; + struct Type_privateData : - CYPrivate + CYRoot { ffi_type *ffi_; sig::Type *type_; @@ -117,9 +146,6 @@ struct Type_privateData : } }; -template -JSClassRef CYPrivate::Class_; - struct CYProtect { private: JSGlobalContextRef context_; @@ -156,7 +182,7 @@ struct CYProtect { namespace cy { struct Functor : - CYPrivate + CYRoot { private: void set() { diff --git a/Java/Execute.cpp b/Java/Execute.cpp index d9eb1e6..c7ecbb1 100644 --- a/Java/Execute.cpp +++ b/Java/Execute.cpp @@ -449,20 +449,6 @@ static CYJavaLocal CYCastJavaString(const CYJavaRef &value) { return jni.CallObjectMethod(value, Object$toString); } -template -struct CYJavaValue : - CYPrivate -{ - CYJavaGlobal value_; - - CYJavaValue(const CYJavaRef &value) : - value_(value) - { - } - - CYJavaValue(const CYJavaValue &) = delete; -}; - static JSValueRef CYCastJSValue(JSContextRef context, const CYJavaRef &value); template @@ -540,7 +526,7 @@ struct CYJavaSignature { typedef std::multiset CYJavaOverload; struct CYJavaMethod : - CYPrivate + CYRoot { CYJavaOverload overload_; @@ -551,7 +537,7 @@ struct CYJavaMethod : }; struct CYJavaStaticMethod : - CYPrivate + CYRoot { CYJavaOverload overload_; @@ -562,8 +548,9 @@ struct CYJavaStaticMethod : }; struct CYJavaClass : - CYJavaValue + CYRoot { + CYJavaGlobal value_; bool interface_; CYJavaFieldMap static_; @@ -571,7 +558,7 @@ struct CYJavaClass : CYJavaOverload overload_; CYJavaClass(const CYJavaRef &value, bool interface) : - CYJavaValue(value), + value_(value), interface_(interface) { } @@ -580,12 +567,13 @@ struct CYJavaClass : static JSObjectRef CYGetJavaClass(JSContextRef context, const CYJavaRef &_class); struct CYJavaObject : - CYJavaValue + CYRoot { + CYJavaGlobal value_; CYJavaClass *table_; CYJavaObject(const CYJavaRef &value, CYJavaClass *table) : - CYJavaValue(value), + value_(value), table_(table) { } @@ -594,36 +582,39 @@ struct CYJavaObject : }; struct CYJavaInterior : - CYJavaValue + CYRoot { + CYJavaGlobal value_; CYJavaClass *table_; CYJavaInterior(const CYJavaRef &value, CYJavaClass *table) : - CYJavaValue(value), + value_(value), table_(table) { } }; struct CYJavaStaticInterior : - CYJavaValue + CYRoot { + CYJavaGlobal value_; CYJavaClass *table_; CYJavaStaticInterior(const CYJavaRef &value, CYJavaClass *table) : - CYJavaValue(value), + value_(value), table_(table) { } }; struct CYJavaArray : - CYJavaValue + CYRoot { + CYJavaGlobal value_; CYJavaPrimitive primitive_; CYJavaArray(const CYJavaRef &value, CYJavaPrimitive primitive) : - CYJavaValue(value), + value_(value), primitive_(primitive) { } @@ -632,7 +623,7 @@ struct CYJavaArray : }; struct CYJavaPackage : - CYPrivate + CYRoot { JNIEnv *jni_; @@ -670,7 +661,7 @@ static JSValueRef CYCastJSValue(JSContextRef context, const CYJavaRef & auto Class$getComponentType(jni.GetMethodID(Class$, "getComponentType", "()Ljava/lang/Class;")); auto component(jni.CallObjectMethod(_class, Class$getComponentType)); auto Class$getName(jni.GetMethodID(Class$, "getName", "()Ljava/lang/String;")); - return CYJavaArray::Make(context, value.cast(), CYJavaGetPrimitive(context, component, Class$getName)); + return CYPrivate::Make(context, value.cast(), CYJavaGetPrimitive(context, component, Class$getName)); } auto Wrapper$(jni.FindClass("Cycript$Wrapper")); @@ -681,7 +672,7 @@ static JSValueRef CYCastJSValue(JSContextRef context, const CYJavaRef & } CYJavaClass *table(reinterpret_cast(JSObjectGetPrivate(CYGetJavaClass(context, _class)))); - return CYJavaObject::Make(context, value, table); + return CYPrivate::Make(context, value, table); } static _finline JSObjectRef CYCastJSObject(JSContextRef context, const CYJavaRef &value) { @@ -713,13 +704,13 @@ CYCastJava$(F, Float, jfloat, CYCastDouble) CYCastJava$(D, Double, jdouble, CYCastDouble) static CYJavaClass *CYGetJavaTable(JSContextRef context, JSObjectRef object) { - if (!JSValueIsObjectOfClass(context, object, CYJavaClass::Class_)) + if (!JSValueIsObjectOfClass(context, object, CYPrivate::Class_)) return NULL; return reinterpret_cast(JSObjectGetPrivate(object)); } static CYJavaObject *CYGetJavaObject(JSContextRef context, JSObjectRef object) { - if (!JSValueIsObjectOfClass(context, object, CYJavaObject::Class_)) + if (!JSValueIsObjectOfClass(context, object, CYPrivate::Class_)) return NULL; return reinterpret_cast(JSObjectGetPrivate(object)); } @@ -817,7 +808,7 @@ static JSObjectRef CYGetJavaClass(JSContextRef context, const CYJavaRef } } - constructor = JSObjectMake(context, CYJavaClass::Class_, table); + constructor = JSObjectMake(context, CYPrivate::Class_, table); prototype = JSObjectMake(context, NULL, NULL); CYSetProperty(context, constructor, prototype_s, prototype, kJSPropertyAttributeDontEnum); @@ -854,9 +845,9 @@ static JSObjectRef CYGetJavaClass(JSContextRef context, const CYJavaRef CYJSString name(entry.first.second); auto &overload(entry.second); if (instance) - CYSetProperty(context, prototype, name, CYJavaMethod::Make(context, overload), kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete); + CYSetProperty(context, prototype, name, CYPrivate::Make(context, overload), kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete); else - CYSetProperty(context, constructor, name, CYJavaStaticMethod::Make(context, overload), kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete); + CYSetProperty(context, constructor, name, CYPrivate::Make(context, overload), kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete); } } @@ -941,7 +932,7 @@ static bool CYCastJavaArguments(const CYJavaFrame &frame, const CYJavaShorty &sh } static JSValueRef JavaMethod_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { - auto internal(CYJavaMethod::Get(context, object)); + auto internal(CYPrivate::Get(context, object)); CYJavaObject *self(CYGetJavaObject(context, _this)); _assert(self != NULL); CYJavaEnv jni(self->value_); @@ -972,7 +963,7 @@ CYJavaForEachPrimitive } CYCatch(NULL) } static JSValueRef JavaStaticMethod_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { - auto internal(CYJavaStaticMethod::Get(context, object)); + auto internal(CYPrivate::Get(context, object)); CYJavaClass *table(CYGetJavaTable(context, _this)); CYJavaEnv jni(table->value_); @@ -1002,7 +993,7 @@ CYJavaForEachPrimitive } CYCatch(NULL) } static JSObjectRef JavaClass_callAsConstructor(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { - auto table(CYJavaClass::Get(context, object)); + auto table(CYPrivate::Get(context, object)); CYJavaEnv jni(table->value_); jclass _class(table->value_); @@ -1027,7 +1018,7 @@ static JSObjectRef JavaClass_callAsConstructor(JSContextRef context, JSObjectRef } CYCatch(NULL) } static bool JavaStaticInterior_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef property) { - auto internal(CYJavaStaticInterior::Get(context, object)); + auto internal(CYPrivate::Get(context, object)); CYJavaClass *table(internal->table_); CYPool pool; auto name(CYPoolUTF8String(pool, context, property)); @@ -1038,7 +1029,7 @@ static bool JavaStaticInterior_hasProperty(JSContextRef context, JSObjectRef obj } static JSValueRef JavaStaticInterior_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { - auto internal(CYJavaStaticInterior::Get(context, object)); + auto internal(CYPrivate::Get(context, object)); CYJavaClass *table(internal->table_); CYJavaEnv jni(table->value_); CYPool pool; @@ -1060,7 +1051,7 @@ CYJavaForEachPrimitive } CYCatch(NULL) } static bool JavaStaticInterior_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYTry { - auto internal(CYJavaStaticInterior::Get(context, object)); + auto internal(CYPrivate::Get(context, object)); CYJavaClass *table(internal->table_); CYJavaEnv jni(table->value_); CYPool pool; @@ -1085,19 +1076,19 @@ CYJavaForEachPrimitive } CYCatch(false) } static void JavaStaticInterior_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef names) { - auto internal(CYJavaStaticInterior::Get(context, object)); + auto internal(CYPrivate::Get(context, object)); CYJavaClass *table(internal->table_); for (const auto &field : table->static_) JSPropertyNameAccumulatorAddName(names, CYJSString(field.first)); } static JSValueRef JavaClass_getProperty_class(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { - auto table(CYJavaClass::Get(context, object)); + auto table(CYPrivate::Get(context, object)); return CYCastJSValue(context, table->value_); } CYCatch(NULL) } static bool JavaInterior_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef property) { - auto internal(CYJavaInterior::Get(context, object)); + auto internal(CYPrivate::Get(context, object)); CYJavaClass *table(internal->table_); CYPool pool; auto name(CYPoolUTF8String(pool, context, property)); @@ -1108,7 +1099,7 @@ static bool JavaInterior_hasProperty(JSContextRef context, JSObjectRef object, J } static JSValueRef JavaInterior_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { - auto internal(CYJavaInterior::Get(context, object)); + auto internal(CYPrivate::Get(context, object)); CYJavaEnv jni(internal->value_); CYJavaClass *table(internal->table_); CYPool pool; @@ -1130,7 +1121,7 @@ CYJavaForEachPrimitive } CYCatch(NULL) } static bool JavaInterior_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYTry { - auto internal(CYJavaInterior::Get(context, object)); + auto internal(CYPrivate::Get(context, object)); CYJavaEnv jni(internal->value_); CYJavaClass *table(internal->table_); CYPool pool; @@ -1155,30 +1146,30 @@ CYJavaForEachPrimitive } CYCatch(false) } static void JavaInterior_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef names) { - auto internal(CYJavaInterior::Get(context, object)); + auto internal(CYPrivate::Get(context, object)); CYJavaClass *table(internal->table_); for (const auto &field : table->instance_) JSPropertyNameAccumulatorAddName(names, CYJSString(field.first)); } static JSValueRef JavaObject_getProperty_constructor(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { - auto internal(CYJavaObject::Get(context, object)); + auto internal(CYPrivate::Get(context, object)); CYJavaEnv jni(internal->value_); return CYGetJavaClass(context, jni.GetObjectClass(internal->value_)); } CYCatch(NULL) } static JSValueRef JavaClass_getProperty_$cyi(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { - auto internal(CYJavaClass::Get(context, object)); - return CYJavaStaticInterior::Make(context, internal->value_, internal); + auto internal(CYPrivate::Get(context, object)); + return CYPrivate::Make(context, internal->value_, internal); } CYCatch(NULL) } static JSValueRef JavaObject_getProperty_$cyi(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { - auto internal(CYJavaObject::Get(context, object)); - return CYJavaInterior::Make(context, internal->value_, internal->table_); + auto internal(CYPrivate::Get(context, object)); + return CYPrivate::Make(context, internal->value_, internal->table_); } CYCatch(NULL) } static JSValueRef JavaClass_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { - auto internal(CYJavaClass::Get(context, _this)); + auto internal(CYPrivate::Get(context, _this)); CYJavaEnv jni(internal->value_); auto Class$(jni.FindClass("java/lang/Class")); auto Class$getCanonicalName(jni.GetMethodID(Class$, "getCanonicalName", "()Ljava/lang/String;")); @@ -1196,7 +1187,7 @@ static JSValueRef JavaStaticMethod_callAsFunction_toCYON(JSContextRef context, J } CYCatch(NULL) } static JSValueRef JavaArray_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { - auto internal(CYJavaArray::Get(context, object)); + auto internal(CYPrivate::Get(context, object)); CYJavaEnv jni(internal->value_); if (JSStringIsEqual(property, length_s)) return CYCastJSValue(context, jni.GetArrayLength(internal->value_)); @@ -1222,7 +1213,7 @@ CYJavaForEachPrimitive } CYCatch(NULL) } static bool JavaArray_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYTry { - auto internal(CYJavaArray::Get(context, object)); + auto internal(CYPrivate::Get(context, object)); CYJavaEnv jni(internal->value_); CYPool pool; @@ -1250,7 +1241,7 @@ CYJavaForEachPrimitive static JNIEnv *GetJNI(JSContextRef context, JNIEnv *&env); static JSValueRef JavaPackage_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { - auto internal(CYJavaPackage::Get(context, _this)); + auto internal(CYPrivate::Get(context, _this)); std::ostringstream name; for (auto &package : internal->package_) name << package << '.'; @@ -1263,7 +1254,7 @@ static bool CYJavaPackage_hasProperty(JSContextRef context, JSObjectRef object, } static JSValueRef CYJavaPackage_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { - auto internal(CYJavaPackage::Get(context, object)); + auto internal(CYPrivate::Get(context, object)); CYJavaPackage::Path package(internal->package_); CYPool pool; @@ -1283,7 +1274,7 @@ static JSValueRef CYJavaPackage_getProperty(JSContextRef context, JSObjectRef ob jni->ExceptionClear(); package.push_back(next); - return CYJavaPackage::Make(context, jni, package); + return CYPrivate::Make(context, jni, package); } CYCatch(NULL) } static void Cycript_delete(JNIEnv *env, jclass api, jlong jprotect) { CYJavaTry { @@ -1539,7 +1530,7 @@ CYJavaForEachPrimitive definition.staticFunctions = JavaClass_staticFunctions; definition.callAsConstructor = &JavaClass_callAsConstructor; definition.finalize = &CYFinalize; - CYJavaClass::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.attributes = kJSClassAttributeNoAutomaticPrototype; @@ -1549,35 +1540,35 @@ CYJavaForEachPrimitive definition.setProperty = &JavaInterior_setProperty; definition.getPropertyNames = &JavaInterior_getPropertyNames; definition.finalize = &CYFinalize; - CYJavaInterior::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.className = "JavaMethod"; definition.staticFunctions = JavaMethod_staticFunctions; definition.callAsFunction = &JavaMethod_callAsFunction; definition.finalize = &CYFinalize; - CYJavaMethod::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.className = "JavaStaticMethod"; definition.staticFunctions = JavaStaticMethod_staticFunctions; definition.callAsFunction = &JavaStaticMethod_callAsFunction; definition.finalize = &CYFinalize; - CYJavaStaticMethod::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.attributes = kJSClassAttributeNoAutomaticPrototype; definition.className = "JavaObject"; definition.staticValues = JavaObject_staticValues; definition.finalize = &CYFinalize; - CYJavaObject::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.className = "JavaArray"; definition.getProperty = &JavaArray_getProperty; definition.setProperty = &JavaArray_setProperty; definition.finalize = &CYFinalize; - CYJavaArray::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.className = "JavaPackage"; @@ -1585,7 +1576,7 @@ CYJavaForEachPrimitive definition.hasProperty = &CYJavaPackage_hasProperty; definition.getProperty = &CYJavaPackage_getProperty; definition.finalize = &CYFinalize; - CYJavaPackage::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.attributes = kJSClassAttributeNoAutomaticPrototype; @@ -1595,7 +1586,7 @@ CYJavaForEachPrimitive definition.setProperty = &JavaStaticInterior_setProperty; definition.getPropertyNames = &JavaStaticInterior_getPropertyNames; definition.finalize = &CYFinalize; - CYJavaStaticInterior::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); } void CYJava_SetupContext(JSContextRef context) { @@ -1609,12 +1600,12 @@ void CYJava_SetupContext(JSContextRef context) { CYSetProperty(context, cycript, CYJSString("Java"), Java); CYSetProperty(context, cy, CYJSString("Java"), Java); - JSObjectRef Packages(CYJavaPackage::Make(context, nullptr, CYJavaPackage::Path())); + JSObjectRef Packages(CYPrivate::Make(context, nullptr, CYJavaPackage::Path())); CYSetProperty(context, all, CYJSString("Packages"), Packages, kJSPropertyAttributeDontEnum); for (auto name : (const char *[]) {"java", "javax", "android", "com", "net", "org"}) { CYJSString js(name); - CYSetProperty(context, all, js, CYJavaPackage::Make(context, nullptr, CYJavaPackage::Path(1, name)), kJSPropertyAttributeDontEnum); + CYSetProperty(context, all, js, CYPrivate::Make(context, nullptr, CYJavaPackage::Path(1, name)), kJSPropertyAttributeDontEnum); } } diff --git a/ObjectiveC/Internal.hpp b/ObjectiveC/Internal.hpp index 356f61b..3a29775 100644 --- a/ObjectiveC/Internal.hpp +++ b/ObjectiveC/Internal.hpp @@ -27,7 +27,7 @@ #include "../Internal.hpp" struct Selector_privateData : - CYPrivate + CYRoot { SEL value_; @@ -38,7 +38,7 @@ struct Selector_privateData : }; struct Instance : - CYPrivate + CYPrivateOld { typedef unsigned Flags; static const Flags None = 0; @@ -66,7 +66,7 @@ struct Instance : namespace cy { struct Super : - CYPrivate + CYRoot { id value_; Class class_; @@ -79,7 +79,7 @@ struct Super : }; } struct Messages : - CYPrivate + CYRoot { Class value_; @@ -92,7 +92,7 @@ struct Messages : }; struct Interior : - CYPrivate + CYRoot { id value_; CYProtect owner_; diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index 6f7c0e6..ca3662b 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -330,7 +330,7 @@ _finline JSValueRef CYGetClassPrototype(JSContextRef context, Class self) { JSValueRef Messages::GetPrototype(JSContextRef context) const { if (Class super = class_getSuperclass(value_)) - return Messages::Make(context, super); + return CYPrivate::Make(context, super); return NULL; } @@ -1471,11 +1471,11 @@ JSValueRef CYCastJSValue(JSContextRef context, NSObject *value) { static JSValueRef CYCastJSValue(JSContextRef context, SEL sel) { if (sel == NULL) return CYJSNull(context); - return Selector_privateData::Make(context, sel); + return CYPrivate::Make(context, sel); } static SEL CYCastSEL(JSContextRef context, JSValueRef value) { - if (JSValueIsObjectOfClass(context, value, Selector_privateData::Class_)) { + if (JSValueIsObjectOfClass(context, value, CYPrivate::Class_)) { Selector_privateData *internal(reinterpret_cast(JSObjectGetPrivate((JSObjectRef) value))); return reinterpret_cast(internal->value_); } else { @@ -1776,7 +1776,7 @@ static JSValueRef Instance_getProperty(JSContextRef context, JSObjectRef object, id self(internal->value_); if (JSStringIsEqualToUTF8CString(property, "$cyi")) - return Interior::Make(context, self, context, object); + return CYPrivate::Make(context, self, context, object); CYPool pool; NSString *name(CYCastNSString(&pool, context, property)); @@ -2462,7 +2462,7 @@ static JSValueRef $objc_msgSend(JSContextRef context, JSObjectRef object, JSObje SEL _cmd; Class _class; - if (JSValueIsObjectOfClass(context, arguments[0], cy::Super::Class_)) { + if (JSValueIsObjectOfClass(context, arguments[0], CYPrivate::Class_)) { cy::Super *internal(reinterpret_cast(JSObjectGetPrivate((JSObjectRef) arguments[0]))); self = internal->value_; _class = internal->class_;; @@ -2520,7 +2520,7 @@ static JSObjectRef Super_new(JSContextRef context, JSObjectRef object, size_t co CYPool pool; id self(CYCastNSObject(&pool, context, arguments[0])); Class _class(CYCastClass(pool, context, arguments[1])); - return cy::Super::Make(context, self, _class); + return CYPrivate::Make(context, self, _class); } CYCatch(NULL) } static JSObjectRef Selector_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { @@ -2528,7 +2528,7 @@ static JSObjectRef Selector_new(JSContextRef context, JSObjectRef object, size_t throw CYJSError(context, "incorrect number of arguments to Selector constructor"); CYPool pool; const char *name(CYPoolCString(pool, context, arguments[0])); - return Selector_privateData::Make(context, sel_registerName(name)); + return CYPrivate::Make(context, sel_registerName(name)); } CYCatch(NULL) } static JSObjectRef Instance_new(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { @@ -2576,7 +2576,7 @@ static JSValueRef Instance_getProperty_messages(JSContextRef context, JSObjectRe id self(internal->value_); if (!CYIsClass(self)) return CYJSUndefined(context); - return Messages::Make(context, (Class) self); + return CYPrivate::Make(context, (Class) self); } CYCatch(NULL) } static JSValueRef Instance_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { @@ -2830,7 +2830,7 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry { definition.setProperty = &Interior_setProperty; definition.getPropertyNames = &Interior_getPropertyNames; definition.finalize = &CYFinalize; - Interior::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.className = "Message"; @@ -2847,7 +2847,7 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry { definition.setProperty = &Messages_setProperty; definition.getPropertyNames = &Messages_getPropertyNames; definition.finalize = &CYFinalize; - Messages::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.className = "Selector"; @@ -2855,12 +2855,12 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry { definition.staticFunctions = Selector_staticFunctions; definition.callAsFunction = &Selector_callAsFunction; definition.finalize = &CYFinalize; - Selector_privateData::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.className = "Super"; definition.finalize = &CYFinalize; - cy::Super::Class_ = JSClassCreate(&definition); + CYPrivate::Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; definition.className = "ObjectiveC::Classes"; @@ -2934,8 +2934,8 @@ void CYObjectiveC_SetupContext(JSContextRef context) { CYPoolTry { #endif JSObjectRef Message(JSObjectMakeConstructor(context, Message_privateData::Class_, NULL)); - JSObjectRef Selector(JSObjectMakeConstructor(context, Selector_privateData::Class_, &Selector_new)); - JSObjectRef Super(JSObjectMakeConstructor(context, cy::Super::Class_, &Super_new)); + JSObjectRef Selector(JSObjectMakeConstructor(context, CYPrivate::Class_, &Selector_new)); + JSObjectRef Super(JSObjectMakeConstructor(context, CYPrivate::Class_, &Super_new)); JSObjectRef Instance(JSObjectMakeConstructor(context, Instance::Class_, &Instance_new)); JSObjectRef Instance_prototype(CYCastJSObject(context, CYGetProperty(context, Instance, prototype_s)));