aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqml.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-03-22 15:24:14 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-03-29 08:24:33 +0100
commita0499808be44ea15db53abf5091398ddd7c56de5 (patch)
tree361fd979386e5bf8ce640da547367929ef758e8f /src/qml/qml/qqml.cpp
parentda8776b98453ddbe08a08daf701a53fae9ede134 (diff)
Allow a bare lookup capture, without executing the lookup
This is useful when we know how to read the property directly. Change-Id: Ibc314a8e8bf9e51b3a15d934f6a1f17a53ea168a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src/qml/qml/qqml.cpp')
-rw-r--r--src/qml/qml/qqml.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/qml/qml/qqml.cpp b/src/qml/qml/qqml.cpp
index 26efb493d3..fa040e0604 100644
--- a/src/qml/qml/qqml.cpp
+++ b/src/qml/qml/qqml.cpp
@@ -49,7 +49,9 @@
#include <private/qqmltypemodule_p.h>
#include <private/qqmltypenotavailable_p.h>
#include <private/qqmlcomponent_p.h>
+#include <private/qqmltypewrapper_p.h>
#include <private/qv4lookup_p.h>
+#include <private/qv4qobjectwrapper_p.h>
#include <QtCore/qmutex.h>
@@ -704,6 +706,30 @@ QJSValue QQmlPrivate::AOTCompiledContext::loadQmlContextPropertyLookup(uint inde
l, engine->handle(), nullptr));
}
+bool QQmlPrivate::AOTCompiledContext::captureQmlContextPropertyLookup(uint index) const
+{
+ QV4::Lookup *l = compilationUnit->runtimeLookups + index;
+ if (l->qmlContextPropertyGetter != QV4::QQmlContextWrapper::lookupScopeObjectProperty
+ && l->qmlContextPropertyGetter != QV4::QQmlContextWrapper::lookupContextObjectProperty) {
+ return false;
+ }
+
+ const auto *property = l->qobjectLookup.propertyData;
+ Q_ASSERT(property);
+ if (property->isConstant())
+ return true;
+
+ if (QQmlEngine *engine = qmlContext->engine()) {
+ QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
+ if (!ep->propertyCapture)
+ return true;
+ ep->propertyCapture->captureProperty(qmlScopeObject, property->coreIndex(),
+ property->notifyIndex());
+ }
+
+ return true;
+}
+
QJSValue QQmlPrivate::AOTCompiledContext::callQmlContextPropertyLookup(
uint index, const QJSValueList &args) const
{
@@ -731,6 +757,31 @@ QJSValue QQmlPrivate::AOTCompiledContext::getLookup(uint index, const QJSValue &
QJSValuePrivate::convertToReturnedValue(engine->handle(), object)));
}
+bool QQmlPrivate::AOTCompiledContext::captureLookup(uint index, QObject *object) const
+{
+ QV4::Lookup *l = compilationUnit->runtimeLookups + index;
+ if (l->getter != QV4::QQmlTypeWrapper::lookupSingletonProperty
+ && l->getter != QV4::QObjectWrapper::lookupGetter) {
+ return false;
+ }
+
+ const auto *property = l->qobjectLookup.propertyData;
+ Q_ASSERT(property);
+ if (property->isConstant())
+ return true;
+
+ if (QQmlEngine *engine = qmlContext->engine()) {
+ QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
+ if (!ep->propertyCapture)
+ return true;
+ ep->propertyCapture->captureProperty(object, property->coreIndex(),
+ property->notifyIndex());
+ return true;
+ }
+
+ return false;
+}
+
void QQmlPrivate::AOTCompiledContext::setLookup(
uint index, const QJSValue &object, const QJSValue &value) const
{