Remove v8 dependencies from QQmlV4Handle
authorLars Knoll <lars.knoll@digia.com>
Wed, 8 May 2013 13:56:03 +0000 (15:56 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Wed, 8 May 2013 17:55:58 +0000 (19:55 +0200)
Change-Id: I87d2183738ec7cfeea846a28f2b9aed79a233f68
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
19 files changed:
src/imports/testlib/main.cpp
src/imports/xmllistmodel/qqmlxmllistmodel.cpp
src/particles/qquickcustomaffector.cpp
src/particles/qquickparticleemitter.cpp
src/particles/qquickparticlesystem.cpp
src/particles/qquickparticlesystem_p.h
src/particles/qquicktrailemitter.cpp
src/particles/qquickv8particledata.cpp
src/qml/qml/qqmlboundsignal.cpp
src/qml/qml/v8/qqmlbuiltinfunctions.cpp
src/qml/qml/v8/qv8engine.cpp
src/qml/qml/v8/qv8engine_p.h
src/qml/qml/v8/qv8qobjectwrapper.cpp
src/qml/qml/v8/qv8valuetypewrapper.cpp
src/qml/types/qqmldelegatemodel.cpp
src/qml/types/qqmllistmodel.cpp
src/qml/types/qquickworkerscript.cpp
src/quick/items/context2d/qquickcanvasitem.cpp
src/quick/util/qquickglobal.cpp

index bd13056..d854a26 100644 (file)
@@ -97,7 +97,7 @@ public Q_SLOTS:
             }
         }
 
-        return QQmlV4Handle::fromV8Handle(v8::String::New(name.toUtf8()));
+        return QQmlV4Handle(v8::String::New(name.toUtf8())->v4Value());
     }
 
     bool compare(const QVariant& act, const QVariant& exp) const {
@@ -110,7 +110,7 @@ public Q_SLOTS:
         int count = stacks->GetFrameCount();
         if (count >= frameIndex + 1) {
             v8::Handle<v8::StackFrame> frame = stacks->GetFrame(frameIndex + 1);
-            return QQmlV4Handle::fromV8Handle(frame->GetScriptNameOrSourceURL());
+            return QQmlV4Handle(frame->GetScriptNameOrSourceURL()->v4Value());
         }
         return QQmlV4Handle();
     }
index 77c04be..e814eda 100644 (file)
@@ -919,7 +919,7 @@ QQmlV4Handle QQuickXmlListModel::get(int index) const
     Q_D(const QQuickXmlListModel);
 
     if (index < 0 || index >= count())
-        return QQmlV4Handle::fromValue(Value::undefinedValue());
+        return QQmlV4Handle(Value::undefinedValue());
 
     QQmlEngine *engine = qmlContext(this)->engine();
     QV8Engine *v8engine = QQmlEnginePrivate::getV8Engine(engine);
@@ -930,7 +930,7 @@ QQmlV4Handle QQuickXmlListModel::get(int index) const
         p->value = v8engine->fromVariant(d->data.value(ii).value(index));
     }
 
