From 5f7a1d380823e5188490c2fd41009f90d59e6fee Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 30 Dec 2015 20:00:25 -0800 Subject: [PATCH] Remove old features of CYValue that are bad ideas. --- Execute.cpp | 25 ++++++------------------- Internal.hpp | 33 ++++++++++----------------------- ObjectiveC/Library.mm | 28 +--------------------------- 3 files changed, 17 insertions(+), 69 deletions(-) diff --git a/Execute.cpp b/Execute.cpp index dfc0158..e2d2d80 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -868,7 +868,7 @@ JSValueRef Function::FromFFI(JSContextRef context, ffi_type *ffi, void *data, bo void CYExecuteClosure(ffi_cif *cif, void *result, void **arguments, void *arg) { Closure_privateData *internal(reinterpret_cast(arg)); - JSContextRef context(internal->context_); + JSContextRef context(internal->function_); size_t count(internal->cif_.nargs); JSValueRef values[count]; @@ -1617,10 +1617,6 @@ static JSValueRef CYValue_callAsFunction_valueOf(JSContextRef context, JSObjectR return CYCastJSValue(context, reinterpret_cast(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 CYValue_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { CYValue *internal(reinterpret_cast(JSObjectGetPrivate(_this))); std::ostringstream str; @@ -1748,17 +1744,12 @@ static JSValueRef Type_callAsFunction_toCYON(JSContextRef context, JSObjectRef o 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}, {NULL, NULL, 0} @@ -1769,9 +1760,8 @@ static JSStaticValue CArray_staticValues[2] = { {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}, @@ -1784,9 +1774,8 @@ static JSStaticValue CString_staticValues[3] = { {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}, {NULL, NULL, 0} @@ -1807,10 +1796,9 @@ static JSStaticValue Struct_staticValues[2] = { {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}, {NULL, NULL, 0} }; @@ -1835,7 +1823,7 @@ static JSStaticValue Type_staticValues[4] = { {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}, @@ -1843,7 +1831,6 @@ static JSStaticFunction Type_staticFunctions[10] = { {"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} }; diff --git a/Internal.hpp b/Internal.hpp index 9819b53..0d6ae78 100644 --- a/Internal.hpp +++ b/Internal.hpp @@ -106,10 +106,6 @@ struct CYValue : value_(rhs.value_) { } - - virtual Type_privateData *GetType() const { - return NULL; - } }; template @@ -117,7 +113,6 @@ struct CYValue_ : CYValue { static JSClassRef Class_; - static Type_privateData *Type_; using CYValue::CYValue; @@ -125,10 +120,6 @@ struct CYValue_ : return reinterpret_cast(value_); } - virtual Type_privateData *GetType() const { - return Type_; - } - _finline JSValueRef GetPrototype(JSContextRef context) const { return NULL; } @@ -151,9 +142,6 @@ struct CYValue_ : template JSClassRef CYValue_::Class_; -template -Type_privateData *CYValue_::Type_; - struct CYProtect { private: JSGlobalContextRef context_; @@ -175,6 +163,14 @@ struct CYProtect { //XXX:JSGlobalContextRelease(context_); } + operator bool() const { + return object_ != NULL; + } + + operator JSContextRef() const { + return context_; + } + operator JSObjectRef() const { return object_; } @@ -221,23 +217,14 @@ struct Functor : struct Closure_privateData : cy::Functor { - JSGlobalContextRef context_; - JSObjectRef function_; + CYProtect function_; JSValueRef (*adapter_)(JSContextRef, size_t, JSValueRef[], JSObjectRef); Closure_privateData(JSContextRef context, JSObjectRef function, JSValueRef (*adapter)(JSContextRef, size_t, JSValueRef[], JSObjectRef), const sig::Signature &signature) : cy::Functor(NULL, false, signature), - context_(CYGetJSContext(context)), - function_(function), + function_(context, function), adapter_(adapter) { - //XXX:JSGlobalContextRetain(context_); - JSValueProtect(context_, function_); - } - - virtual ~Closure_privateData() { - JSValueUnprotect(context_, function_); - //XXX:JSGlobalContextRelease(context_); } }; diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index 01f9240..49dede4 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -2498,26 +2498,6 @@ static JSValueRef CYValue_getProperty_value(JSContextRef context, JSObjectRef ob return CYCastJSValue(context, reinterpret_cast(internal->value_)); } CYCatch(NULL) } -static JSValueRef CYValue_callAsFunction_$cya(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { - CYValue *internal(reinterpret_cast(JSObjectGetPrivate(_this))); - Type_privateData *typical(internal->GetType()); - - sig::Void XXX; - - sig::Type *type; - ffi_type *ffi; - - if (typical == NULL) { - type = &XXX; - ffi = NULL; - } else { - type = typical->type_; - ffi = typical->ffi_; - } - - return CYMakePointer(context, &internal->value_, *type, ffi, object); -} CYCatch(NULL) } - static JSValueRef Selector_getProperty_$cyt(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { return CYMakeType(context, sig::Selector()); } CYCatch(NULL) } @@ -2708,8 +2688,7 @@ static JSStaticValue FunctionInstance_staticValues[6] = { {NULL, NULL, NULL, 0} }; -static JSStaticFunction Instance_staticFunctions[7] = { - {"$cya", &CYValue_callAsFunction_$cya, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, +static JSStaticFunction Instance_staticFunctions[6] = { {"toCYON", &Instance_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"toJSON", &Instance_callAsFunction_toJSON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"valueOf", &Instance_callAsFunction_valueOf, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, @@ -2743,11 +2722,6 @@ JSValueRef NSCFType$cy$toJSON$inContext$(id self, SEL sel, JSValueRef key, JSCon #endif void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry { - CYPool &pool(CYGetGlobalPool()); - - Instance::Type_ = new(pool) Type_privateData(sig::Object()); - Selector_privateData::Type_ = new(pool) Type_privateData(sig::Selector()); - NSArray_ = objc_getClass("NSArray"); NSBlock_ = objc_getClass("NSBlock"); NSDictionary_ = objc_getClass("NSDictionary"); -- 2.47.2