diff options
author | Morten Johan Sørvig <morten.sorvig@qt.io> | 2018-06-01 15:13:30 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2018-08-30 06:48:33 +0000 |
commit | 29c0377f07f4942f9957ea87d59c252148dc9e5b (patch) | |
tree | cb79a59b6c47305ca024675cc1325ed0a6be8aac /src/corelib/kernel | |
parent | 707ae5b66774a2ed4713da3b8fa69c1d002c3beb (diff) |
WebAssembly for QtBase
This is the squashed diff from wip/webassembly to dev.
Done-with: Peng Wu <peng.wu@intopalo.com>
Done-with: Sami Enne <sami.enne@intopalo.com>
Done-with: Morten Johan Sørvig <morten.sorvig@qt.io>
Started-by: Andrew Knight <andrew.knight@intopalo.com>
Change-Id: I6562433c0a38d6ec49ab675e0f104f2665f3392d
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qcoreapplication.cpp | 22 | ||||
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_unix.cpp | 2 | ||||
-rw-r--r-- | src/corelib/kernel/qeventloop.cpp | 24 |
3 files changed, 47 insertions, 1 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 0303916c11..1350a7aa94 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -118,6 +118,10 @@ # include <taskLib.h> #endif +#ifdef Q_OS_WASM +#include <emscripten.h> +#endif + #ifdef QT_BOOTSTRAPPED #include <private/qtrace_p.h> #else @@ -486,6 +490,13 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint QCoreApplicationPrivate::~QCoreApplicationPrivate() { +#ifdef Q_OS_WASM + EM_ASM( + // unmount persistent directory as IDBFS + // see also QTBUG-70002 + FS.unmount('/home/web_user'); + ); +#endif #ifndef QT_NO_QOBJECT cleanupThreadData(); #endif @@ -777,6 +788,17 @@ void QCoreApplicationPrivate::init() Q_ASSERT_X(!QCoreApplication::self, "QCoreApplication", "there should be only one application object"); QCoreApplication::self = q; +#ifdef Q_OS_WASM + EM_ASM( + // mount and sync persistent filesystem to sandbox + FS.mount(IDBFS, {}, '/home/web_user'); + FS.syncfs(true, function(err) { + if (err) + Module.print(err); + }); + ); +#endif + // Store app name/version (so they're still available after QCoreApplication is destroyed) if (!coreappdata()->applicationNameSet) coreappdata()->application = appName(); diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp index a28f2e3f0a..535f86fefe 100644 --- a/src/corelib/kernel/qeventdispatcher_unix.cpp +++ b/src/corelib/kernel/qeventdispatcher_unix.cpp @@ -130,7 +130,7 @@ static void initThreadPipeFD(int fd) bool QThreadPipe::init() { -#if defined(Q_OS_NACL) +#if defined(Q_OS_NACL) || defined(Q_OS_WASM) // do nothing. #elif defined(Q_OS_VXWORKS) qsnprintf(name, sizeof(name), "/pipe/qt_%08x", int(taskIdSelf())); diff --git a/src/corelib/kernel/qeventloop.cpp b/src/corelib/kernel/qeventloop.cpp index f1d32b15d1..a6cc51621a 100644 --- a/src/corelib/kernel/qeventloop.cpp +++ b/src/corelib/kernel/qeventloop.cpp @@ -48,6 +48,10 @@ #include "qeventloop_p.h" #include <private/qthread_p.h> +#ifdef Q_OS_WASM +#include <emscripten.h> +#endif + QT_BEGIN_NAMESPACE /*! @@ -208,6 +212,15 @@ int QEventLoop::exec(ProcessEventsFlags flags) if (app && app->thread() == thread()) QCoreApplication::removePostedEvents(app, QEvent::Quit); +#ifdef Q_OS_WASM + // Partial support for nested event loops: Make the runtime throw a JavaSrcript + // exception, which returns control to the browser while preserving the C++ stack. + // Event processing then continues as normal. The sleep call below never returns. + // QTBUG-70185 + if (d->threadData->loopLevel > 1) + emscripten_sleep(1); +#endif + while (!d->exit.loadAcquire()) processEvents(flags | WaitForMoreEvents | EventLoopExec); @@ -269,6 +282,17 @@ void QEventLoop::exit(int returnCode) d->returnCode.store(returnCode); d->exit.storeRelease(true); d->threadData->eventDispatcher.load()->interrupt(); + +#ifdef Q_OS_WASM + // QEventLoop::exec() never returns in emscripten. We implement approximate behavior here. + // QTBUG-70185 + if (d->threadData->loopLevel == 1) { + emscripten_force_exit(returnCode); + } else { + d->inExec = false; + --d->threadData->loopLevel; + } +#endif } /*! |