aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlbert Astals Cid <albert.astals@canonical.com>2014-03-20 16:28:15 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-24 11:40:10 +0100
commitfc45fd6983e12c2701b445dae1f3d99988091eac (patch)
tree8d4a29fd26d9c4ba9cf78d36bd9fc8e3178888a3 /tests
parentb3d8a4d47db63a06d354b6002ec764fd1442ec6e (diff)
Don't crash on Runtime::getQmlImportedScripts
Task-number: QTBUG-37303 Change-Id: I083ca0cc3223fe0dbf1c768ad43a0d4927579867 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlecmascript/data/Types.js3
-rw-r--r--tests/auto/qml/qqmlecmascript/data/importedScriptsAccessOnObjectWithInvalidContext.qml42
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp11
3 files changed, 56 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/Types.js b/tests/auto/qml/qqmlecmascript/data/Types.js
new file mode 100644
index 0000000000..8da80a9565
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/Types.js
@@ -0,0 +1,3 @@
+.pragma library
+
+var Foo = 0;
diff --git a/tests/auto/qml/qqmlecmascript/data/importedScriptsAccessOnObjectWithInvalidContext.qml b/tests/auto/qml/qqmlecmascript/data/importedScriptsAccessOnObjectWithInvalidContext.qml
new file mode 100644
index 0000000000..74310c6d6b
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/importedScriptsAccessOnObjectWithInvalidContext.qml
@@ -0,0 +1,42 @@
+import QtQuick 2.0
+
+import "Types.js" as Types
+
+Rectangle {
+ id: root
+ property bool success: false
+
+ color: "white"
+ height: 100
+ width: 100
+
+ signal modelChanged
+
+ Timer {
+ id: timer
+ interval: 100
+ onTriggered: {
+ root.modelChanged();
+ root.success = true;
+ }
+ }
+
+ Loader{
+ id: weekPage
+ sourceComponent: Component {
+ Item{
+ function createAllDayEvents() {
+ if (3 == Types.Foo) {
+ console.log("Hello")
+ }
+ }
+ }
+ }
+ onLoaded: root.modelChanged.connect(item.createAllDayEvents);
+ }
+
+ Component.onCompleted: {
+ weekPage.sourceComponent = null
+ timer.running = true
+ }
+}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 67c7dfb5b2..a1e36b42e6 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 importedScriptsAccessOnObjectWithInvalidContext();
void contextObjectOnLazyBindings();
private:
@@ -7580,6 +7581,16 @@ void tst_qqmlecmascript::varPropertyAccessOnObjectWithInvalidContext()
QVERIFY(obj->property("success") == true);
}
+void tst_qqmlecmascript::importedScriptsAccessOnObjectWithInvalidContext()
+{
+ QQmlComponent component(&engine, testFileUrl("importedScriptsAccessOnObjectWithInvalidContext.qml"));
+ QScopedPointer<QObject> obj(component.create());
+ if (obj.isNull())
+ qDebug() << component.errors().first().toString();
+ QVERIFY(!obj.isNull());
+ QTRY_VERIFY(obj->property("success") == true);
+}
+
void tst_qqmlecmascript::contextObjectOnLazyBindings()
{
QQmlComponent component(&engine, testFileUrl("contextObjectOnLazyBindings.qml"));