Move the registerQmlDependencies method into QQmlPropertyCapture
authorLars Knoll <lars.knoll@theqtcompany.com>
Wed, 12 Aug 2015 12:02:19 +0000 (14:02 +0200)
committerLars Knoll <lars.knoll@theqtcompany.com>
Thu, 20 Aug 2015 20:01:21 +0000 (20:01 +0000)
This is where the method logically belongs, and removes one more
thing from the context wrapper.

Change-Id: Ibc076c9b31903a484ad4517402eca2a3b7f0d660
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
src/qml/jsruntime/qv4functionobject.cpp
src/qml/qml/qqmlcontextwrapper.cpp
src/qml/qml/qqmlcontextwrapper_p.h
src/qml/qml/qqmljavascriptexpression.cpp
src/qml/qml/qqmljavascriptexpression_p.h

index da01592..6412e65 100644 (file)
@@ -46,7 +46,7 @@
 #include <private/qqmljslexer_p.h>
 #include <private/qqmljsparser_p.h>
 #include <private/qqmljsast_p.h>
-#include <private/qqmlcontextwrapper_p.h>
+#include <private/qqmljavascriptexpression_p.h>
 #include <private/qqmlengine_p.h>
 #include <qv4codegen_p.h>
 #include "private/qlocale_tools_p.h"
@@ -430,7 +430,7 @@ ReturnedValue ScriptFunction::construct(const Managed *that, CallData *callData)
     ScopedValue result(scope, Q_V4_PROFILE(v4, f->function()));
 
     if (f->function()->compiledFunction->hasQmlDependencies())
-        QmlContextWrapper::registerQmlDependencies(v4, f->function()->compiledFunction);
+        QQmlPropertyCapture::registerQmlDependencies(v4, f->function()->compiledFunction);
 
     if (v4->hasException)
         return Encode::undefined();
@@ -457,7 +457,7 @@ ReturnedValue ScriptFunction::call(const Managed *that, CallData *callData)
     ScopedValue result(scope, Q_V4_PROFILE(v4, f->function()));
 
     if (f->function()->compiledFunction->hasQmlDependencies())
-        QmlContextWrapper::registerQmlDependencies(scope.engine, f->function()->compiledFunction);
+        QQmlPropertyCapture::registerQmlDependencies(scope.engine, f->function()->compiledFunction);
 
     return result->asReturnedValue();
 }
@@ -531,7 +531,7 @@ ReturnedValue SimpleScriptFunction::construct(const Managed *that, CallData *cal
     ScopedObject result(scope, Q_V4_PROFILE(v4, f->function()));
 
     if (f->function()->compiledFunction->hasQmlDependencies())
-        QmlContextWrapper::registerQmlDependencies(v4, f->function()->compiledFunction);
+        QQmlPropertyCapture::registerQmlDependencies(v4, f->function()->compiledFunction);
 
     if (!result)
         return callData->thisObject.asReturnedValue();
@@ -569,7 +569,7 @@ ReturnedValue SimpleScriptFunction::call(const Managed *that, CallData *callData
     ScopedValue result(scope, Q_V4_PROFILE(v4, f->function()));
 
     if (f->function()->compiledFunction->hasQmlDependencies())
-        QmlContextWrapper::registerQmlDependencies(v4, f->function()->compiledFunction);
+        QQmlPropertyCapture::registerQmlDependencies(v4, f->function()->compiledFunction);
 
     return result->asReturnedValue();
 }
index 23084fb..be06c59 100644 (file)
@@ -323,49 +323,6 @@ void QmlContextWrapper::put(Managed *m, String *name, const Value &value)
     Object::put(m, name, value);
 }
 
