Remove two more places where we used v8
authorLars Knoll <lars.knoll@digia.com>
Mon, 10 Jun 2013 13:10:02 +0000 (15:10 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Mon, 10 Jun 2013 13:45:29 +0000 (15:45 +0200)
Change Value::isInt32() to convert to an integer if possible.
Use this to avoid casting doubles to ints twice. usage of
v8::Value::IsInt32() in two places.

Change-Id: I5b9d8be7d90b461c11440bf54660ceef7e8f0f1b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/qml/v4/qv4value_p.h
src/qml/qml/v4/qv4variantobject.cpp
src/quick/items/qquickdrag.cpp
src/quick/items/qquickdroparea.cpp

index 207ee22..cc27954 100644 (file)
@@ -151,11 +151,17 @@ struct Q_QML_EXPORT Value
     inline bool isObject() const { return tag == Object_Type; }
 #endif
     inline bool isConvertibleToInt() const { return (tag & ConvertibleToInt) == ConvertibleToInt; }
-    inline bool isInt32() const {
+    inline bool isInt32() {
         if (tag == _Integer_Type)
             return true;
-        if (isDouble() && (int)dbl == dbl)
-            return true;
+        if (isDouble()) {
+            int i = (int)dbl;
+            if (i == dbl) {
+                int_32 = i;
+                tag = _Integer_Type;
+                return true;
+            }
+        }
         return false;
     }
 
index ddd6002..733f289 100644 (file)
@@ -72,8 +72,9 @@ QVariant VariantObject::toVariant(const QV4::Value &v)
     if (v.isBoolean())
         return QVariant(v.booleanValue());
     if (v.isNumber()) {
-        if (v.isInt32())
-            return QVariant(v.toInt32());
+        QV4::Value val = v;
+        if (val.isInt32())
+            return QVariant(val.integerValue());
         return QVariant(v.asDouble());
     }
     if (v.isNull())
index 14bd4b5..55b3e56 100644 (file)
@@ -517,9 +517,9 @@ void QQuickDragAttached::start(QQmlV4Function *args)
     Qt::DropActions supportedActions = d->supportedActions;
     // check arguments for supportedActions, maybe data?
     if (args->length() >= 1) {
-        v8::Handle<v8::Value> v = (*args)[0];
-        if (v->IsInt32()) {
-            supportedActions = Qt::DropActions(v->Int32Value());
+        QV4::Value v = (*args)[0];
+        if (v.isInt32()) {
+            supportedActions = Qt::DropActions(v.integerValue());
             d->overrideActions = true;
         }
     }
index 3b8f02d..f930835 100644 (file)
@@ -421,9 +421,9 @@ void QQuickDropEvent::accept(QQmlV4Function *args)
     Qt::DropAction action = event->dropAction();
 
     if (args->length() >= 1) {
-        v8::Handle<v8::Value> v = (*args)[0];
-        if (v->IsInt32())
-            action = Qt::DropAction(v->Int32Value());
+        QV4::Value v = (*args)[0];
+        if (v.isInt32())
+            action = Qt::DropAction(v.integerValue());
     }
     // get action from arguments.
     event->setDropAction(action);