From a336ca4cc35fdcabedf4ff2614cc6d6625e7d4ef Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 3 Jun 2013 15:51:45 +0200 Subject: [PATCH] Get rid of QV8Engine::toQObject and QV8QObjectWrapper::toQObject Change-Id: I8726148093079b3385c6b0f16284af0b5ba92066 Reviewed-by: Lars Knoll --- src/qml/qml/qqmlcomponent.cpp | 12 ++-- src/qml/qml/qqmlvmemetaobject.cpp | 2 +- src/qml/qml/v4/qv4mm.cpp | 2 +- src/qml/qml/v4/qv4serialize.cpp | 2 +- src/qml/qml/v8/qjsvalue.cpp | 11 +-- src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 7 +- src/qml/qml/v8/qv8engine.cpp | 8 +-- src/qml/qml/v8/qv8engine_p.h | 6 -- src/qml/qml/v8/qv8qobjectwrapper.cpp | 71 ++++++++++--------- src/qml/qml/v8/qv8qobjectwrapper_p.h | 9 +-- src/qml/types/qqmllistmodel.cpp | 6 +- src/quick/items/context2d/qquickcontext2d.cpp | 15 ++-- src/quick/items/qquickitem.cpp | 14 ++-- .../qml/qqmlecmascript/tst_qqmlecmascript.cpp | 4 +- 14 files changed, 90 insertions(+), 79 deletions(-) diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index 94aeda0fb0..b580f6b66f 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -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()) + 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()) + parent = qobjectWrapper->object(); + } if (args->length() >= 2) { QV4::Value v = (*args)[1]; diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 0ccaf7fcfc..4a939f29e5 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -1031,7 +1031,7 @@ void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) v->addVmePropertyReference(); } else if (QV4::QObjectWrapper *wrapper = o->as()) { // 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) { diff --git a/src/qml/qml/v4/qv4mm.cpp b/src/qml/qml/v4/qv4mm.cpp index c3942a915b..4afef6801a 100644 --- a/src/qml/qml/v4/qv4mm.cpp +++ b/src/qml/qml/v4/qv4mm.cpp @@ -300,7 +300,7 @@ void MemoryManager::mark() QObjectWrapper *qobjectWrapper = weak->value.as(); if (!qobjectWrapper) continue; - QObject *qobject = qobjectWrapper->object; + QObject *qobject = qobjectWrapper->object(); if (!qobject) continue; bool keepAlive = QQmlData::keepAliveDuringGarbageCollection(qobject); diff --git a/src/qml/qml/v4/qv4serialize.cpp b/src/qml/qml/v4/qv4serialize.cpp index ab6a544441..88119fb196 100644 --- a/src/qml/qml/v4/qv4serialize.cpp +++ b/src/qml/qml/v4/qv4serialize.cpp @@ -226,7 +226,7 @@ void Serialize::serialize(QByteArray &data, const QV4::Value &v, QV8Engine *engi } else if (QV4::QObjectWrapper *qobjectWrapper = v.as()) { // 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(qobjectWrapper->object); + QQmlListModel *lm = qobject_cast(qobjectWrapper->object()); if (lm && lm->agent()) { QQmlListModelWorkerAgent *agent = lm->agent(); agent->addref(); diff --git a/src/qml/qml/v8/qjsvalue.cpp b/src/qml/qml/v8/qjsvalue.cpp index 3e649422d0..379177ed97 100644 --- a/src/qml/qml/v8/qjsvalue.cpp +++ b/src/qml/qml/v8/qjsvalue.cpp @@ -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(); 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() != 0; + return d->value.as() != 0; } QT_END_NAMESPACE diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index 60fa680050..020a813718 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -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()) + 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()) + parentArg = qobjectWrapper->object(); if (!parentArg) ctx->throwError(invalidParent); } else if (lastArg.isNull()) { diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 66eedc5d60..b5d42f6028 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -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()) { - return qVariantFromValue(wrapper->object); + return qVariantFromValue(wrapper->object()); } else if (QV4::QmlContextWrapper *wrapper = object->as()) { return QVariant(); } else if (QV4::QmlTypeWrapper *w = object->as()) { @@ -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()) { + list << qobjectWrapper->object(); } else { list << 0; } @@ -1021,7 +1021,7 @@ QObject *QV8Engine::qtObjectFromJS(const QV4::Value &value) QV4::QObjectWrapper *wrapper = value.as(); if (!wrapper) return 0; - return wrapper->object; + return wrapper->object(); } void QV8Engine::startTimer(const QString &timerName) diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h index 896650de16..9b317b5f88 100644 --- a/src/qml/qml/v8/qv8engine_p.h +++ b/src/qml/qml/v8/qv8engine_p.h @@ -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(); diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp index ee1a9b7472..084cd4f974 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper.cpp +++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp @@ -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(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 result = QV8QObjectWrapper::GetProperty(v8engine, that->object, propertystring, + v8::Handle 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(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(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(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 obj) -{ - QV4::QObjectWrapper *wrapper = obj->v4Value().as(); - return wrapper?wrapper->object:0; -} - // Load value properties template @@ -762,10 +756,10 @@ static void FastValueSetter(v8::Handle, v8::Handle value, { QV4::QObjectWrapper *wrapper = info.This()->v4Value().as(); - 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 property, v8::Handle< { QV4::QObjectWrapper *wrapper = info.This()->v4Value().as(); - 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()) + qobjectPtr = qobjectWrapper->object(); type = callType; } else if (callType == qMetaTypeId()) { 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(); 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()) + o = qobjectWrapper->object(); + qlistPtr->append(o); + } } else { - qlistPtr->append(engine->toQObject(value)); + QObject *o = 0; + if (QV4::QObjectWrapper *qobjectWrapper = value.as()) + o = qobjectWrapper->object(); + qlistPtr->append(o); } type = callType; } else if (callType == qMetaTypeId()) { @@ -1823,8 +1826,10 @@ QV4::Value CallArgument::toValue(QV8Engine *engine) } else if (type == -1 || type == qMetaTypeId()) { 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()) { + if (QObject *object = qobjectWrapper->object()) + QQmlData::get(object, true)->setImplicitDestructible(); + } return rv; } else { return QV4::Value::undefinedValue(); diff --git a/src/qml/qml/v8/qv8qobjectwrapper_p.h b/src/qml/qml/v8/qv8qobjectwrapper_p.h index 65a3836be2..b88b3cea99 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper_p.h +++ b/src/qml/qml/v8/qv8qobjectwrapper_p.h @@ -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 object; + + QObject *object() const { return m_object.data(); } void deleteQObject(bool deleteInstantly = false); private: + QQmlGuard 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 newQObject(QObject *object); - QObject *toQObject(v8::Handle); enum RevisionMode { IgnoreRevision, CheckRevision }; inline v8::Handle getProperty(QObject *, const QHashedV4String &, QQmlContextData *, RevisionMode); diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp index daaf43052d..85081e1251 100644 --- a/src/qml/types/qqmllistmodel.cpp +++ b/src/qml/types/qqmllistmodel.cpp @@ -454,7 +454,7 @@ void ListModel::set(int elementIndex, v8::Handle object, QVectorsetDateTimeProperty(r, dt); } else if (propertyValue->IsObject()) { if (QV4::QObjectWrapper *wrapper = propertyValue->v4Value().as()) { - 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 object, QV8Engine * } } else if (propertyValue->IsObject()) { if (QV4::QObjectWrapper *wrapper = propertyValue->v4Value().as()) { - 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::HandleIsObject()) { QV4::QObjectWrapper *wrapper = d->v4Value().as(); 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); diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp index cee492e5ab..8f2c454a9a 100644 --- a/src/quick/items/context2d/qquickcontext2d.cpp +++ b/src/quick/items/context2d/qquickcontext2d.cpp @@ -1537,9 +1537,10 @@ static void ctx2d_path_set(v8::Handle, v8::Handle value, r->context->beginPath(); if (value->IsObject()) { - QQuickPath* path = qobject_cast(engine->toQObject(value->v4Value())); - if (path) - r->context->m_path = path->path(); + if (QV4::QObjectWrapper *qobjectWrapper = value->v4Value().as()) { + if (QQuickPath *path = qobject_cast(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(engine->toQObject(args[0]->v4Value())); - QQuickCanvasItem *canvas = qobject_cast(engine->toQObject(args[0]->v4Value())); + QQuickImage *imageItem = 0; + if (QV4::QObjectWrapper *qobjectWrapper = args[0]->v4Value().as()) + imageItem = qobject_cast(qobjectWrapper->object()); + QQuickCanvasItem *canvas = 0; + if (QV4::QObjectWrapper *qobjectWrapper = args[0]->v4Value().as()) + canvas = qobject_cast(qobjectWrapper->object()); QV8Context2DPixelArrayResource *pix = v8_resource_cast(args[0]->ToObject()->GetInternalField(0)->ToObject()); if (pix && !pix->image.isNull()) { diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index fb64fa854c..659058d70f 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -3755,11 +3755,12 @@ void QQuickItem::mapFromItem(QQmlV4Function *args) const { if (args->length() != 0) { v8::Handle item = (*args)[0]; - QV8Engine *engine = args->engine(); QQuickItem *itemObj = 0; - if (!item->IsNull()) - itemObj = qobject_cast(engine->toQObject(item->v4Value())); + if (!item->IsNull()) { + if (QV4::QObjectWrapper *qobjectWrapper = item->v4Value().as()) + itemObj = qobject_cast(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 item = (*args)[0]; - QV8Engine *engine = args->engine(); QQuickItem *itemObj = 0; - if (!item->IsNull()) - itemObj = qobject_cast(engine->toQObject(item->v4Value())); + if (!item->IsNull()) { + if (QV4::QObjectWrapper *qobjectWrapper = item->v4Value().as()) + itemObj = qobject_cast(qobjectWrapper->object()); + } if (!itemObj && !item->IsNull()) { qmlInfo(this) << "mapToItem() given argument \"" << item->v4Value().toQString() diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index ffd4a154ca..261e0c2512 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -2323,7 +2323,9 @@ void tst_qqmlecmascript::callQtInvokables() o->reset(); { v8::Handle ret = EVALUATE("object.method_NoArgs_QObject()"); - QCOMPARE(engine->toQObject(ret->v4Value()), (QObject *)o); + QV4::QObjectWrapper *qobjectWrapper = ret->v4Value().as(); + QVERIFY(qobjectWrapper); + QCOMPARE(qobjectWrapper->object(), (QObject *)o); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 4); QCOMPARE(o->actuals().count(), 0);