summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/qdeclarativebinding.cpp5
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/deletedEngine.qml11
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp23
3 files changed, 36 insertions, 3 deletions
diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp
index b397177..6a99855 100644
--- a/src/declarative/qml/qdeclarativebinding.cpp
+++ b/src/declarative/qml/qdeclarativebinding.cpp
@@ -126,7 +126,7 @@ void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags)
QDeclarativeBindingData *data = d->bindingData();
- if (!data->enabled)
+ if (!data->enabled || !data->context() || !data->context()->engine)
return;
data->addref();
@@ -148,8 +148,7 @@ void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags)
idx, a);
} else {
- QDeclarativeEnginePrivate *ep = (data->context() && data->context()->engine)?
- QDeclarativeEnginePrivate::get(data->context()->engine):0;
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(data->context()->engine);
bool isUndefined = false;
QVariant value;
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/deletedEngine.qml b/tests/auto/declarative/qdeclarativeecmascript/data/deletedEngine.qml
new file mode 100644
index 0000000..6c538fe
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/deletedEngine.qml
@@ -0,0 +1,11 @@
+import Qt 4.6
+
+QtObject {
+ function calculate() {
+ return b * 13;
+ }
+
+ property int a: calculate()
+ property int b: 3
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index f675801..72f14f9 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -138,6 +138,7 @@ private slots:
void dynamicCreationCrash();
void regExpBug();
void nullObjectBinding();
+ void deletedEngine();
void callQtInvokables();
private:
@@ -2158,6 +2159,28 @@ void tst_qdeclarativeecmascript::nullObjectBinding()
delete object;
}
+// Test that bindings don't evaluate once the engine has been destroyed
+void tst_qdeclarativeecmascript::deletedEngine()
+{
+ QDeclarativeEngine *engine = new QDeclarativeEngine;
+ QDeclarativeComponent component(engine, TEST_FILE("deletedEngine.qml"));
+
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("a").toInt(), 39);
+ object->setProperty("b", QVariant(9));
+ QCOMPARE(object->property("a").toInt(), 117);
+
+ delete engine;
+
+ QCOMPARE(object->property("a").toInt(), 117);
+ object->setProperty("b", QVariant(10));
+ QCOMPARE(object->property("a").toInt(), 117);
+
+ delete object;
+}
+
QTEST_MAIN(tst_qdeclarativeecmascript)
#include "tst_qdeclarativeecmascript.moc"