diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2014-08-28 13:12:53 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@digia.com> | 2014-09-05 09:43:16 +0200 |
commit | f7c3035fa1d965dceb36892122683a5ceb6cab89 (patch) | |
tree | 94365c55f8a3dd6590edcd3ac5ec7149cea12e3e /tests | |
parent | 210475565969ca5381174016b47cd32ddc96eaed (diff) |
QML: parse .js files as JavaScript, not QML.
When importing a JS library into a QML file with the "import" keyword,
that JS file was parsed in QML mode, disallowing QML keywords like "as".
Task-number: QTBUG-40143
Change-Id: Ie98adceb27544732c2e96657d41170db36bff288
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests')
3 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/importScriptsWithoutQmlMode.js b/tests/auto/qml/qqmlecmascript/data/importScriptsWithoutQmlMode.js new file mode 100644 index 0000000000..aabcc9f3b8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/importScriptsWithoutQmlMode.js @@ -0,0 +1,7 @@ +.pragma library + +var as = undefined +function isLegal() { + var as = true; + return as; +} diff --git a/tests/auto/qml/qqmlecmascript/data/importScriptsWithoutQmlMode.qml b/tests/auto/qml/qqmlecmascript/data/importScriptsWithoutQmlMode.qml new file mode 100644 index 0000000000..17d12199d7 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/importScriptsWithoutQmlMode.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 + +import "importScriptsWithoutQmlMode.js" as Export + +Rectangle { + id: root + property bool success: false + + Component.onCompleted: success = Export.isLegal() +} diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 34413b23de..7e9adeadcc 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -321,6 +321,7 @@ private slots: void lazyBindingEvaluation(); void varPropertyAccessOnObjectWithInvalidContext(); void importedScriptsAccessOnObjectWithInvalidContext(); + void importedScriptsWithoutQmlMode(); void contextObjectOnLazyBindings(); void garbageCollectionDuringCreation(); @@ -7609,6 +7610,16 @@ void tst_qqmlecmascript::importedScriptsAccessOnObjectWithInvalidContext() QTRY_VERIFY(obj->property("success") == true); } +void tst_qqmlecmascript::importedScriptsWithoutQmlMode() +{ + QQmlComponent component(&engine, testFileUrl("importScriptsWithoutQmlMode.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")); |