From ac15ec470ebc8fe0e66550ce1183187e3868bb40 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 6 Jun 2013 14:52:07 +0200 Subject: [PATCH] Get rid of QV8QObjectWrapper::getProperty Replace the call sites with calls to getQmlProperty on the QObjectWrapper. Change-Id: I3dbc3788c8d1631d817f65c738f0a8a31deb2866 Reviewed-by: Lars Knoll --- src/qml/qml/qqmlcontextwrapper.cpp | 17 +++++++++-------- src/qml/qml/qqmltypewrapper.cpp | 13 +++++++++---- src/qml/qml/qqmlvaluetypewrapper.cpp | 5 +++-- src/qml/qml/v8/qv8qobjectwrapper.cpp | 15 +++++++-------- src/qml/qml/v8/qv8qobjectwrapper_p.h | 15 +-------------- 5 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index 4d8a8ac..dd7d28c 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -190,7 +190,6 @@ Value QmlContextWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bo } QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine->engine()); - QV8QObjectWrapper *qobjectWrapper = engine->qobjectWrapper(); while (context) { // Search context properties @@ -231,7 +230,7 @@ Value QmlContextWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bo if (scopeObject) { if (QV4::QObjectWrapper *o = QV4::QObjectWrapper::wrap(ctx->engine, scopeObject).as()) { bool hasProp = false; - QV4::Value result = o->getQmlProperty(o->engine()->current, propertystring.string().asString(), QV4::QObjectWrapper::CheckRevision, &hasProp); + QV4::Value result = o->getQmlProperty(ctx, context, name, QV4::QObjectWrapper::CheckRevision, &hasProp); if (hasProp) { if (hasProperty) *hasProperty = true; @@ -244,12 +243,14 @@ Value QmlContextWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bo // Search context object if (context->contextObject) { - QV4::Value result = qobjectWrapper->getProperty(context->contextObject, propertystring, - context, QV4::QObjectWrapper::CheckRevision)->v4Value(); - if (!result.isEmpty()) { - if (hasProperty) - *hasProperty = true; - return result; + if (QV4::QObjectWrapper *o = QV4::QObjectWrapper::wrap(ctx->engine, context->contextObject).as()) { + bool hasProp = false; + QV4::Value result = o->getQmlProperty(ctx, context, name, QV4::QObjectWrapper::CheckRevision, &hasProp); + if (hasProp) { + if (hasProperty) + *hasProperty = true; + return result; + } } } diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index 5074590..e98117e 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -158,7 +158,10 @@ Value QmlTypeWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool } // check for property. - return v8engine->qobjectWrapper()->getProperty(qobjectSingleton, propertystring, context, QV4::QObjectWrapper::IgnoreRevision)->v4Value(); + if (QV4::QObjectWrapper *o = QV4::QObjectWrapper::wrap(ctx->engine, qobjectSingleton).as()) + return o->getQmlProperty(ctx, context, name, QV4::QObjectWrapper::IgnoreRevision); + else + return QV4::Value::undefinedValue(); } else if (!siinfo->scriptApi(e).isUndefined()) { QV4::ExecutionEngine *engine = QV8Engine::getV4(v8engine); // NOTE: if used in a binding, changes will not trigger re-evaluation since non-NOTIFYable. @@ -181,9 +184,11 @@ Value QmlTypeWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool } else if (w->object) { QObject *ao = qmlAttachedPropertiesObjectById(type->attachedPropertiesId(), object); - if (ao) - return v8engine->qobjectWrapper()->getProperty(ao, propertystring, context, - QV4::QObjectWrapper::IgnoreRevision)->v4Value(); + if (ao) { + QV4::QObjectWrapper *wrapper = QV4::QObjectWrapper::wrap(ctx->engine, ao).as(); + if (wrapper) + return wrapper->getQmlProperty(ctx, context, name, QV4::QObjectWrapper::IgnoreRevision); + } // Fall through to base implementation } diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp index abf0be7..955ea04 100644 --- a/src/qml/qml/qqmlvaluetypewrapper.cpp +++ b/src/qml/qml/qqmlvaluetypewrapper.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -283,8 +284,8 @@ Value QmlValueTypeWrapper::get(Managed *m, ExecutionContext *ctx, String *name, if (result->isFunction()) { // calling a Q_INVOKABLE function of a value type - QQmlContextData *context = r->v8->callingContext(); - return r->v8->qobjectWrapper()->getProperty(r->type, propertystring, context, QV4::QObjectWrapper::IgnoreRevision)->v4Value(); + QQmlContextData *qmlContext = QV4::QmlContextWrapper::callingContext(ctx->engine); + return QV4::QObjectWrapper::wrap(ctx->engine, r->type).as()->getQmlProperty(ctx, qmlContext, name, QV4::QObjectWrapper::IgnoreRevision); } #define VALUE_TYPE_LOAD(metatype, cpptype, constructor) \ diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp index 32d08c3..4ce860e 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper.cpp +++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp @@ -146,7 +146,7 @@ void QObjectWrapper::deleteQObject(bool deleteInstantly) } } -Value QObjectWrapper::getQmlProperty(ExecutionContext *ctx, String *name, QObjectWrapper::RevisionMode revisionMode, bool *hasProperty, bool includeImports) +Value QObjectWrapper::getQmlProperty(ExecutionContext *ctx, QQmlContextData *qmlContext, String *name, QObjectWrapper::RevisionMode revisionMode, bool *hasProperty, bool includeImports) { if (QQmlData::wasDeleted(m_object)) { if (hasProperty) @@ -173,9 +173,7 @@ Value QObjectWrapper::getQmlProperty(ExecutionContext *ctx, String *name, QObjec QHashedV4String propertystring(QV4::Value::fromString(name)); QV8Engine *v8Engine = ctx->engine->v8Engine; - QQmlContextData *context = QV4::QmlContextWrapper::callingContext(ctx->engine); - - v8::Handle result = QV8QObjectWrapper::GetProperty(v8Engine, m_object, propertystring, context, revisionMode); + v8::Handle result = QV8QObjectWrapper::GetProperty(v8Engine, m_object, propertystring, qmlContext, revisionMode); if (!result.IsEmpty()) { if (hasProperty) *hasProperty = true; @@ -184,8 +182,8 @@ Value QObjectWrapper::getQmlProperty(ExecutionContext *ctx, String *name, QObjec if (includeImports && name->startsWithUpper()) { // Check for attached properties - if (context && context->imports) { - QQmlTypeNameCache::Result r = context->imports->query(propertystring); + if (qmlContext && qmlContext->imports) { + QQmlTypeNameCache::Result r = qmlContext->imports->query(propertystring); if (r.isValid()) { if (r.scriptIndex != -1) { @@ -193,7 +191,7 @@ Value QObjectWrapper::getQmlProperty(ExecutionContext *ctx, String *name, QObjec } else if (r.type) { return QmlTypeWrapper::create(v8Engine, m_object, r.type, QmlTypeWrapper::ExcludeEnums); } else if (r.importNamespace) { - return QmlTypeWrapper::create(v8Engine, m_object, context->imports, r.importNamespace, QmlTypeWrapper::ExcludeEnums); + return QmlTypeWrapper::create(v8Engine, m_object, qmlContext->imports, r.importNamespace, QmlTypeWrapper::ExcludeEnums); } Q_ASSERT(!"Unreachable"); } @@ -267,7 +265,8 @@ QV4::Value QObjectWrapper::create(ExecutionEngine *engine, QQmlData *ddata, QObj QV4::Value QObjectWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty) { QObjectWrapper *that = static_cast(m); - return that->getQmlProperty(ctx, name, IgnoreRevision, hasProperty, /*includeImports*/ true); + QQmlContextData *qmlContext = QV4::QmlContextWrapper::callingContext(ctx->engine); + return that->getQmlProperty(ctx, qmlContext, name, IgnoreRevision, hasProperty, /*includeImports*/ true); } void QObjectWrapper::put(Managed *m, ExecutionContext *ctx, String *name, const Value &value) diff --git a/src/qml/qml/v8/qv8qobjectwrapper_p.h b/src/qml/qml/v8/qv8qobjectwrapper_p.h index e06ce49..fe8ff38 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper_p.h +++ b/src/qml/qml/v8/qv8qobjectwrapper_p.h @@ -92,7 +92,7 @@ struct Q_QML_EXPORT QObjectWrapper : public QV4::Object void deleteQObject(bool deleteInstantly = false); - Value getQmlProperty(ExecutionContext *ctx, String *name, RevisionMode revisionMode, bool *hasProperty = 0, bool includeImports = false); + Value getQmlProperty(ExecutionContext *ctx, QQmlContextData *qmlContext, String *name, RevisionMode revisionMode, bool *hasProperty = 0, bool includeImports = false); static Value wrap(ExecutionEngine *engine, QObject *object); @@ -203,7 +203,6 @@ public: void init(QV8Engine *); void destroy(); - inline v8::Handle getProperty(QObject *, const QHashedV4String &, QQmlContextData *, QV4::QObjectWrapper::RevisionMode); inline bool setProperty(QObject *, const QHashedV4String &, QQmlContextData *, v8::Handle, QV4::QObjectWrapper::RevisionMode); private: @@ -219,18 +218,6 @@ private: QV8Engine *m_engine; }; -v8::Handle QV8QObjectWrapper::getProperty(QObject *object, const QHashedV4String &string, - QQmlContextData *context, QV4::QObjectWrapper::RevisionMode mode) -{ - QQmlData *dd = QQmlData::get(object, false); - if (!dd || !dd->propertyCache || - dd->propertyCache->property(string, object, context)) { - return GetProperty(m_engine, object, string, context, mode); - } else { - return v8::Handle(); - } -} - bool QV8QObjectWrapper::setProperty(QObject *object, const QHashedV4String &string, QQmlContextData *context, v8::Handle value, QV4::QObjectWrapper::RevisionMode mode) { -- 2.7.4