Fix bindings not being re-evaluated when changing context property
Commit 7cb6dce1f3
introduced an
optimization to remove bindings that after their initial evaluation had
no dependencies or errors (such as when accessing properties not set
yet). However when accessing a context property in a silent way -- using
typeof -- then no error state is set and the binding is removed. Any
later change of the context property results therefore in no binding
re-evaluation. This patch skips the optimization on bindings that are
associated with a context that has unresolved names. This fixes the
concrete bug at the expense of disabling further optimizations in the
context if other bindings access unresolved context properties. However
since context properties are discouraged anyway, this may be an
acceptable price to pay.
Change-Id: I95e120a4f71e8ebe0ec1fc44e8703c75f920dd28
Fixes: QTBUG-76796
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
2ca5ea6aaf
commit
cca5d1ec2f
|
@ -1353,7 +1353,8 @@ QQmlContextData *QQmlObjectCreator::finalize(QQmlInstantiationInterrupt &interru
|
|||
QQmlPropertyData::DontRemoveBinding);
|
||||
if (!b->isValueTypeProxy()) {
|
||||
QQmlBinding *binding = static_cast<QQmlBinding*>(b.data());
|
||||
if (!binding->hasError() && !binding->hasDependencies())
|
||||
if (!binding->hasError() && !binding->hasDependencies()
|
||||
&& binding->context() && !binding->context()->unresolvedNames)
|
||||
b->removeFromObject();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
import QtQml 2.0
|
||||
QtObject {
|
||||
property string testTypeOf: typeof(contextProp)
|
||||
}
|
|
@ -356,6 +356,7 @@ private slots:
|
|||
void callPropertyOnUndefined();
|
||||
void jumpStrictNotEqualUndefined();
|
||||
void removeBindingsWithNoDependencies();
|
||||
void preserveBindingWithUnresolvedNames();
|
||||
void temporaryDeadZone();
|
||||
void importLexicalVariables_data();
|
||||
void importLexicalVariables();
|
||||
|
@ -8815,6 +8816,18 @@ void tst_qqmlecmascript::removeBindingsWithNoDependencies()
|
|||
|
||||
}
|
||||
|
||||
void tst_qqmlecmascript::preserveBindingWithUnresolvedNames()
|
||||
{
|
||||
QQmlEngine engine;
|
||||
QQmlComponent component(&engine, testFileUrl("preserveBindingWithUnresolvedNames.qml"));
|
||||
QScopedPointer<QObject> object(component.create());
|
||||
QVERIFY(!object.isNull());
|
||||
QCOMPARE(object->property("testTypeOf").toString(), QString("undefined"));
|
||||
QObject obj;
|
||||
engine.rootContext()->setContextProperty("contextProp", &obj);
|
||||
QCOMPARE(object->property("testTypeOf").toString(), QString("object"));
|
||||
}
|
||||
|
||||
void tst_qqmlecmascript::temporaryDeadZone()
|
||||
{
|
||||
QJSEngine engine;
|
||||
|
|
Loading…
Reference in New Issue