diff options
author | Morten Sørvig <[email protected]> | 2025-04-09 12:11:16 +0200 |
---|---|---|
committer | Morten Sørvig <[email protected]> | 2025-04-15 18:31:47 +0200 |
commit | f5231e2dbbe3550eb2b245ef79f2b54e39b5683d (patch) | |
tree | 3e9ccf3603967c39a676a9b09c441f737bc9e995 /tests/manual | |
parent | 03699cc0ffb3c2f1c35b2815a6f9635e9d21aca2 (diff) |
wasm: implement promise handler using suspendresumecontrol
This is required to make sure we resume the wasm instance
when a promise resolves. As a bonus QWasmSuspendResumeControl
already implements the JS -> C++ callback mapping, and
we can removed the fixed-4 ThunkPool which the current
implementation is using.
The implementation is straightforward, where the only
snag is that cleanup must be done in the finally callback.
Implement Promise::all by calling JS Promise.all(). This
function returns a new Promise, which we can adopt.
Make two changes to the test:
- remove throwInThen(): We no longer support propagating
JS exceptions from the then() handler to the catch function.
(catching a rejected promise still works). As far as
I can see this functionality is not used in qtbase.
- In finallyWithThen(), change shared_ptr<bool> to plain
pointer. This works around a (mysterious) issue where we
were not getting the correct value when reading from the
shared_ptr.
Change-Id: I8fb11b66ecba74f80708bd39eeeac59bb62f3786
Reviewed-by: Lorn Potter <[email protected]>
Diffstat (limited to 'tests/manual')
-rw-r--r-- | tests/manual/wasm/qstdweb/promise_main.cpp | 27 |
1 files changed, 3 insertions, 24 deletions
diff --git a/tests/manual/wasm/qstdweb/promise_main.cpp b/tests/manual/wasm/qstdweb/promise_main.cpp index c5f6f7f4122..5f1e5102c93 100644 --- a/tests/manual/wasm/qstdweb/promise_main.cpp +++ b/tests/manual/wasm/qstdweb/promise_main.cpp @@ -5,6 +5,7 @@ #include <QtCore/QEvent> #include <QtCore/QMutex> #include <QtCore/QObject> +#include <QtCore/QDebug> #include <QtCore/private/qstdweb_p.h> #include <qtwasmtestlib.h> @@ -53,7 +54,6 @@ private slots: void multipleResolve(); void simpleReject(); void multipleReject(); - void throwInThen(); void bareFinally(); void finallyWithThen(); void finallyWithThrow(); @@ -188,28 +188,6 @@ void WasmPromiseTest::multipleReject() }, promiseCount); } -void WasmPromiseTest::throwInThen() -{ - init(); - - qstdweb::Promise::make(m_testSupport, "makeTestPromise", { - .thenFunc = [](val result) { - Q_UNUSED(result); - EM_ASM({ - throw "Expected error"; - }); - }, - .catchFunc = [](val error) { - QWASMCOMPARE("Expected error", error.as<std::string>()); - QWASMSUCCESS(); - } - }, std::string("throwInThen")); - - EM_ASM({ - testSupport.resolve["throwInThen"](); - }); -} - void WasmPromiseTest::bareFinally() { init(); @@ -229,7 +207,7 @@ void WasmPromiseTest::finallyWithThen() { init(); - auto thenCalled = std::make_shared<bool>(); + bool *thenCalled = new bool(false); qstdweb::Promise::make(m_testSupport, "makeTestPromise", { .thenFunc = [thenCalled] (val result) { Q_UNUSED(result); @@ -237,6 +215,7 @@ void WasmPromiseTest::finallyWithThen() }, .finallyFunc = [thenCalled]() { QWASMVERIFY(*thenCalled); + delete thenCalled; QWASMSUCCESS(); } }, std::string("finallyWithThen")); |