Fix regression against 4.7
authorAaron Kennedy <aaron.kennedy@nokia.com>
Thu, 23 Jun 2011 01:20:00 +0000 (11:20 +1000)
committerAaron Kennedy <aaron.kennedy@nokia.com>
Thu, 23 Jun 2011 01:20:00 +0000 (11:20 +1000)
Task-number: QTBUG-19136

src/declarative/qml/qdeclarativevme.cpp
tests/auto/declarative/qdeclarativeecmascript/data/importScope.1.js [new file with mode: 0644]
tests/auto/declarative/qdeclarativeecmascript/data/importScope.2.js [new file with mode: 0644]
tests/auto/declarative/qdeclarativeecmascript/data/importScope.qml [new file with mode: 0644]
tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp

index a9b303c..8959f17 100644 (file)
@@ -988,6 +988,7 @@ QScriptValue QDeclarativeVME::run(QDeclarativeContextData *parentCtxt, QDeclarat
             ctxt->imports = script->importCache;
         } else {
             ctxt->imports = parentCtxt->imports;
+            ctxt->importedScripts = parentCtxt->importedScripts;
         }
 
         if (ctxt->imports) {
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/importScope.1.js b/tests/auto/declarative/qdeclarativeecmascript/data/importScope.1.js
new file mode 100644 (file)
index 0000000..4c556f9
--- /dev/null
@@ -0,0 +1 @@
+var value = 240
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/importScope.2.js b/tests/auto/declarative/qdeclarativeecmascript/data/importScope.2.js
new file mode 100644 (file)
index 0000000..291fb9d
--- /dev/null
@@ -0,0 +1,3 @@
+function getValue() {
+    return ImportScope1.value
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/importScope.qml b/tests/auto/declarative/qdeclarativeecmascript/data/importScope.qml
new file mode 100644 (file)
index 0000000..a72847f
--- /dev/null
@@ -0,0 +1,7 @@
+import QtQuick 1.0
+import "importScope.1.js" as ImportScope1
+import "importScope.2.js" as ImportScope2
+
+QtObject {
+    property int test: ImportScope2.getValue()
+}
index cabadde..3c4c336 100644 (file)
@@ -108,6 +108,7 @@ private slots:
     void aliasPropertyAndBinding();
     void nonExistentAttachedObject();
     void scope();
+    void importScope();
     void signalParameterTypes();
     void objectsCompareAsEqual();
     void dynamicCreation_data();
@@ -959,6 +960,19 @@ void tst_qdeclarativeecmascript::scope()
     }
 }
 
+// In 4.7, non-library javascript files that had no imports shared the imports of their
+// importing context
+void tst_qdeclarativeecmascript::importScope()
+{
+    QDeclarativeComponent component(&engine, TEST_FILE("importScope.qml"));
+    QObject *o = component.create();
+    QVERIFY(o != 0);
+
+    QCOMPARE(o->property("test").toInt(), 240);
+
+    delete o;
+}
+
 /*
 Tests that "any" type passes through a synthesized signal parameter.  This
 is essentially a test of QDeclarativeMetaType::copy()