aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-03-17 14:42:05 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-17 15:45:45 +0100
commitacf1298e21abd2fb12d8364c593fbbff345374bc (patch)
tree30533bedc74cbf5f55ba767c34daa694e746c865 /tests
parent3f362cdf9304afeed06081cd5abfcaf6aaabe19e (diff)
Fix crash with lazy binding initialization and compile time calculated dependencies
During lazy binding initialization we may execute bindings where we calculated dependencies to the context object at compile time. In order to register those dependencies, the contet object needs to be set in the QQmlContextData. This patch makes sure to set it before setting up the bindings. Change-Id: Iacd360140cd9c389487bda82f6a7e6cc3a44c154 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlecmascript/data/SubObject.qml8
-rw-r--r--tests/auto/qml/qqmlecmascript/data/contextObjectOnLazyBindings.qml10
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp13
3 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/SubObject.qml b/tests/auto/qml/qqmlecmascript/data/SubObject.qml
new file mode 100644
index 0000000000..4658edd1db
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/SubObject.qml
@@ -0,0 +1,8 @@
+import QtQml 2.0
+QtObject {
+ property int testValue: -1
+ property int subValue;
+ onSubValueChanged: {
+ testValue = this.someExpression
+ }
+}
diff --git a/tests/auto/qml/qqmlecmascript/data/contextObjectOnLazyBindings.qml b/tests/auto/qml/qqmlecmascript/data/contextObjectOnLazyBindings.qml
new file mode 100644
index 0000000000..33b21c74a8
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/contextObjectOnLazyBindings.qml
@@ -0,0 +1,10 @@
+import QtQml 2.0
+QtObject {
+ property SubObject subObject: SubObject {
+ subValue: 20;
+ property int someExpression: {
+ return someValue;
+ }
+ }
+ property int someValue: 42
+}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index b6c564a6ce..085bf24430 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -320,6 +320,7 @@ private slots:
void singletonWithEnum();
void lazyBindingEvaluation();
void varPropertyAccessOnObjectWithInvalidContext();
+ void contextObjectOnLazyBindings();
private:
// static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
@@ -7579,6 +7580,18 @@ void tst_qqmlecmascript::varPropertyAccessOnObjectWithInvalidContext()
QVERIFY(obj->property("success") == true);
}
+void tst_qqmlecmascript::contextObjectOnLazyBindings()
+{
+ QQmlComponent component(&engine, testFileUrl("contextObjectOnLazyBindings.qml"));
+ QScopedPointer<QObject> obj(component.create());
+ if (obj.isNull())
+ qDebug() << component.errors().first().toString();
+ QVERIFY(!obj.isNull());
+ QObject *subObject = qvariant_cast<QObject*>(obj->property("subObject"));
+ QVERIFY(subObject);
+ QCOMPARE(subObject->property("testValue").toInt(), int(42));
+}
+
QTEST_MAIN(tst_qqmlecmascript)
#include "tst_qqmlecmascript.moc"