-void QmlContextWrapper::registerQmlDependencies(ExecutionEngine *engine, const CompiledData::Function *compiledFunction)
-{
-    // Let the caller check and avoid the function call :)
-    Q_ASSERT(compiledFunction->hasQmlDependencies());
-
-    QQmlEnginePrivate *ep = engine->qmlEngine() ? QQmlEnginePrivate::get(engine->qmlEngine()) : 0;
-    if (!ep)
-        return;
-    QQmlPropertyCapture *capture = ep->propertyCapture;
-    if (!capture)
-        return;
-
-    QV4::Scope scope(engine);
-    QV4::Scoped<QmlContext> context(scope, engine->qmlContext());
-    QQmlContextData *qmlContext = context->qmlContext();
-
-    const quint32 *idObjectDependency = compiledFunction->qmlIdObjectDependencyTable();
-    const int idObjectDependencyCount = compiledFunction->nDependingIdObjects;
-    for (int i = 0; i < idObjectDependencyCount; ++i, ++idObjectDependency) {
-        Q_ASSERT(int(*idObjectDependency) < qmlContext->idValueCount);
-        capture->captureProperty(&qmlContext->idValues[*idObjectDependency].bindings);
-    }
-
-    Q_ASSERT(qmlContext->contextObject);
-    const quint32 *contextPropertyDependency = compiledFunction->qmlContextPropertiesDependencyTable();
-    const int contextPropertyDependencyCount = compiledFunction->nDependingContextProperties;
-    for (int i = 0; i < contextPropertyDependencyCount; ++i) {
-        const int propertyIndex = *contextPropertyDependency++;
-        const int notifyIndex = *contextPropertyDependency++;
-        capture->captureProperty(qmlContext->contextObject, propertyIndex, notifyIndex);
-    }
-
-    QObject *scopeObject = context->qmlScope();
-    const quint32 *scopePropertyDependency = compiledFunction->qmlScopePropertiesDependencyTable();
-    const int scopePropertyDependencyCount = compiledFunction->nDependingScopeProperties;
-    for (int i = 0; i < scopePropertyDependencyCount; ++i) {
-        const int propertyIndex = *scopePropertyDependency++;
-        const int notifyIndex = *scopePropertyDependency++;
-        capture->captureProperty(scopeObject, propertyIndex, notifyIndex);
-    }
-
-}
-
 ReturnedValue QmlContextWrapper::qmlSingletonWrapper(ExecutionEngine *v4, String *name)
 {
     if (!d()->context->imports)
index 7b5d321..d7a4a10 100644 (file)
@@ -99,8 +99,6 @@ struct Q_QML_EXPORT QmlContextWrapper : Object
     static ReturnedValue get(const Managed *m, String *name, bool *hasProperty);
     static void put(Managed *m, String *name, const Value &value);
 
-    static void registerQmlDependencies(ExecutionEngine *context, const CompiledData::Function *compiledFunction);
-
     ReturnedValue qmlSingletonWrapper(ExecutionEngine *e, String *name);
 };
 
index 5f30eac..967a7e7 100644 (file)
@@ -287,6 +287,50 @@ void QQmlPropertyCapture::captureProperty(QObject *o, int c, int n)
     }
 }
 
+void QQmlPropertyCapture::registerQmlDependencies(QV4::ExecutionEngine *engine, const QV4::CompiledData::Function *compiledFunction)
+{
+    // Let the caller check and avoid the function call :)
+    Q_ASSERT(compiledFunction->hasQmlDependencies());
+
+    QQmlEnginePrivate *ep = engine->qmlEngine() ? QQmlEnginePrivate::get(engine->qmlEngine()) : 0;
+    if (!ep)
+        return;
+    QQmlPropertyCapture *capture = ep->propertyCapture;
+    if (!capture)
+        return;
+
+    QV4::Scope scope(engine);
+    QV4::Scoped<QV4::QmlContext> context(scope, engine->qmlContext());
+    QQmlContextData *qmlContext = context->qmlContext();
+
+    const quint32 *idObjectDependency = compiledFunction->qmlIdObjectDependencyTable();
+    const int idObjectDependencyCount = compiledFunction->nDependingIdObjects;
+    for (int i = 0; i < idObjectDependencyCount; ++i, ++idObjectDependency) {
+        Q_ASSERT(int(*idObjectDependency) < qmlContext->idValueCount);
+        capture->captureProperty(&qmlContext->idValues[*idObjectDependency].bindings);
+    }
+
+    Q_ASSERT(qmlContext->contextObject);
+    const quint32 *contextPropertyDependency = compiledFunction->qmlContextPropertiesDependencyTable();
+    const int contextPropertyDependencyCount = compiledFunction->nDependingContextProperties;
+    for (int i = 0; i < contextPropertyDependencyCount; ++i) {
+        const int propertyIndex = *contextPropertyDependency++;
+        const int notifyIndex = *contextPropertyDependency++;
+        capture->captureProperty(qmlContext->contextObject, propertyIndex, notifyIndex);
+    }
+
+    QObject *scopeObject = context->qmlScope();
+    const quint32 *scopePropertyDependency = compiledFunction->qmlScopePropertiesDependencyTable();
+    const int scopePropertyDependencyCount = compiledFunction->nDependingScopeProperties;
+    for (int i = 0; i < scopePropertyDependencyCount; ++i) {
+        const int propertyIndex = *scopePropertyDependency++;
+        const int notifyIndex = *scopePropertyDependency++;
+        capture->captureProperty(scopeObject, propertyIndex, notifyIndex);
+    }
+
+}
+
+
 void QQmlJavaScriptExpression::clearError()
 {
     if (m_error)
index dfcf8b2..f0a3741 100644 (file)
@@ -176,6 +176,8 @@ public:
     void captureProperty(QQmlNotifier *);
     void captureProperty(QObject *, int, int);
 
+    static void registerQmlDependencies(QV4::ExecutionEngine *engine, const QV4::CompiledData::Function *compiledFunction);
+
     QQmlEngine *engine;
     QQmlJavaScriptExpression *expression;
     QQmlJavaScriptExpression::DeleteWatcher *watcher;