]> git.saurik.com Git - cycript.git/blobdiff - Execute.cpp
Avoid guessing when converting Functor to Pointer.
[cycript.git] / Execute.cpp
index 6ded65e32622673f0850d4dc97635326bbee321c..81bd6ec35885585941bd86711163ff46db769725 100644 (file)
@@ -217,6 +217,8 @@ static JSStringRef Result_;
 
 void CYFinalize(JSObjectRef object) {
     CYData *internal(reinterpret_cast<CYData *>(JSObjectGetPrivate(object)));
+    if (internal == NULL)
+        return;
     _assert(internal->count_ != _not(unsigned));
     if (--internal->count_ == 0)
         delete internal;
@@ -750,12 +752,13 @@ void Primitive<char>::PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi,
         CYJSString script(context, value);
         auto string(CYCastUTF16String(script));
         _assert(string.size == 1);
+        _assert((string.data[0] & 0xff) == string.data[0]);
         *reinterpret_cast<char *>(data) = string.data[0];
     }
 }
 
 void Void::PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const {
-    _assert(false);
+    _assert(JSValueIsUndefined(context, value));
 }
 
 void Unknown::PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const {
@@ -955,8 +958,7 @@ void CYExecuteClosure(ffi_cif *cif, void *result, void **arguments, void *arg) {
         values[index] = internal->signature_.elements[1 + index].type->FromFFI(context, internal->cif_.arg_types[index], arguments[index]);
 
     JSValueRef value(internal->adapter_(context, count, values, internal->function_));
-    if (internal->cif_.rtype != &ffi_type_void)
-        internal->signature_.elements[0].type->PoolFFI(NULL, context, internal->cif_.rtype, result, value);
+    internal->signature_.elements[0].type->PoolFFI(NULL, context, internal->cif_.rtype, result, value);
 }
 
 static JSValueRef FunctionAdapter_(JSContextRef context, size_t count, JSValueRef values[], JSObjectRef function) {
@@ -1678,7 +1680,7 @@ static JSValueRef Type_callAsFunction_pointerTo(JSContextRef context, JSObjectRe
     Type_privateData *internal(reinterpret_cast<Type_privateData *>(JSObjectGetPrivate(_this)));
 
     if (dynamic_cast<sig::Primitive<char> *>(internal->type_) != NULL)
-        return CYMakeType(context, sig::String());
+        return CYMakeType(context, sig::String((internal->type_->flags & JOC_TYPE_CONST) != 0));
     else
         return CYMakeType(context, sig::Pointer(*internal->type_));
 } CYCatch(NULL) }
@@ -1860,7 +1862,7 @@ static JSValueRef CString_getProperty_length(JSContextRef context, JSObjectRef o
 } CYCatch(NULL) }
 
 static JSValueRef CString_getProperty_$cyt(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
-    return CYMakeType(context, sig::String());
+    return CYMakeType(context, sig::String(true));
 } CYCatch(NULL) }
 
 static JSValueRef CArray_getProperty_$cyt(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
@@ -1987,9 +1989,10 @@ static JSStaticValue Struct_staticValues[2] = {
     {NULL, NULL, NULL, 0}
 };
 
-static JSStaticFunction Functor_staticFunctions[4] = {
+static JSStaticFunction Functor_staticFunctions[5] = {
     {"$cya", &Functor_callAsFunction_$cya, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {"toCYON", &Functor_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+    {"toPointer", &Functor_callAsFunction_$cya, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {"valueOf", &Functor_callAsFunction_valueOf, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {NULL, NULL, 0}
 };
@@ -2545,7 +2548,7 @@ extern "C" void CYSetupContext(JSGlobalContextRef context) {
     }
 #endif
 
-    CYSetProperty(context, String_prototype, cyt_s, CYMakeType(context, sig::String()), kJSPropertyAttributeDontEnum);
+    CYSetProperty(context, String_prototype, cyt_s, CYMakeType(context, sig::String(true)), kJSPropertyAttributeDontEnum);
 
     CYSetProperty(context, cache, CYJSString("dlerror"), CYMakeFunctor(context, "dlerror", "*"), kJSPropertyAttributeDontEnum);
     CYSetProperty(context, cache, CYJSString("RTLD_DEFAULT"), CYCastJSValue(context, reinterpret_cast<intptr_t>(RTLD_DEFAULT)), kJSPropertyAttributeDontEnum);