From 566deba033b3f91ee3adf0b355ce76b6b01fa75b Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 23 Apr 2025 10:41:27 +0200 Subject: [PATCH] Prepare asyncify support --- cmake/compiler-env.cmake | 2 +- page/public/emulator-worker.js | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmake/compiler-env.cmake b/cmake/compiler-env.cmake index 2840e536..d582dd00 100644 --- a/cmake/compiler-env.cmake +++ b/cmake/compiler-env.cmake @@ -103,7 +103,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "Emscripten") -sMAXIMUM_MEMORY=4gb #-sEXCEPTION_CATCHING_ALLOWED=[..] -sEXIT_RUNTIME - #-sASYNCIFY + -sASYNCIFY ) if(MOMO_EMSCRIPTEN_SUPPORT_NODEJS) diff --git a/page/public/emulator-worker.js b/page/public/emulator-worker.js index 65af92a1..4bead2a3 100644 --- a/page/public/emulator-worker.js +++ b/page/public/emulator-worker.js @@ -26,6 +26,12 @@ function logLine(text) { } } +function notifyExit(code) { + flushLines(); + postMessage({ message: "end", data: code }); + self.close(); +} + function runEmulation(filesystem, file, options) { globalThis.Module = { arguments: [...options, "-e", "./root", file], @@ -46,12 +52,10 @@ function runEmulation(filesystem, file, options) { }, print: logLine, printErr: logLine, - postRun: () => { - flushLines(); - postMessage({ message: "end", data: null }); - self.close(); - }, + onAbort: () => notifyExit(null), + onExit: notifyExit, + postRun: flushLines, }; - importScripts("./analyzer.js?1"); + importScripts("./analyzer.js"); }