From 01bbd7e41ac8444d2282ac6ca1862c3748f685a1 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Fri, 3 Jan 2020 10:32:01 +0100 Subject: QV4::ExecutionEngine: provide QNAM accessor In XMLHttpRequest, we need to get the QNetworkAccessManager from the engine. However, if the request originates from a WorkerScript, there exists no qmlEngine. We therefore add a new indirection to access the QNAM, and set it up accordinly in registerWorkerScript. Fixes: QTBUG-81055 Change-Id: I8915202b6d6b7139c8386304b3d1d7a22a82045e Reviewed-by: Simon Hausmann --- tests/auto/qml/qquickworkerscript/data/doRequest.mjs | 6 ++++++ .../auto/qml/qquickworkerscript/data/xmlHttpRequest.qml | 16 ++++++++++++++++ .../qml/qquickworkerscript/tst_qquickworkerscript.cpp | 8 ++++++++ 3 files changed, 30 insertions(+) create mode 100644 tests/auto/qml/qquickworkerscript/data/doRequest.mjs create mode 100644 tests/auto/qml/qquickworkerscript/data/xmlHttpRequest.qml (limited to 'tests') diff --git a/tests/auto/qml/qquickworkerscript/data/doRequest.mjs b/tests/auto/qml/qquickworkerscript/data/doRequest.mjs new file mode 100644 index 0000000000..d607c3400d --- /dev/null +++ b/tests/auto/qml/qquickworkerscript/data/doRequest.mjs @@ -0,0 +1,6 @@ +WorkerScript.onMessage = function(message) +{ + var req = new XMLHttpRequest(); + req.open("GET", message.url, true); + req.send(); +}; diff --git a/tests/auto/qml/qquickworkerscript/data/xmlHttpRequest.qml b/tests/auto/qml/qquickworkerscript/data/xmlHttpRequest.qml new file mode 100644 index 0000000000..42136d78f0 --- /dev/null +++ b/tests/auto/qml/qquickworkerscript/data/xmlHttpRequest.qml @@ -0,0 +1,16 @@ +import QtQuick 2.14 + +Rectangle +{ + width: 100 + height: 100 + + WorkerScript + { + source: "doRequest.mjs" + Component.onCompleted: + { + sendMessage({"url": "https://example.com"}); + } + } +} diff --git a/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp b/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp index bea9978f0b..d11e7bde4b 100644 --- a/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp +++ b/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp @@ -59,6 +59,7 @@ private slots: void script_function(); void script_var(); void stressDispose(); + void xmlHttpRequest(); private: void waitForEchoMessage(QQuickWorkerScript *worker) { @@ -341,6 +342,13 @@ void tst_QQuickWorkerScript::stressDispose() } } +void tst_QQuickWorkerScript::xmlHttpRequest() +{ + QQmlComponent component(&m_engine, testFileUrl("xmlHttpRequest.qml")); + QScopedPointer root{component.create()}; // should not crash + QVERIFY(root); +} + QTEST_MAIN(tst_QQuickWorkerScript) #include "tst_qquickworkerscript.moc" -- cgit v1.2.3