diff --git a/src/corelib/platform/wasm/qstdweb.cpp b/src/corelib/platform/wasm/qstdweb.cpp index 18ab0ec1a9c..727668c45ae 100644 --- a/src/corelib/platform/wasm/qstdweb.cpp +++ b/src/corelib/platform/wasm/qstdweb.cpp @@ -487,10 +487,15 @@ void Promise::adoptPromise(emscripten::val promise, PromiseCallbacks callbacks) // Set handlers on the promise if (thenIndex) - promise.call("then", suspendResume->jsEventHandlerAt(*thenIndex)); + promise = + promise.call("then", suspendResume->jsEventHandlerAt(*thenIndex)); + if (catchIndex) - promise.call("catch", suspendResume->jsEventHandlerAt(*catchIndex)); - promise.call("finally", suspendResume->jsEventHandlerAt(*finallyIndex)); + promise = promise.call("catch", + suspendResume->jsEventHandlerAt(*catchIndex)); + + promise = promise.call("finally", + suspendResume->jsEventHandlerAt(*finallyIndex)); } void Promise::all(std::vector promises, PromiseCallbacks callbacks) diff --git a/tests/manual/wasm/qstdweb/promise_main.cpp b/tests/manual/wasm/qstdweb/promise_main.cpp index 5f1e5102c93..395e815cf95 100644 --- a/tests/manual/wasm/qstdweb/promise_main.cpp +++ b/tests/manual/wasm/qstdweb/promise_main.cpp @@ -54,6 +54,7 @@ private slots: void multipleResolve(); void simpleReject(); void multipleReject(); + void throwInThen(); void bareFinally(); void finallyWithThen(); void finallyWithThrow(); @@ -188,6 +189,28 @@ 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()); + QWASMSUCCESS(); + } + }, std::string("throwInThen")); + + EM_ASM({ + testSupport.resolve["throwInThen"](); + }); +} + void WasmPromiseTest::bareFinally() { init();