From a4852b1ee77a913f6cc4806e6606c1b720e8f40b Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 4 Sep 2018 10:25:37 +0200 Subject: Fix error reporting when imports or re-exports in modules fail Collect the location of the import/export statement and include it in the exception thrown. Change-Id: I7966dfd53ed67d2d7087acde2dd8ff67c64cb044 Reviewed-by: Lars Knoll --- tests/auto/qml/qjsengine/exporterror1.mjs | 2 ++ tests/auto/qml/qjsengine/importerror1.mjs | 2 ++ tests/auto/qml/qjsengine/qjsengine.pro | 2 +- tests/auto/qml/qjsengine/tst_qjsengine.cpp | 17 +++++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qml/qjsengine/exporterror1.mjs create mode 100644 tests/auto/qml/qjsengine/importerror1.mjs (limited to 'tests') diff --git a/tests/auto/qml/qjsengine/exporterror1.mjs b/tests/auto/qml/qjsengine/exporterror1.mjs new file mode 100644 index 0000000000..9ce9aa3b83 --- /dev/null +++ b/tests/auto/qml/qjsengine/exporterror1.mjs @@ -0,0 +1,2 @@ +let dummy = 0; +export { nothere } from "./testmodule.mjs"; diff --git a/tests/auto/qml/qjsengine/importerror1.mjs b/tests/auto/qml/qjsengine/importerror1.mjs new file mode 100644 index 0000000000..be33753c56 --- /dev/null +++ b/tests/auto/qml/qjsengine/importerror1.mjs @@ -0,0 +1,2 @@ +let dummy = 0; +import { nothere } from "./testmodule.mjs"; diff --git a/tests/auto/qml/qjsengine/qjsengine.pro b/tests/auto/qml/qjsengine/qjsengine.pro index 1fb2d55b31..b412e37727 100644 --- a/tests/auto/qml/qjsengine/qjsengine.pro +++ b/tests/auto/qml/qjsengine/qjsengine.pro @@ -4,6 +4,6 @@ QT += qml qml-private widgets testlib gui-private macx:CONFIG -= app_bundle SOURCES += tst_qjsengine.cpp RESOURCES += qjsengine.qrc -RESOURCES += testmodule.mjs modulewithlexicals.mjs +RESOURCES += testmodule.mjs modulewithlexicals.mjs importerror1.mjs exporterror1.mjs TESTDATA = script/* diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index be62908772..6bc0359483 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -227,6 +227,7 @@ private slots: void importModule(); void importModuleRelative(); void importModuleWithLexicallyScopedVars(); + void importExportErrors(); public: Q_INVOKABLE QJSValue throwingCppMethod(); @@ -4404,6 +4405,22 @@ void tst_QJSEngine::importModuleWithLexicallyScopedVars() QCOMPARE(ns.property("main").call().toInt(), 10); } +void tst_QJSEngine::importExportErrors() +{ + { + QJSEngine engine; + QJSValue result = engine.importModule(QStringLiteral(":/importerror1.mjs")); + QVERIFY(result.isError()); + QCOMPARE(result.property("lineNumber").toInt(), 2); + } + { + QJSEngine engine; + QJSValue result = engine.importModule(QStringLiteral(":/exporterror1.mjs")); + QVERIFY(result.isError()); + QCOMPARE(result.property("lineNumber").toInt(), 2); + } +} + QTEST_MAIN(tst_QJSEngine) #include "tst_qjsengine.moc" -- cgit v1.2.3