Get rid of QV8Engine::toQObject and QV8QObjectWrapper::toQObject
authorSimon Hausmann <simon.hausmann@digia.com>
Mon, 3 Jun 2013 13:51:45 +0000 (15:51 +0200)
committerLars Knoll <lars.knoll@digia.com>
Mon, 3 Jun 2013 18:35:24 +0000 (20:35 +0200)
Change-Id: I8726148093079b3385c6b0f16284af0b5ba92066
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
14 files changed:
src/qml/qml/qqmlcomponent.cpp
src/qml/qml/qqmlvmemetaobject.cpp
src/qml/qml/v4/qv4mm.cpp
src/qml/qml/v4/qv4serialize.cpp
src/qml/qml/v8/qjsvalue.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/qv8qobjectwrapper_p.h
src/qml/types/qqmllistmodel.cpp
src/quick/items/context2d/qquickcontext2d.cpp
src/quick/items/qquickitem.cpp
tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp

index 94aeda0..b580f6b 100644 (file)
@@ -1181,8 +1181,10 @@ void QQmlComponent::createObject(QQmlV4Function *args)
     QObject *parent = 0;
     QV4::Value valuemap = QV4::Value::emptyValue();
 
-    if (args->length() >= 1)
-        parent = args->engine()->toQObject((*args)[0]);
+    if (args->length() >= 1) {
+        if (QV4::QObjectWrapper *qobjectWrapper = (*args)[0].as<QV4::QObjectWrapper>())
+            parent = qobjectWrapper->object();
+    }
 
     if (args->length() >= 2) {
         QV4::Value v = (*args)[1];
@@ -1301,8 +1303,10 @@ void QQmlComponent::incubateObject(QQmlV4Function *args)
     QV4::Value valuemap = QV4::Value::emptyValue();
     QQmlIncubator::IncubationMode mode = QQmlIncubator::Asynchronous;
 
-    if (args->length() >= 1)
-        parent = args->engine()->toQObject((*args)[0]);
+    if (args->length() >= 1) {
+        if (QV4::QObjectWrapper *qobjectWrapper = (*args)[0].as<QV4::QObjectWrapper>())
+            parent = qobjectWrapper->object();
+    }
 
     if (args->length() >= 2) {
         QV4::Value v = (*args)[1];
index 0ccaf7f..4a939f2 100644 (file)
@@ -1031,7 +1031,7 @@ void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value)
             v->addVmePropertyReference();
         } else if (QV4::QObjectWrapper *wrapper = o->as<QV4::QObjectWrapper>()) {
             // We need to track this QObject to signal its deletion
-            valueObject = wrapper->object;
+            valueObject = wrapper->object();
 
             // Do we already have a QObject guard for this property?
             if (valueObject && !guard) {
index c3942a9..4afef68 100644 (file)
@@ -300,7 +300,7 @@ void MemoryManager::mark()
         QObjectWrapper *qobjectWrapper = weak->value.as<QObjectWrapper>();
         if (!qobjectWrapper)
             continue;
-        QObject *qobject = qobjectWrapper->object;
+        QObject *qobject = qobjectWrapper->object();
         if (!qobject)
             continue;
         bool keepAlive = QQmlData::keepAliveDuringGarbageCollection(qobject);
index ab6a544..88119fb 100644 (file)
@@ -226,7 +226,7 @@ void Serialize::serialize(QByteArray &data, const QV4::Value &v, QV8Engine *engi
     } else if (QV4::QObjectWrapper *qobjectWrapper = v.as<QV4::QObjectWrapper>()) {
         // XXX TODO: Generalize passing objects between the main thread and worker scripts so
         // that others can trivially plug in their elements.
-        QQmlListModel *lm = qobject_cast<QQmlListModel *>(qobjectWrapper->object);
+        QQmlListModel *lm = qobject_cast<QQmlListModel *>(qobjectWrapper->object());
         if (lm && lm->agent()) {
             QQmlListModelWorkerAgent *agent = lm->agent();
             agent->addref();
index 3e64942..379177e 100644 (file)
@@ -925,12 +925,11 @@ bool QJSValue::hasOwnProperty(const QString &name) const
  */
 QObject *QJSValue::toQObject() const
 {
-    Object *o = d->value.asObject();
+    QV4::QObjectWrapper *o = d->value.as<QV4::QObjectWrapper>();
     if (!o)
         return 0;
 
-    QV8Engine *v8 = d->engine()->publicEngine->handle();
-    return v8->toQObject(d->value);
+    return o->object();
 }
 
 /*!
@@ -979,11 +978,7 @@ bool QJSValue::isRegExp() const
 */
 bool QJSValue::isQObject() const
 {
-    Object *o = d->value.asObject();
-    if (!o)
-        return false;
-
-    return o->as<QV4::QObjectWrapper>() != 0;
+    return d->value.as<QV4::QObjectWrapper>() != 0;
 }
 
 QT_END_NAMESPACE
index 60fa680..020a813 100644 (file)
@@ -997,7 +997,9 @@ Value QtObject::method_createQmlObject(SimpleCallContext *ctx)
     if (url.isValid() && url.isRelative())
         url = context->resolvedUrl(url);
 
-    QObject *parentArg = v8engine->toQObject(ctx->arguments[1]);
+    QObject *parentArg = 0;
+    if (QV4::QObjectWrapper *qobjectWrapper = ctx->arguments[1].as<QV4::QObjectWrapper>())
+        parentArg = qobjectWrapper->object();
     if (!parentArg)
         V4THROW_ERROR("Qt.createQmlObject(): Missing parent object");
 
@@ -1111,7 +1113,8 @@ Value QtObject::method_createComponent(SimpleCallContext *ctx)
 
         if (consumedCount < ctx->argumentCount) {
             if (lastArg.isObject()) {
-                parentArg = v8engine->toQObject(lastArg);
+                if (QV4::QObjectWrapper *qobjectWrapper = lastArg.as<QV4::QObjectWrapper>())
+                    parentArg = qobjectWrapper->object();
                 if (!parentArg)
                     ctx->throwError(invalidParent);
             } else if (lastArg.isNull()) {
index 66eedc5..b5d42f6 100644 (file)
@@ -157,7 +157,7 @@ QVariant QV8Engine::toVariant(const QV4::Value &value, int typeHint)
                    && !value.asArrayObject() && !value.asFunctionObject()) {
             return QVariant::fromValue(jsonObjectFromJS(value));
         } else if (QV4::QObjectWrapper *wrapper = object->as<QV4::QObjectWrapper>()) {
-            return qVariantFromValue<QObject *>(wrapper->object);
+            return qVariantFromValue<QObject *>(wrapper->object());
         } else if (QV4::QmlContextWrapper *wrapper = object->as<QV4::QmlContextWrapper>()) {
             return QVariant();
         } else if (QV4::QmlTypeWrapper *w = object->as<QV4::QmlTypeWrapper>()) {
@@ -176,8 +176,8 @@ QVariant QV8Engine::toVariant(const QV4::Value &value, int typeHint)
             uint32_t length = a->arrayLength();
             for (uint32_t ii = 0; ii < length; ++ii) {
                 QV4::Value arrayItem = a->getIndexed(m_v4Engine->current, ii);
-                if (arrayItem.isObject()) {
-                    list << toQObject(arrayItem);
+                if (QV4::QObjectWrapper *qobjectWrapper = arrayItem.as<QV4::QObjectWrapper>()) {
+                    list << qobjectWrapper->object();
                 } else {
                     list << 0;
                 }
@@ -1021,7 +1021,7 @@ QObject *QV8Engine::qtObjectFromJS(const QV4::Value &value)
     QV4::QObjectWrapper *wrapper = value.as<QV4::QObjectWrapper>();
     if (!wrapper)
         return 0;
-    return wrapper->object;
+    return wrapper->object();
 }
 
 void QV8Engine::startTimer(const QString &timerName)
index 896650d..9b317b5 100644 (file)
@@ -259,7 +259,6 @@ public:
     // Return a JS wrapper for the given QObject \a object
     inline QV4::Value newQObject(QObject *object);
     inline QV4::Value newQObject(QObject *object, const ObjectOwnership ownership);
-    inline QObject *toQObject(const QV4::Value &value);
 
     // Return a JS string for the given QString \a string
     QV4::Value toString(const QString &string);
@@ -353,11 +352,6 @@ private:
     Q_DISABLE_COPY(QV8Engine)
 };
 
-QObject *QV8Engine::toQObject(const QV4::Value &value)
-{
-    return value.isObject() ? m_qobjectWrapper.toQObject(value) : 0;
-}
-
 QV4::Value QV8Engine::newQObject(QObject *object)
 {
     return m_qobjectWrapper.newQObject(object)->v4Value();
index ee1a9b7..084cd4f 100644 (file)
@@ -85,7 +85,7 @@ using namespace QV4;
 
 QObjectWrapper::QObjectWrapper(ExecutionEngine *engine, QObject *object)
     : Object(engine)
-    , object(object)
+    , m_object(object)
 {
     this->v8Engine = QV8Engine::get(engine->publicEngine);
     vtbl = &static_vtbl;
@@ -102,20 +102,20 @@ QObjectWrapper::~QObjectWrapper()
 
 void QObjectWrapper::deleteQObject(bool deleteInstantly)
 {
-    if (!object)
+    if (!m_object)
         return;
-    QQmlData *ddata = QQmlData::get(object, false);
+    QQmlData *ddata = QQmlData::get(m_object, false);
     if (!ddata)
         return;
-    if (!object->parent() && !ddata->indestructible) {
+    if (!m_object->parent() && !ddata->indestructible) {
         // This object is notionally destroyed now
         if (ddata->ownContext && ddata->context)
             ddata->context->emitDestruction();
         ddata->isQueuedForDeletion = true;
         if (deleteInstantly)
-            delete object;
+            delete m_object;
         else
-            object->deleteLater();
+            m_object->deleteLater();
     }
 }
 
@@ -123,7 +123,7 @@ QV4::Value QObjectWrapper::get(Managed *m, ExecutionContext *ctx, String *name,
 {
     QObjectWrapper *that = static_cast<QObjectWrapper*>(m);
 
-    if (QQmlData::wasDeleted(that->object)) {
+    if (QQmlData::wasDeleted(that->m_object)) {
         if (hasProperty)
             *hasProperty = false;
         return QV4::Value::undefinedValue();
@@ -135,7 +135,7 @@ QV4::Value QObjectWrapper::get(Managed *m, ExecutionContext *ctx, String *name,
 
         if (!hasProp) {
             int index = name->isEqualTo(that->m_destroy) ? QV4::QObjectMethod::DestroyMethod : QV4::QObjectMethod::ToStringMethod;
-            method = QV4::Value::fromObject(new (ctx->engine->memoryManager) QV4::QObjectMethod(ctx->engine->rootContext, that->object, index, QV4::Value::undefinedValue()));
+            method = QV4::Value::fromObject(new (ctx->engine->memoryManager) QV4::QObjectMethod(ctx->engine->rootContext, that->m_object, index, QV4::Value::undefinedValue()));
             QV4::Object::put(m, ctx, name, method);
         }
 
@@ -150,7 +150,7 @@ QV4::Value QObjectWrapper::get(Managed *m, ExecutionContext *ctx, String *name,
     QV8Engine *v8engine = that->v8Engine;
     QQmlContextData *context = v8engine->callingContext();
 
-    v8::Handle<v8::Value> result = QV8QObjectWrapper::GetProperty(v8engine, that->object, propertystring,
+    v8::Handle<v8::Value> result = QV8QObjectWrapper::GetProperty(v8engine, that->m_object, propertystring,
                                                                   context, QV8QObjectWrapper::IgnoreRevision);
     if (!result.IsEmpty()) {
         if (hasProperty)
@@ -167,9 +167,9 @@ QV4::Value QObjectWrapper::get(Managed *m, ExecutionContext *ctx, String *name,
                 if (r.scriptIndex != -1) {
                     return QV4::Value::undefinedValue();
                 } else if (r.type) {
-                    return QmlTypeWrapper::create(v8engine, that->object, r.type, QmlTypeWrapper::ExcludeEnums);
+                    return QmlTypeWrapper::create(v8engine, that->m_object, r.type, QmlTypeWrapper::ExcludeEnums);
                 } else if (r.importNamespace) {
-                    return QmlTypeWrapper::create(v8engine, that->object, context->imports, r.importNamespace, QmlTypeWrapper::ExcludeEnums);
+                    return QmlTypeWrapper::create(v8engine, that->m_object, context->imports, r.importNamespace, QmlTypeWrapper::ExcludeEnums);
                 }
                 Q_ASSERT(!"Unreachable");
             }
@@ -183,10 +183,10 @@ void QObjectWrapper::put(Managed *m, ExecutionContext *ctx, String *name, const
 {
     QObjectWrapper *that = static_cast<QObjectWrapper*>(m);
 
-    if (QQmlData::wasDeleted(that->object))
+    if (QQmlData::wasDeleted(that->m_object))
         return;
 
-    QObject *object = that->object;
+    QObject *object = that->m_object;
 
     QHashedV4String propertystring(QV4::Value::fromString(name));
 
@@ -205,7 +205,7 @@ QV4::Value QObjectWrapper::enumerateProperties(Object *object)
 {
     QObjectWrapper *that = static_cast<QObjectWrapper*>(object);
 
-    if (that->object.isNull())
+    if (that->m_object.isNull())
         return QV4::Value::undefinedValue();
 
     QStringList result;
@@ -215,17 +215,17 @@ QV4::Value QObjectWrapper::enumerateProperties(Object *object)
             : 0;
 
     QQmlPropertyCache *cache = 0;
-    QQmlData *ddata = QQmlData::get(that->object);
+    QQmlData *ddata = QQmlData::get(that->m_object);
     if (ddata)
         cache = ddata->propertyCache;
 
     if (!cache) {
-        cache = ep ? ep->cache(that->object) : 0;
+        cache = ep ? ep->cache(that->m_object) : 0;
         if (cache) {
             if (ddata) { cache->addref(); ddata->propertyCache = cache; }
         } else {
             // Not cachable - fall back to QMetaObject (eg. dynamic meta object)
-            const QMetaObject *mo = that->object->metaObject();
+            const QMetaObject *mo = that->m_object->metaObject();
             int pc = mo->propertyCount();
             int po = mo->propertyOffset();
             for (int i=po; i<pc; ++i)
@@ -242,7 +242,7 @@ void QObjectWrapper::markObjects(Managed *that)
 {
     QObjectWrapper *This = static_cast<QObjectWrapper*>(that);
 
-    QQmlVMEMetaObject *vme = QQmlVMEMetaObject::get(This->object);
+    QQmlVMEMetaObject *vme = QQmlVMEMetaObject::get(This->m_object);
     if (vme)
         vme->mark();
 
@@ -417,12 +417,6 @@ void QV8QObjectWrapper::init(QV8Engine *engine)
     v4->functionPrototype->defineDefaultProperty(v4, QStringLiteral("disconnect"), Disconnect);
 }
 
-QObject *QV8QObjectWrapper::toQObject(v8::Handle<v8::Object> obj)
-{
-    QV4::QObjectWrapper *wrapper =  obj->v4Value().as<QObjectWrapper>();
-    return wrapper?wrapper->object:0;
-}
-
 // Load value properties
 template<void (*ReadFunction)(QObject *, const QQmlPropertyData &,
                               void *, QQmlNotifier **)>
@@ -762,10 +756,10 @@ static void FastValueSetter(v8::Handle<v8::String>, v8::Handle<v8::Value> value,
 {
     QV4::QObjectWrapper *wrapper = info.This()->v4Value().as<QObjectWrapper>();
 
-    if (QQmlData::wasDeleted(wrapper->object))
+    if (QQmlData::wasDeleted(wrapper->object()))
         return; 
 
-    QObject *object = wrapper->object;
+    QObject *object = wrapper->object();
 
     QQmlPropertyData *property =
             (QQmlPropertyData *)v8::External::Cast(info.Data().get())->Value();
@@ -789,7 +783,7 @@ static void FastValueSetterReadOnly(v8::Handle<v8::String> property, v8::Handle<
 {
     QV4::QObjectWrapper *wrapper = info.This()->v4Value().as<QObjectWrapper>();
 
-    if (QQmlData::wasDeleted(wrapper->object))
+    if (QQmlData::wasDeleted(wrapper->object()))
         return; 
 
     QV8Engine *v8engine = wrapper->v8Engine;
@@ -1719,7 +1713,9 @@ void CallArgument::fromValue(int callType, QV8Engine *engine, const QV4::Value &
             qstringPtr = new (&allocData) QString(value.toQString());
         type = callType;
     } else if (callType == QMetaType::QObjectStar) {
-        qobjectPtr = engine->toQObject(value);
+        qobjectPtr = 0;
+        if (QV4::QObjectWrapper *qobjectWrapper = value.as<QV4::QObjectWrapper>())
+            qobjectPtr = qobjectWrapper->object();
         type = callType;
     } else if (callType == qMetaTypeId<QVariant>()) {
         qvariantPtr = new (&allocData) QVariant(engine->toVariant(value, -1));
@@ -1728,10 +1724,17 @@ void CallArgument::fromValue(int callType, QV8Engine *engine, const QV4::Value &
         qlistPtr = new (&allocData) QList<QObject *>();
         if (QV4::ArrayObject *array = value.asArrayObject()) {
             uint32_t length = array->arrayLength();
-            for (uint32_t ii = 0; ii < length; ++ii) 
-                qlistPtr->append(engine->toQObject(array->getIndexed(ii)));
+            for (uint32_t ii = 0; ii < length; ++ii)  {
+                QObject *o = 0;
+                if (QV4::QObjectWrapper *qobjectWrapper = array->getIndexed(ii).as<QV4::QObjectWrapper>())
+                    o = qobjectWrapper->object();
+                qlistPtr->append(o);
+            }
         } else {
-            qlistPtr->append(engine->toQObject(value));
+            QObject *o = 0;
+            if (QV4::QObjectWrapper *qobjectWrapper = value.as<QV4::QObjectWrapper>())
+                o = qobjectWrapper->object();
+            qlistPtr->append(o);
         }
         type = callType;
     } else if (callType == qMetaTypeId<QQmlV4Handle>()) {
@@ -1823,8 +1826,10 @@ QV4::Value CallArgument::toValue(QV8Engine *engine)
     } else if (type == -1 || type == qMetaTypeId<QVariant>()) {
         QVariant value = *qvariantPtr;
         QV4::Value rv = engine->fromVariant(value);
-        if (QObject *object = engine->toQObject(rv))
-            QQmlData::get(object, true)->setImplicitDestructible();
+        if (QV4::QObjectWrapper *qobjectWrapper = rv.as<QV4::QObjectWrapper>()) {
+            if (QObject *object = qobjectWrapper->object())
+                QQmlData::get(object, true)->setImplicitDestructible();
+        }
         return rv;
     } else {
         return QV4::Value::undefinedValue();
index 65a3836..b88b3ce 100644 (file)
@@ -83,15 +83,17 @@ struct Q_QML_EXPORT QObjectWrapper : public QV4::Object
 {
     Q_MANAGED
 
-    QObjectWrapper(ExecutionEngine *v8Engine, QObject *object);
+    QObjectWrapper(ExecutionEngine *v8Engine, QObject *m_object);
     ~QObjectWrapper();
 
     QV8Engine *v8Engine; // ### Remove again.
-    QQmlGuard<QObject> object;
+
+    QObject *object() const { return m_object.data(); }
 
     void deleteQObject(bool deleteInstantly = false);
 
 private:
+    QQmlGuard<QObject> m_object;
     String *m_destroy;
     String *m_toString;
 
@@ -99,7 +101,7 @@ private:
     static void put(Managed *m, ExecutionContext *ctx, String *name, const Value &value);
     static void markObjects(Managed *that);
 
-    static Value enumerateProperties(Object *object);
+    static Value enumerateProperties(Object *m_object);
 
     static void destroy(Managed *that)
     {
@@ -167,7 +169,6 @@ public:
     void destroy();
 
     v8::Handle<v8::Value> newQObject(QObject *object);
-    QObject *toQObject(v8::Handle<v8::Object>);
 
     enum RevisionMode { IgnoreRevision, CheckRevision };
     inline v8::Handle<v8::Value> getProperty(QObject *, const QHashedV4String &, QQmlContextData *, RevisionMode);
index daaf430..85081e1 100644 (file)
@@ -454,7 +454,7 @@ void ListModel::set(int elementIndex, v8::Handle<v8::Object> object, QVector<int
             roleIndex = e->setDateTimeProperty(r, dt);
         } else if (propertyValue->IsObject()) {
             if (QV4::QObjectWrapper *wrapper = propertyValue->v4Value().as<QV4::QObjectWrapper>()) {
-                QObject *o = wrapper->object;
+                QObject *o = wrapper->object();
                 const ListLayout::Role &role = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::QObject);
                 if (role.type == ListLayout::Role::QObject)
                     roleIndex = e->setQObjectProperty(role, o);
@@ -529,7 +529,7 @@ void ListModel::set(int elementIndex, v8::Handle<v8::Object> object, QV8Engine *
             }
         } else if (propertyValue->IsObject()) {
             if (QV4::QObjectWrapper *wrapper = propertyValue->v4Value().as<QV4::QObjectWrapper>()) {
-                QObject *o = wrapper->object;
+                QObject *o = wrapper->object();
                 const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::QObject);
                 if (r.type == ListLayout::Role::QObject)
                     e->setQObjectPropertyFast(r, o);
@@ -1190,7 +1190,7 @@ int ListElement::setJsProperty(const ListLayout::Role &role, v8::Handle<v8::Valu
     } else if (d->IsObject()) {
         QV4::QObjectWrapper *wrapper = d->v4Value().as<QV4::QObjectWrapper>();
         if (role.type == ListLayout::Role::QObject && wrapper) {
-            QObject *o = wrapper->object;
+            QObject *o = wrapper->object();
             roleIndex = setQObjectProperty(role, o);
         } else if (role.type == ListLayout::Role::VariantMap) {
             roleIndex = setVariantMapProperty(role, d->ToObject(), eng);
index cee492e..8f2c454 100644 (file)
@@ -1537,9 +1537,10 @@ static void ctx2d_path_set(v8::Handle<v8::String>, v8::Handle<v8::Value> value,
 
     r->context->beginPath();
     if (value->IsObject()) {
-        QQuickPath* path = qobject_cast<QQuickPath*>(engine->toQObject(value->v4Value()));
-        if (path)
-            r->context->m_path = path->path();
+        if (QV4::QObjectWrapper *qobjectWrapper = value->v4Value().as<QV4::QObjectWrapper>()) {
+            if (QQuickPath *path = qobject_cast<QQuickPath*>(qobjectWrapper->object()))
+                r->context->m_path = path->path();
+        }
     } else {
         QString path = value->v4Value().toQString();
         QQuickSvgParser::parsePathDataFast(path, r->context->m_path);
@@ -2329,8 +2330,12 @@ static QV4::Value ctx2d_drawImage(const v8::Arguments &args)
 
         pixmap = r->context->createPixmap(url);
     } else if (args[0]->IsObject()) {
-        QQuickImage *imageItem = qobject_cast<QQuickImage*>(engine->toQObject(args[0]->v4Value()));
-        QQuickCanvasItem *canvas = qobject_cast<QQuickCanvasItem*>(engine->toQObject(args[0]->v4Value()));
+        QQuickImage *imageItem = 0;
+        if (QV4::QObjectWrapper *qobjectWrapper = args[0]->v4Value().as<QV4::QObjectWrapper>())
+            imageItem = qobject_cast<QQuickImage*>(qobjectWrapper->object());
+        QQuickCanvasItem *canvas = 0;
+        if (QV4::QObjectWrapper *qobjectWrapper = args[0]->v4Value().as<QV4::QObjectWrapper>())
+            canvas = qobject_cast<QQuickCanvasItem*>(qobjectWrapper->object());
 
         QV8Context2DPixelArrayResource *pix = v8_resource_cast<QV8Context2DPixelArrayResource>(args[0]->ToObject()->GetInternalField(0)->ToObject());
         if (pix && !pix->image.isNull()) {
index fb64fa8..659058d 100644 (file)
@@ -3755,11 +3755,12 @@ void QQuickItem::mapFromItem(QQmlV4Function *args) const
 {
     if (args->length() != 0) {
         v8::Handle<v8::Value> item = (*args)[0];
-        QV8Engine *engine = args->engine();
 
         QQuickItem *itemObj = 0;
-        if (!item->IsNull())
-            itemObj = qobject_cast<QQuickItem*>(engine->toQObject(item->v4Value()));
+        if (!item->IsNull()) {
+            if (QV4::QObjectWrapper *qobjectWrapper = item->v4Value().as<QV4::QObjectWrapper>())
+                itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
+        }
 
         if (!itemObj && !item->IsNull()) {
             qmlInfo(this) << "mapFromItem() given argument \"" << item->v4Value().toQString()
@@ -3827,11 +3828,12 @@ void QQuickItem::mapToItem(QQmlV4Function *args) const
 {
     if (args->length() != 0) {
         v8::Handle<v8::Value> item = (*args)[0];
-        QV8Engine *engine = args->engine();
 
         QQuickItem *itemObj = 0;
-        if (!item->IsNull())
-            itemObj = qobject_cast<QQuickItem*>(engine->toQObject(item->v4Value()));
+        if (!item->IsNull()) {
+            if (QV4::QObjectWrapper *qobjectWrapper = item->v4Value().as<QV4::QObjectWrapper>())
+                itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
+        }
 
         if (!itemObj && !item->IsNull()) {
             qmlInfo(this) << "mapToItem() given argument \"" << item->v4Value().toQString()
index ffd4a15..261e0c2 100644 (file)
@@ -2323,7 +2323,9 @@ void tst_qqmlecmascript::callQtInvokables()
     o->reset();
     {
     v8::Handle<v8::Value> ret = EVALUATE("object.method_NoArgs_QObject()");
-    QCOMPARE(engine->toQObject(ret->v4Value()), (QObject *)o);
+    QV4::QObjectWrapper *qobjectWrapper = ret->v4Value().as<QV4::QObjectWrapper>();
+    QVERIFY(qobjectWrapper);
+    QCOMPARE(qobjectWrapper->object(), (QObject *)o);
     QCOMPARE(o->error(), false);
     QCOMPARE(o->invoked(), 4);
     QCOMPARE(o->actuals().count(), 0);