aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4qmlcontext.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-05-04 22:28:08 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2021-05-05 13:34:51 +0200
commitf2aaa182528008bfa6b3859e98263fa9470b1594 (patch)
tree2377624e40cc6fa2ad81488a2d1a1640e34e5967 /src/qml/jsruntime/qv4qmlcontext.cpp
parentf617d739cbbb4bef0588bc4da765362c3486a742 (diff)
Use custom lookup for QJSValue singleton
There is no reason to branch in the getter, the type of the singleton cannot change as long as the lookup exists. Change-Id: I32534c505191d2da797cc94f536aa59e9b96e8ba Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4qmlcontext.cpp')
-rw-r--r--src/qml/jsruntime/qv4qmlcontext.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/qml/jsruntime/qv4qmlcontext.cpp b/src/qml/jsruntime/qv4qmlcontext.cpp
index e1eb7b7a86..65481e4539 100644
--- a/src/qml/jsruntime/qv4qmlcontext.cpp
+++ b/src/qml/jsruntime/qv4qmlcontext.cpp
@@ -232,6 +232,7 @@ ReturnedValue QQmlContextWrapper::getPropertyAndBase(const QQmlContextWrapper *r
return QV4::Encode::null();
} else if (r.type.isValid()) {
if (lookup) {
+ bool isValueSingleton = false;
if (r.type.isSingleton()) {
QQmlEnginePrivate *e = QQmlEnginePrivate::get(v4->qmlEngine());
if (r.type.isQObjectSingleton() || r.type.isCompositeSingleton()) {
@@ -251,9 +252,11 @@ ReturnedValue QQmlContextWrapper::getPropertyAndBase(const QQmlContextWrapper *r
lookup->qmlContextSingletonLookup.singletonObject = val->heapObject();
} else {
lookup->qmlContextSingletonLookup.singletonValue = QJSValuePrivate::asReturnedValue(&singleton);
+ isValueSingleton = true;
}
}
- lookup->qmlContextPropertyGetter = QQmlContextWrapper::lookupSingleton;
+ lookup->qmlContextPropertyGetter = isValueSingleton ? QQmlContextWrapper::lookupValueSingleton
+ : QQmlContextWrapper::lookupSingleton;
return lookup->qmlContextPropertyGetter(lookup, v4, base);
}
}
@@ -539,9 +542,15 @@ ReturnedValue QQmlContextWrapper::lookupSingleton(Lookup *l, ExecutionEngine *en
Q_UNUSED(engine);
Q_UNUSED(base);
- if (l->qmlContextSingletonLookup.singletonObject != nullptr)
- return l->qmlContextSingletonLookup.singletonObject->asReturnedValue();
+ return l->qmlContextSingletonLookup.singletonObject->asReturnedValue();
+}
+
+ReturnedValue QQmlContextWrapper::lookupValueSingleton(Lookup *l, ExecutionEngine *engine, Value *base)
+{
+ Q_UNUSED(engine);
+ Q_UNUSED(base);
+ Q_ASSERT(l->qmlContextSingletonLookup.singletonObject == nullptr);
return l->qmlContextSingletonLookup.singletonValue;
}