Smaller cleanups in qv8engine
authorLars Knoll <lars.knoll@digia.com>
Thu, 16 May 2013 07:31:28 +0000 (09:31 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Fri, 17 May 2013 22:02:53 +0000 (00:02 +0200)
Change-Id: I5cc7150c37312db78ce0985fe546646a9df61258
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/qml/v8/qv8engine.cpp
src/qml/qml/v8/qv8engine_p.h

index 664403a..fcd3087 100644 (file)
@@ -1193,25 +1193,25 @@ bool QV8Engine::metaTypeFromJS(const QV4::Value &value, int type, void *data) {
     QByteArray name = QMetaType::typeName(type);
     if (convertToNativeQObject(value, name, reinterpret_cast<void* *>(data)))
         return true;
-    if (isVariant(value) && name.endsWith('*')) {
+    if (value.asVariantObject() && name.endsWith('*')) {
         int valueType = QMetaType::type(name.left(name.size()-1));
         QVariant &var = value.asVariantObject()->data;
         if (valueType == var.userType()) {
             // We have T t, T* is requested, so return &t.
             *reinterpret_cast<void* *>(data) = var.data();
             return true;
-        } else {
+        } else if (QV4::Object *o = value.asObject()) {
             // Look in the prototype chain.
-            v8::Handle<v8::Value> proto = v8::Value::fromV4Value(value)->ToObject()->GetPrototype();
-            while (proto->IsObject()) {
+            QV4::Object *proto = o->prototype;
+            while (proto) {
                 bool canCast = false;
-                if (isVariant(proto->v4Value())) {
-                    const QVariant &v = proto->v4Value().asVariantObject()->data;
+                if (QV4::VariantObject *vo = proto->asVariantObject()) {
+                    const QVariant &v = vo->data;
                     canCast = (type == v.userType()) || (valueType && (valueType == v.userType()));
                 }
-                else if (isQObject(proto->v4Value())) {
+                else if (isQObject(QV4::Value::fromObject(proto))) {
                     QByteArray className = name.left(name.size()-1);
-                    if (QObject *qobject = qtObjectFromJS(proto->v4Value()))
+                    if (QObject *qobject = qtObjectFromJS(QV4::Value::fromObject(proto)))
                         canCast = qobject->qt_metacast(className) != 0;
                 }
                 if (canCast) {
@@ -1222,7 +1222,7 @@ bool QV8Engine::metaTypeFromJS(const QV4::Value &value, int type, void *data) {
                         *reinterpret_cast<void* *>(data) = var.data();
                     return true;
                 }
-                proto = proto->ToObject()->GetPrototype();
+                proto = proto->prototype;
             }
         }
     } else if (value.isNull() && name.endsWith('*')) {
@@ -1275,8 +1275,8 @@ QVariant QV8Engine::variantFromJS(const QV4::Value &value,
         return d->toQDateTime();
     if (QV4::RegExpObject *re = value.asRegExpObject())
         return re->toQRegExp();
-    if (isVariant(value))
-        return value.asVariantObject()->data;
+    if (QV4::VariantObject *v = value.asVariantObject())
+        return v->data;
     if (isQObject(value))
         return qVariantFromValue(qtObjectFromJS(value));
     if (isValueType(value))
index b957982..65640ee 100644 (file)
@@ -294,7 +294,6 @@ public:
 
     QVariant toVariant(const QV4::Value &value, int typeHint);
     QV4::Value fromVariant(const QVariant &);
-    inline bool isVariant(const QV4::Value &);
 
     // Compile \a source (from \a fileName at \a lineNumber) in QML mode
     v8::Handle<v8::Script> qmlModeCompile(const QString &source,
@@ -461,12 +460,6 @@ private:
     Q_DISABLE_COPY(QV8Engine)
 };
 
-bool QV8Engine::isVariant(const QV4::Value &value)
-{
-    QV4::Managed *m = value.asManaged();
-    return m ? m->asVariantObject() : 0;
-}
-
 v8::Handle<v8::Object> QV8Engine::qmlScope(QQmlContextData *ctxt, QObject *scope)
 {
     return m_contextWrapper.qmlScope(ctxt, scope);