Get rid of QV8QObjectWrapper::getProperty
authorSimon Hausmann <simon.hausmann@digia.com>
Thu, 6 Jun 2013 12:52:07 +0000 (14:52 +0200)
committerLars Knoll <lars.knoll@digia.com>
Fri, 7 Jun 2013 16:32:55 +0000 (18:32 +0200)
Replace the call sites with calls to getQmlProperty on the QObjectWrapper.

Change-Id: I3dbc3788c8d1631d817f65c738f0a8a31deb2866
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/qml/qqmlcontextwrapper.cpp
src/qml/qml/qqmltypewrapper.cpp
src/qml/qml/qqmlvaluetypewrapper.cpp
src/qml/qml/v8/qv8qobjectwrapper.cpp
src/qml/qml/v8/qv8qobjectwrapper_p.h

index 4d8a8ac..dd7d28c 100644 (file)
@@ -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<QV4::QObjectWrapper>()) {
                 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<QV4::QObjectWrapper>()) {
+                bool hasProp = false;
+                QV4::Value result = o->getQmlProperty(ctx, context, name, QV4::QObjectWrapper::CheckRevision, &hasProp);
+                if (hasProp) {
+                    if (hasProperty)
+                        *hasProperty = true;
+                    return result;
+                }
             }
         }
 
index 5074590..e98117e 100644 (file)
@@ -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<QV4::QObjectWrapper>())
+                    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<QV4::QObjectWrapper>();
+                    if (wrapper)
+                        return wrapper->getQmlProperty(ctx, context, name, QV4::QObjectWrapper::IgnoreRevision);
+                }
 
                 // Fall through to base implementation
             }
index abf0be7..955ea04 100644 (file)
@@ -45,6 +45,7 @@
 #include <private/qqmlvaluetype_p.h>
 #include <private/qqmlbinding_p.h>
 #include <private/qqmlglobal_p.h>
+#include <private/qqmlcontextwrapper_p.h>
 
 #include <private/qv4engine_p.h>
 #include <private/qv4functionobject_p.h>
@@ -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<QV4::QObjectWrapper>()->getQmlProperty(ctx, qmlContext, name, QV4::QObjectWrapper::IgnoreRevision);
     }
 
 #define VALUE_TYPE_LOAD(metatype, cpptype, constructor) \
index 32d08c3..4ce860e 100644 (file)
@@ -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<v8::Value> result = QV8QObjectWrapper::GetProperty(v8Engine, m_object, propertystring, context, revisionMode);
+    v8::Handle<v8::Value> 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<QObjectWrapper*>(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)
index e06ce49..fe8ff38 100644 (file)
@@ -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<v8::Value> getProperty(QObject *, const QHashedV4String &, QQmlContextData *, QV4::QObjectWrapper::RevisionMode);
     inline bool setProperty(QObject *, const QHashedV4String &, QQmlContextData *, v8::Handle<v8::Value>, QV4::QObjectWrapper::RevisionMode);
 
 private:
@@ -219,18 +218,6 @@ private:
     QV8Engine *m_engine;
 };
 
-v8::Handle<v8::Value> 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<v8::Value>();
-    }
-}
-
 bool QV8QObjectWrapper::setProperty(QObject *object, const QHashedV4String &string,
                                     QQmlContextData *context, v8::Handle<v8::Value> value, QV4::QObjectWrapper::RevisionMode mode)
 {