-    return QQmlV4Handle::fromValue(Value::fromObject(o));
+    return QQmlV4Handle(Value::fromObject(o));
 }
 
 /*!
index 9c46510..37db984 100644 (file)
@@ -145,11 +145,11 @@ void QQuickCustomAffector::affectSystem(qreal dt)
 
     v8::Handle<v8::Array> array = v8::Array::New(toAffect.size());
     for (int i=0; i<toAffect.size(); i++)
-        array->Set(i, toAffect[i]->v8Value().toV8Handle());
+        array->Set(i, toAffect[i]->v4Value().toValue());
 
     if (dt >= simulationCutoff || dt <= simulationDelta) {
         affectProperties(toAffect, dt);
-        emit affectParticles(QQmlV4Handle::fromV8Handle(array), dt);
+        emit affectParticles(QQmlV4Handle(array->v4Value()), dt);
     } else {
         int realTime = m_system->timeInt;
         m_system->timeInt -= dt * 1000.0;
@@ -157,12 +157,12 @@ void QQuickCustomAffector::affectSystem(qreal dt)
             m_system->timeInt += simulationDelta * 1000.0;
             dt -= simulationDelta;
             affectProperties(toAffect, simulationDelta);
-            emit affectParticles(QQmlV4Handle::fromV8Handle(array), simulationDelta);
+            emit affectParticles(QQmlV4Handle(array->v4Value()), simulationDelta);
         }
         m_system->timeInt = realTime;
         if (dt > 0.0) {
             affectProperties(toAffect, dt);
-            emit affectParticles(QQmlV4Handle::fromV8Handle(array), dt);
+            emit affectParticles(QQmlV4Handle(array->v4Value()), dt);
         }
     }
 
index d3a7adb..630565f 100644 (file)
@@ -481,9 +481,9 @@ void QQuickParticleEmitter::emitWindow(int timeStamp)
         //We then don't need to request another reload, because the first reload isn't scheduled until we get back to the render thread
         v8::Handle<v8::Array> array = v8::Array::New(toEmit.size());
         for (int i=0; i<toEmit.size(); i++)
-            array->Set(i, toEmit[i]->v8Value().toV8Handle());
+            array->Set(i, toEmit[i]->v4Value().toValue());
 
-        emitParticles(QQmlV4Handle::fromV8Handle(array));//A chance for arbitrary JS changes
+        emitParticles(QQmlV4Handle(array->v4Value()));//A chance for arbitrary JS changes
     }
 
     m_last_emission = pt;
index ce67fec..4776199 100644 (file)
@@ -527,7 +527,7 @@ void QQuickParticleData::clone(const QQuickParticleData& other)
     animationOwner = other.animationOwner;
 }
 
-QQmlV4Handle QQuickParticleData::v8Value()
+QQmlV4Handle QQuickParticleData::v4Value()
 {
     if (!v8Datum)
         v8Datum = new QQuickV8ParticleData(QQmlEnginePrivate::getV8Engine(qmlEngine(system)), this);
index 3b58fd1..1eb26a2 100644 (file)
@@ -228,7 +228,7 @@ public:
     float lifeLeft();
     float curSize();
     void clone(const QQuickParticleData& other);//Not =, leaves meta-data like index
-    QQmlV4Handle v8Value();
+    QQmlV4Handle v4Value();
     void extendLife(float time);
 private:
     QQuickV8ParticleData* v8Datum;
index c0e65e5..85cc23c 100644 (file)
@@ -271,12 +271,12 @@ void QQuickTrailEmitter::emitWindow(int timeStamp)
         if (isEmitConnected() || isEmitFollowConnected()) {
             v8::Handle<v8::Array> array = v8::Array::New(toEmit.size());
             for (int i=0; i<toEmit.size(); i++)
-                array->Set(i, toEmit[i]->v8Value().toV8Handle());
+                array->Set(i, toEmit[i]->v4Value().toValue());
 
             if (isEmitFollowConnected())
-                emitFollowParticles(QQmlV4Handle::fromV8Handle(array), d->v8Value());//A chance for many arbitrary JS changes
+                emitFollowParticles(QQmlV4Handle(array->v4Value()), d->v4Value());//A chance for many arbitrary JS changes
             else if (isEmitConnected())
-                emitParticles(QQmlV4Handle::fromV8Handle(array));//A chance for arbitrary JS changes
+                emitParticles(QQmlV4Handle(array->v4Value()));//A chance for arbitrary JS changes
         }
         m_lastEmission[d->index] = pt;
     }
index 9b8d1ad..8a73e4b 100644 (file)
@@ -496,7 +496,7 @@ QQuickV8ParticleData::~QQuickV8ParticleData()
 
 QQmlV4Handle QQuickV8ParticleData::v4Value()
 {
-    return QQmlV4Handle::fromValue(m_v4Value);
+    return QQmlV4Handle(m_v4Value);
 }
 
 QT_END_NAMESPACE
index acb7903..44c1c52 100644 (file)
@@ -238,7 +238,7 @@ void QQmlBoundSignalExpression::evaluate(void **a)
                     //### optimization. Can go away if we switch to metaTypeToJS, or be expanded otherwise
                     args[ii] = v8::Integer::New(*reinterpret_cast<const int*>(a[ii + 1]));
                 } else if (type == qMetaTypeId<QQmlV4Handle>()) {
-                    args[ii] = reinterpret_cast<QQmlV4Handle *>(a[ii + 1])->toV8Handle();
+                    args[ii] = reinterpret_cast<QQmlV4Handle *>(a[ii + 1])->toValue();
                 } else if (ep->isQObject(type)) {
                     if (!*reinterpret_cast<void* const *>(a[ii + 1]))
                         args[ii] = QV4::Value::nullValue();
index a967407..4e8fad3 100644 (file)
@@ -632,7 +632,7 @@ QV4::Value font(const v8::Arguments &args)
 
     v8::Handle<v8::Object> obj = args[0]->ToObject();
     bool ok = false;
-    QVariant v = QQml_valueTypeProvider()->createVariantFromJsObject(QMetaType::QFont, QQmlV4Handle::fromV8Handle(obj), V8ENGINE(), &ok);
+    QVariant v = QQml_valueTypeProvider()->createVariantFromJsObject(QMetaType::QFont, QQmlV4Handle(obj->v4Value()), V8ENGINE(), &ok);
     if (!ok)
         V4THROW_ERROR("Qt.font(): Invalid argument: no valid font subproperties specified");
     return V8ENGINE()->fromVariant(v);
@@ -650,7 +650,7 @@ QV4::Value matrix4x4(const v8::Arguments &args)
     if (args.Length() == 1 && args[0]->IsObject()) {
         v8::Handle<v8::Object> obj = args[0]->ToObject();
         bool ok = false;
-        QVariant v = QQml_valueTypeProvider()->createVariantFromJsObject(QMetaType::QMatrix4x4, QQmlV4Handle::fromV8Handle(obj), V8ENGINE(), &ok);
+        QVariant v = QQml_valueTypeProvider()->createVariantFromJsObject(QMetaType::QMatrix4x4, QQmlV4Handle(obj->v4Value()), V8ENGINE(), &ok);
         if (!ok)
             V4THROW_ERROR("Qt.matrix4x4(): Invalid argument: not a valid matrix4x4 values array");
         return V8ENGINE()->fromVariant(v);
index 650d982..7d1bdb7 100644 (file)
@@ -1480,20 +1480,6 @@ QV4::Value QV8Engine::toString(const QString &string)
 }
 
 
-QV4::Value QQmlV4Handle::toValue() const
-{
-    QV4::Value val;
-    val.val = d;
-    return val;
-}
-
-QQmlV4Handle QQmlV4Handle::fromValue(const QV4::Value &v)
-{
-    QQmlV4Handle handle;
-    handle.d = v.val;
-    return handle;
-}
-
 QV4::Value QV8Engine::evaluateScript(const QString &script, QV4::Object *scopeObject)
 {
     QV4::ExecutionContext *ctx = m_v4Engine->current;
index 077c784..9781375 100644 (file)
 #include "qv4jsonwrapper_p.h"
 #include <private/qv4value_p.h>
 
-namespace QV4 {
-struct ArrayObject;
-}
-
-namespace v8 {
-
-// Needed for V8ObjectSet
-inline uint qHash(const v8::Handle<v8::Object> &object, uint seed = 0)
-{
-    return (object->GetIdentityHash() ^ seed);
-}
-
-}
-
 QT_BEGIN_NAMESPACE
 
 namespace QV4 {
+    struct ArrayObject;
     struct ExecutionEngine;
     struct Value;
 }
@@ -221,18 +208,16 @@ public:
     QQmlV4Handle() : d(0) {}
     QQmlV4Handle(const QQmlV4Handle &other) : d(other.d) {}
     QQmlV4Handle &operator=(const QQmlV4Handle &other) { d = other.d; return *this; }
+    explicit QQmlV4Handle(const QV4::Value &v) : d(v.val) {}
 
-    static QQmlV4Handle fromV8Handle(v8::Handle<v8::Value> h) {
-        return QQmlV4Handle(h);
-    }
-    v8::Handle<v8::Value> toV8Handle() const {
-        return v8::Value::NewFromInternalValue(d);
+    QV4::Value toValue() const {
+        QV4::Value v;
+        v.val = d;
+        return v;
     }
 
-    QV4::Value toValue() const;
-    static QQmlV4Handle fromValue(const QV4::Value &v);
 private:
-    QQmlV4Handle(v8::Handle<v8::Value> h) : d(h.val) {}
+    QQmlV4Handle(quint64 h) : d(h) {}
     quint64 d;
 };
 
index 6025289..d998c25 100644 (file)
@@ -426,7 +426,7 @@ static v8::Handle<v8::Value> LoadProperty(QV8Engine *engine, QObject *object,
     } else if (property.isV4Handle()) {
         QQmlV4Handle handle;
         ReadFunction(object, property, &handle, notifier);
-        return handle.toV8Handle();
+        return handle.toValue();
     } else if (property.propType == qMetaTypeId<QJSValue>()) {
         QJSValue v;
         ReadFunction(object, property, &v, notifier);
@@ -2171,7 +2171,7 @@ void CallArgument::fromValue(int callType, QV8Engine *engine, v8::Handle<v8::Val
         }
         type = callType;
     } else if (callType == qMetaTypeId<QQmlV4Handle>()) {
-        handlePtr = new (&allocData) QQmlV4Handle(QQmlV4Handle::fromV8Handle(value));
+        handlePtr = new (&allocData) QQmlV4Handle(QQmlV4Handle(value->v4Value()));
         type = callType;
     } else if (callType == QMetaType::QJsonArray) {
         jsonArrayPtr = new (&allocData) QJsonArray(engine->jsonArrayFromJS(value->v4Value()));
index 124a49d..dd669fc 100644 (file)
@@ -192,7 +192,7 @@ QVariant QV8ValueTypeWrapper::toVariant(v8::Handle<v8::Object> obj, int typeHint
     // NOTE: obj must not be an external resource object (ie, wrapper object)
     // instead, it is a normal js object which one of the value-type providers
     // may know how to convert to the given type.
-    return QQml_valueTypeProvider()->createVariantFromJsObject(typeHint, QQmlV4Handle::fromV8Handle(obj), m_engine, succeeded);
+    return QQml_valueTypeProvider()->createVariantFromJsObject(typeHint, QQmlV4Handle(obj->v4Value()), m_engine, succeeded);
 }
 
 QVariant QV8ValueTypeWrapper::toVariant(v8::Handle<v8::Object> obj)
index 1616add..4d0f174 100644 (file)
@@ -2131,7 +2131,7 @@ void QQmlDelegateModelGroupPrivate::emitChanges(QV8Engine *engine)
     if (isChangedConnected() && !changeSet.isEmpty()) {
         v8::Handle<v8::Object> removed  = engineData(engine)->array(engine, changeSet.removes());
         v8::Handle<v8::Object> inserted = engineData(engine)->array(engine, changeSet.inserts());
-        emit q->changed(QQmlV4Handle::fromV8Handle(removed), QQmlV4Handle::fromV8Handle(inserted));
+        emit q->changed(QQmlV4Handle(removed->v4Value()), QQmlV4Handle(inserted->v4Value()));
     }
     if (changeSet.difference() != 0)
         emit q->countChanged();
@@ -2325,14 +2325,14 @@ QQmlV4Handle QQmlDelegateModelGroup::get(int index)
 {
     Q_D(QQmlDelegateModelGroup);
     if (!d->model)
-        return QQmlV4Handle::fromV8Handle(QV4::Value::undefinedValue());;
+        return QQmlV4Handle(QV4::Value::undefinedValue());;
 
     QQmlDelegateModelPrivate *model = QQmlDelegateModelPrivate::get(d->model);
     if (!model->m_context->isValid()) {
-        return QQmlV4Handle::fromV8Handle(QV4::Value::undefinedValue());
+        return QQmlV4Handle(QV4::Value::undefinedValue());
     } else if (index < 0 || index >= model->m_compositor.count(d->group)) {
         qmlInfo(this) << tr("get: index out of range");
-        return QQmlV4Handle::fromV8Handle(QV4::Value::undefinedValue());
+        return QQmlV4Handle(QV4::Value::undefinedValue());
     }
 
     Compositor::iterator it = model->m_compositor.find(d->group, index);
@@ -2344,7 +2344,7 @@ QQmlV4Handle QQmlDelegateModelGroup::get(int index)
         cacheItem = model->m_adaptorModel.createItem(
                 model->m_cacheMetaType, model->m_context->engine(), it.modelIndex());
         if (!cacheItem)
-            return QQmlV4Handle::fromV8Handle(QV4::Value::undefinedValue());
+            return QQmlV4Handle(QV4::Value::undefinedValue());
         cacheItem->groups = it->flags;
 
         model->m_cache.insert(it.cacheIndex, cacheItem);
@@ -2357,7 +2357,7 @@ QQmlV4Handle QQmlDelegateModelGroup::get(int index)
     handle->SetExternalResource(cacheItem);
     ++cacheItem->scriptRef;
 
-    return QQmlV4Handle::fromV8Handle(handle);
+    return QQmlV4Handle(handle->v4Value());
 }
 
 bool QQmlDelegateModelGroupPrivate::parseIndex(
index eb52179..23a41d4 100644 (file)
@@ -2136,7 +2136,7 @@ QQmlV4Handle QQmlListModel::get(int index) const
         }
     }
 
-    return QQmlV4Handle::fromV8Handle(result);
+    return QQmlV4Handle(result->v4Value());
 }
 
 /*!
@@ -2157,7 +2157,7 @@ QQmlV4Handle QQmlListModel::get(int index) const
 */
 void QQmlListModel::set(int index, const QQmlV4Handle &handle)
 {
-    v8::Handle<v8::Value> valuemap = handle.toV8Handle();
+    v8::Handle<v8::Value> valuemap = handle.toValue();
 
     if (!valuemap->IsObject() || valuemap->IsArray()) {
         qmlInfo(this) << tr("set: value is not an object");
index 39a2852..6a98621 100644 (file)
@@ -713,7 +713,7 @@ bool QQuickWorkerScript::event(QEvent *event)
             WorkerDataEvent *workerEvent = static_cast<WorkerDataEvent *>(event);
             QV8Engine *v8engine = QQmlEnginePrivate::get(engine)->v8engine();
             v8::Handle<v8::Value> value = QV8Worker::deserialize(workerEvent->data(), v8engine);
-            emit message(QQmlV4Handle::fromV8Handle(value));
+            emit message(QQmlV4Handle(value->v4Value()));
         }
         return true;
     } else if (event->type() == (QEvent::Type)WorkerErrorEvent::WorkerError) {
index cc9d2c1..1c71c9b 100644 (file)
@@ -369,9 +369,9 @@ QQmlV4Handle QQuickCanvasItem::context() const
 {
     Q_D(const QQuickCanvasItem);
     if (d->contextInitialized)
-        return QQmlV4Handle::fromV8Handle(d->context->v8value());
+        return QQmlV4Handle(d->context->v8value()->v4Value());
 
-    return QQmlV4Handle::fromV8Handle(QV4::Value::nullValue());
+    return QQmlV4Handle(QV4::Value::nullValue());
 }
 
 /*!
index f018075..6bd7373 100644 (file)
@@ -315,7 +315,7 @@ public:
 
         if (ok) *ok = false;
         QFont retn;
-        v8::Handle<v8::Object> obj = object.toV8Handle()->ToObject();
+        v8::Handle<v8::Object> obj = object.toValue();
 
         v8::Handle<v8::Value> vbold = obj->Get(v8::String::New("bold"));
         v8::Handle<v8::Value> vcap = obj->Get(v8::String::New("capitalization"));
@@ -381,7 +381,7 @@ public:
     static QMatrix4x4 matrix4x4FromObject(QQmlV4Handle object, bool *ok)
     {
         if (ok) *ok = false;
-        v8::Handle<v8::Object> obj = object.toV8Handle()->ToObject();
+        v8::Handle<v8::Object> obj = object.toValue();
         if (!obj->IsArray())
             return QMatrix4x4();
 
@@ -751,7 +751,7 @@ public:
     bool variantFromJsObject(int type, QQmlV4Handle object, QV8Engine *e, QVariant *v)
     {
         // must be called with a valid v8 context.
-        Q_ASSERT(object.toV8Handle()->IsObject());
+        Q_ASSERT(object.toValue().isObject());
         bool ok = false;
         switch (type) {
         case QMetaType::QFont: