From a4d1c30a1b52e797cce504f90bcf20d7943dd1f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Wed, 5 Jul 2023 14:46:13 +0200 Subject: wasm: clarify qtloader onExit behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit onExit is called whenever the application exits, i.e. when the app canvas should no longer be displayed and the loader/embedder code should take some action. Emscripten provides two callbacks which can be used here: - onExit, called when the app exits (but see EXIT_RUNTIME) - onAbort, called on abort errors. These map to the two cases Qt's onExit supports. onExit is not called when EXIT_RUNTIME is disabled, which means we don't need the special case for exit code 0. In addition call onExit on any exception. The second call to showUi() in html_shell.html is then not needed any more and we avoid duplicating the UI state handling in user code. Update the qtloader_integration test to handle changes in behavior (we no longer set the error text on exit). Use emscripten_force_exit() to simulate application exit - using this function makes Emscripten call onExit even when EXIT_RUNTIME is disabled. Pick-to: 6.6 Change-Id: I72b5463c1836e8d5054e594abbd304fbc67032b7 Reviewed-by: Piotr Wierciński Reviewed-by: Mikołaj Boc --- tests/manual/wasm/qtloader_integration/main.cpp | 4 ++-- tests/manual/wasm/qtloader_integration/test_body.js | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'tests/manual/wasm') diff --git a/tests/manual/wasm/qtloader_integration/main.cpp b/tests/manual/wasm/qtloader_integration/main.cpp index b9bed0d49b..ee032e9952 100644 --- a/tests/manual/wasm/qtloader_integration/main.cpp +++ b/tests/manual/wasm/qtloader_integration/main.cpp @@ -71,7 +71,7 @@ void crash() void exitApp() { - exit(ExitValueFromExitApp); + emscripten_force_exit(ExitValueFromExitApp); } void produceOutput() @@ -135,7 +135,7 @@ int main(int argc, char **argv) std::find(arguments.begin(), arguments.end(), QStringLiteral("--exit-immediately")) != arguments.end(); if (exitImmediately) - return ExitValueImmediateReturn; + emscripten_force_exit(ExitValueImmediateReturn); const bool crashImmediately = std::find(arguments.begin(), arguments.end(), QStringLiteral("--crash-immediately")) diff --git a/tests/manual/wasm/qtloader_integration/test_body.js b/tests/manual/wasm/qtloader_integration/test_body.js index 233c64f2f6..f1285d617a 100644 --- a/tests/manual/wasm/qtloader_integration/test_body.js +++ b/tests/manual/wasm/qtloader_integration/test_body.js @@ -345,9 +345,7 @@ export class QtLoaderIntegrationTests caughtException = e; } - // An exception should have been thrown from load() - assert.equal('RuntimeError', caughtException.name); - + assert.isUndefined(caughtException); assert.equal(1, onExitMock.calls.length); const exitStatus = onExitMock.calls[0][0]; assert.isTrue(exitStatus.crashed); @@ -395,7 +393,7 @@ export class QtLoaderIntegrationTests const exitStatus = onExitMock.calls[0][0]; assert.isFalse(exitStatus.crashed); assert.equal(instance.EXIT_VALUE_FROM_EXIT_APP, exitStatus.code); - assert.isNotUndefined(exitStatus.text); + assert.isUndefined(exitStatus.text); } async exitImmediately() @@ -414,7 +412,7 @@ export class QtLoaderIntegrationTests assert.isFalse(exitStatusFromOnExit.crashed); assert.equal(instance.EXIT_VALUE_IMMEDIATE_RETURN, exitStatusFromOnExit.code); - assert.isNotUndefined(exitStatusFromOnExit.text); + assert.isUndefined(exitStatusFromOnExit.text); } async userQuitCallbackCalled() -- cgit v1.2.3