summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/kernel/qeventdispatcher_wasm.cpp23
-rw-r--r--src/corelib/platform/wasm/qstdweb.cpp6
-rw-r--r--src/corelib/platform/wasm/qstdweb_p.h2
-rw-r--r--tests/manual/wasm/eventloop/eventloop_auto/CMakeLists.txt2
-rw-r--r--tests/manual/wasm/eventloop/eventloop_auto/main.cpp13
5 files changed, 23 insertions, 23 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_wasm.cpp b/src/corelib/kernel/qeventdispatcher_wasm.cpp
index a2248676b5..23f218c4a0 100644
--- a/src/corelib/kernel/qeventdispatcher_wasm.cpp
+++ b/src/corelib/kernel/qeventdispatcher_wasm.cpp
@@ -7,6 +7,7 @@
#include <QtCore/qcoreapplication.h>
#include <QtCore/qthread.h>
#include <QtCore/qsocketnotifier.h>
+#include <QtCore/private/qstdweb_p.h>
#include "emscripten.h"
#include <emscripten/html5.h>
@@ -34,9 +35,10 @@ static bool g_is_asyncify_suspended = false;
#if defined(QT_STATIC)
-EM_JS(bool, qt_have_asyncify_js, (), {
- return typeof Asyncify != "undefined";
-});
+static bool useAsyncify()
+{
+ return qstdweb::haveAsyncify();
+}
EM_JS(void, qt_asyncify_suspend_js, (), {
let sleepFn = (wakeUp) => {
@@ -60,7 +62,7 @@ EM_JS(void, qt_asyncify_resume_js, (), {
// EM_JS is not supported for side modules; disable asyncify
-bool qt_have_asyncify_js()
+static bool useAsyncify()
{
return false;
}
@@ -77,15 +79,6 @@ void qt_asyncify_resume_js()
#endif // defined(QT_STATIC)
-// Returns true if asyncify is available.
-bool qt_have_asyncify()
-{
- static bool have_asyncify = []{
- return qt_have_asyncify_js();
- }();
- return have_asyncify;
-}
-
// Suspends the main thread until qt_asyncify_resume() is called. Returns
// false immediately if Qt has already suspended the main thread (recursive
// suspend is not supported by Emscripten). Returns true (after resuming),
@@ -391,7 +384,7 @@ void QEventDispatcherWasm::handleApplicationExec()
void QEventDispatcherWasm::handleDialogExec()
{
- if (!qt_have_asyncify()) {
+ if (!useAsyncify()) {
qWarning() << "Warning: exec() is not supported on Qt for WebAssembly in this configuration. Please build"
<< "with asyncify support, or use an asynchronous API like QDialog::open()";
emscripten_sleep(1); // This call never returns
@@ -420,7 +413,7 @@ bool QEventDispatcherWasm::wait(int timeout)
#endif
Q_ASSERT(emscripten_is_main_runtime_thread());
Q_ASSERT(isMainThreadEventDispatcher());
- if (qt_have_asyncify()) {
+ if (useAsyncify()) {
if (timeout > 0)
qWarning() << "QEventDispatcherWasm asyncify wait with timeout is not supported; timeout will be ignored"; // FIXME
diff --git a/src/corelib/platform/wasm/qstdweb.cpp b/src/corelib/platform/wasm/qstdweb.cpp
index 3a3cf4ada6..bead64f97d 100644
--- a/src/corelib/platform/wasm/qstdweb.cpp
+++ b/src/corelib/platform/wasm/qstdweb.cpp
@@ -667,6 +667,12 @@ namespace Promise {
}
}
+bool haveAsyncify()
+{
+ static bool HaveAsyncify = !emscripten::val::global("Asyncify").isUndefined();
+ return HaveAsyncify;
+}
+
} // namespace qstdweb
QT_END_NAMESPACE
diff --git a/src/corelib/platform/wasm/qstdweb_p.h b/src/corelib/platform/wasm/qstdweb_p.h
index e3c60b7188..badca5d402 100644
--- a/src/corelib/platform/wasm/qstdweb_p.h
+++ b/src/corelib/platform/wasm/qstdweb_p.h
@@ -189,6 +189,8 @@ namespace qstdweb {
static emscripten::val savedWindow = emscripten::val::global("window");
return savedWindow;
}
+
+ bool haveAsyncify();
}
QT_END_NAMESPACE
diff --git a/tests/manual/wasm/eventloop/eventloop_auto/CMakeLists.txt b/tests/manual/wasm/eventloop/eventloop_auto/CMakeLists.txt
index f8669c2030..9bfa875be7 100644
--- a/tests/manual/wasm/eventloop/eventloop_auto/CMakeLists.txt
+++ b/tests/manual/wasm/eventloop/eventloop_auto/CMakeLists.txt
@@ -7,6 +7,7 @@ qt_internal_add_manual_test(eventloop_auto
../../qtwasmtestlib/qtwasmtestlib.cpp
LIBRARIES
Qt::Core
+ Qt::CorePrivate
)
add_custom_command(
@@ -28,6 +29,7 @@ qt_internal_add_manual_test(eventloop_auto_asyncify
../../qtwasmtestlib/qtwasmtestlib.cpp
LIBRARIES
Qt::Core
+ Qt::CorePrivate
)
target_link_options(eventloop_auto_asyncify PRIVATE -sASYNCIFY -Os)
diff --git a/tests/manual/wasm/eventloop/eventloop_auto/main.cpp b/tests/manual/wasm/eventloop/eventloop_auto/main.cpp
index b6de2310ad..b2ff6779fd 100644
--- a/tests/manual/wasm/eventloop/eventloop_auto/main.cpp
+++ b/tests/manual/wasm/eventloop/eventloop_auto/main.cpp
@@ -7,6 +7,7 @@
#include <QtCore/QObject>
#include <QtCore/QThread>
#include <QtCore/QTimer>
+#include <QtCore/private/qstdweb_p.h>
#include <qtwasmtestlib.h>
@@ -14,10 +15,6 @@
const int timerTimeout = 10;
-EM_JS(bool, have_asyncify, (), {
- return typeof Asyncify != "undefined";
-});
-
class WasmEventDispatcherTest: public QObject
{
Q_OBJECT
@@ -242,7 +239,7 @@ void WasmEventDispatcherTest::timerSecondaryThread()
// Post an event to the main thread and asyncify wait for it
void WasmEventDispatcherTest::postEventAsyncify()
{
- if (!have_asyncify()) {
+ if (!qstdweb::haveAsyncify()) {
QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify");
return;
}
@@ -259,7 +256,7 @@ void WasmEventDispatcherTest::postEventAsyncify()
// Create a timer on the main thread and asyncify wait for it
void WasmEventDispatcherTest::timerAsyncify()
{
- if (!have_asyncify()) {
+ if (!qstdweb::haveAsyncify()) {
QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify");
return;
}
@@ -276,7 +273,7 @@ void WasmEventDispatcherTest::timerAsyncify()
// Asyncify wait in a loop
void WasmEventDispatcherTest::postEventAsyncifyLoop()
{
- if (!have_asyncify()) {
+ if (!qstdweb::haveAsyncify()) {
QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify");
return;
}
@@ -296,7 +293,7 @@ void WasmEventDispatcherTest::postEventAsyncifyLoop()
// Asyncify wait for QThread::wait() / pthread_join()
void WasmEventDispatcherTest::threadAsyncifyWait()
{
- if (!have_asyncify())
+ if (!qstdweb::haveAsyncify())
QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify");
const int threadCount = 15;