From 8e82b165877c4f0847c74d4bb581f76cdd9ad7a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Wed, 25 Oct 2023 12:14:36 +0200 Subject: [PATCH] wasm: call onExit once and only once on exit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We listen to the onExit and on onAbort Emscripten events, and also handle exit by exception. Make sure we call onExit only once on exit, regardless of the order and number of Emscripten events. Change-Id: I4833a1056fad0a2706bd6c0f0fce98fb052fe8c8 Reviewed-by: Morten Johan Sørvig (cherry picked from commit ac4619a36a54a2168ea5d7a2c7d059781564098c) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/wasm/qtloader.js | 38 ++++++++++++++++---------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/plugins/platforms/wasm/qtloader.js b/src/plugins/platforms/wasm/qtloader.js index c0bb3652cfa..d1abc2545c7 100644 --- a/src/plugins/platforms/wasm/qtloader.js +++ b/src/plugins/platforms/wasm/qtloader.js @@ -162,25 +162,32 @@ async function qtLoad(config) return originalLocatedFilename; } + let onExitCalled = false; const originalOnExit = config.onExit; config.onExit = code => { originalOnExit?.(); - config.qt.onExit?.({ - code, - crashed: false - }); + + if (!onExitCalled) { + onExitCalled = true; + config.qt.onExit?.({ + code, + crashed: false + }); + } } const originalOnAbort = config.onAbort; config.onAbort = text => { originalOnAbort?.(); - - aborted = true; - config.qt.onExit?.({ - text, - crashed: true - }); + + if (!onExitCalled) { + onExitCalled = true; + config.qt.onExit?.({ + text, + crashed: true + }); + } }; const fetchPreloadFiles = async () => { @@ -206,10 +213,13 @@ async function qtLoad(config) instance = await Promise.race( [circuitBreaker, config.qt.entryFunction(config)]); } catch (e) { - config.qt.onExit?.({ - text: e.message, - crashed: true - }); + if (!onExitCalled) { + onExitCalled = true; + config.qt.onExit?.({ + text: e.message, + crashed: true + }); + } throw e; }