From 4b73fc5bd2fd3df10f1e7499c82da08fbd417055 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 17 Aug 2018 16:53:05 +0200 Subject: Add support for ECMASCript modules in WorkerScript elements Similar to script imports from .qml files, the .mjs extension is used to distinguish between ES modules and plain script files. Change-Id: Id5f9b59fb77e99e3c9d6a404e6d091d96b501ad6 Reviewed-by: Mitch Curtis Reviewed-by: Lars Knoll --- .../qquickworkerscript/tst_qquickworkerscript.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp') diff --git a/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp b/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp index e21a53b4f3..4ad58ba56c 100644 --- a/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp +++ b/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp @@ -77,24 +77,30 @@ private: void tst_QQuickWorkerScript::source() { QQmlComponent component(&m_engine, testFileUrl("worker.qml")); - QQuickWorkerScript *worker = qobject_cast(component.create()); + QScopedPointerworker(qobject_cast(component.create())); QVERIFY(worker != nullptr); const QMetaObject *mo = worker->metaObject(); QVariant value(100); - QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value))); - waitForEchoMessage(worker); - QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value(), value); + QVERIFY(QMetaObject::invokeMethod(worker.data(), "testSend", Q_ARG(QVariant, value))); + waitForEchoMessage(worker.data()); + QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker.data()).value(), value); QUrl source = testFileUrl("script_fixed_return.js"); worker->setSource(source); QCOMPARE(worker->source(), source); - QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value))); - waitForEchoMessage(worker); - QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value(), qVariantFromValue(QString("Hello_World"))); + QVERIFY(QMetaObject::invokeMethod(worker.data(), "testSend", Q_ARG(QVariant, value))); + waitForEchoMessage(worker.data()); + QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker.data()).value(), qVariantFromValue(QString("Hello_World"))); + + source = testFileUrl("script_module.mjs"); + worker->setSource(source); + QCOMPARE(worker->source(), source); + QVERIFY(QMetaObject::invokeMethod(worker.data(), "testSend", Q_ARG(QVariant, value))); + waitForEchoMessage(worker.data()); + QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker.data()).value(), qVariantFromValue(QString("Hello from the module"))); qApp->processEvents(); - delete worker; } void tst_QQuickWorkerScript::messaging() -- cgit v1.2.3