]> git.saurik.com Git - cycript.git/blobdiff - Execute.cpp
Move number's typeid set to FromFFI from Type_new.
[cycript.git] / Execute.cpp
index 48dc4780d8924538f8ac01af90bef4ac5647a57b..c19dc76cafb49e9d2b59e15ad7ad1407a0c5123b 100644 (file)
@@ -181,11 +181,12 @@ static JSObjectRef (*JSObjectMakeArray$)(JSContextRef, size_t, const JSValueRef[
 JSObjectRef CYObjectMakeArray(JSContextRef context, size_t length, const JSValueRef values[]) {
     if (JSObjectMakeArray$ != NULL)
         return _jsccall(*JSObjectMakeArray$, context, length, values);
-    else {
-        JSObjectRef Array(CYGetCachedObject(context, CYJSString("Array")));
-        JSValueRef value(CYCallAsFunction(context, Array, NULL, length, values));
-        return CYCastJSObject(context, value);
-    }
+    JSObjectRef Array(CYGetCachedObject(context, CYJSString("Array")));
+    bool wat(length == 1 && JSValueGetType(context, values[0]) == kJSTypeNumber);
+    JSValueRef value(CYCallAsFunction(context, Array, NULL, wat ? 0 : length, values));
+    JSObjectRef object(CYCastJSObject(context, value));
+    if (wat) CYArrayPush(context, object, 1, values);
+    return object;
 }
 
 static JSClassRef All_;
@@ -853,10 +854,12 @@ void Function::PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *
 #define CYFromFFI_(Type_) \
 template <> \
 JSValueRef Primitive<Type_>::FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const { \
-    return CYCastJSValue(context, *reinterpret_cast<Type_ *>(data)); \
+    JSValueRef value(CYCastJSValue(context, *reinterpret_cast<Type_ *>(data))); \
+    JSObjectRef typed(_jsccall(JSObjectCallAsConstructor, context, CYGetCachedObject(context, CYJSString("Number")), 1, &value)); \
+    CYSetProperty(context, typed, cyt_s, CYMakeType(context, *this), kJSPropertyAttributeDontEnum); \
+    return typed; \
 }
 
-CYFromFFI_(bool)
 CYFromFFI_(wchar_t)
 CYFromFFI_(float)
 CYFromFFI_(double)
@@ -879,6 +882,11 @@ CYFromFFI_(signed __int128)
 CYFromFFI_(unsigned __int128)
 #endif
 
+template <>
+JSValueRef Primitive<bool>::FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const {
+    return CYCastJSValue(context, *reinterpret_cast<bool *>(data));
+}
+
 template <>
 JSValueRef Primitive<char>::FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const {
     uint16_t string(uint8_t(*reinterpret_cast<char *>(data)));
@@ -1705,13 +1713,6 @@ static JSValueRef Type_callAsFunction(JSContextRef context, JSObjectRef object,
 
     type->PoolFFI(buffer, context, ffi, data, arguments[0]);
     JSValueRef value(type->FromFFI(context, ffi, data, false, buffer));
-
-    if (JSValueGetType(context, value) == kJSTypeNumber) {
-        JSObjectRef typed(_jsccall(JSObjectCallAsConstructor, context, CYGetCachedObject(context, CYJSString("Number")), 1, &value));
-        CYSetProperty(context, typed, cyt_s, object, kJSPropertyAttributeDontEnum);
-        value = typed;
-    }
-
     return value;
 } CYCatch(NULL) }