]> git.saurik.com Git - cycript.git/commitdiff
Remove old features of CYValue that are bad ideas.
authorJay Freeman (saurik) <saurik@saurik.com>
Thu, 31 Dec 2015 04:00:25 +0000 (20:00 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Thu, 31 Dec 2015 04:00:25 +0000 (20:00 -0800)
Execute.cpp
Internal.hpp
ObjectiveC/Library.mm

index dfc015835c958979b4586bc5e843d9b116a6a5aa..e2d2d8086d5fd463bea3e91fa7937244b9f444ff 100644 (file)
@@ -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<Closure_privateData *>(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<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 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)));
     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}
 };
index 9819b53352ef6e9b165e014dd1488bff8600163a..0d6ae78c72d1664d19a5258339de584129ce5612 100644 (file)
@@ -106,10 +106,6 @@ struct CYValue :
         value_(rhs.value_)
     {
     }
-
-    virtual Type_privateData *GetType() const {
-        return NULL;
-    }
 };
 
 template <typename Internal_, typename Value_>
@@ -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_>(value_);
     }
 
-    virtual Type_privateData *GetType() const {
-        return Type_;
-    }
-
     _finline JSValueRef GetPrototype(JSContextRef context) const {
         return NULL;
     }
@@ -151,9 +142,6 @@ struct CYValue_ :
 template <typename Internal_, typename Value_>
 JSClassRef CYValue_<Internal_, Value_>::Class_;
 
-template <typename Internal_, typename Value_>
-Type_privateData *CYValue_<Internal_, Value_>::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_);
     }
 };
 
index 01f924092667f5a87dfd56c90674ac432811908f..49dede4e1eea42518d9601c964221750d6c3aa9f 100644 (file)
@@ -2498,26 +2498,6 @@ static JSValueRef CYValue_getProperty_value(JSContextRef context, JSObjectRef ob
     return CYCastJSValue(context, reinterpret_cast<uintptr_t>(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<CYValue *>(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");