diff --git a/.circleci/config.yml b/.circleci/config.yml index 0ff9d94611889..ab5c508087c7b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -706,6 +706,7 @@ jobs: wasmfs.test_fs_llseek_rawfs wasmfs.test_freetype minimal0.test_utf + minimal0.test_static_variable omitexports0.test_asyncify_longjmp strict.test_no_declare_asm_module_exports " diff --git a/src/postamble_minimal.js b/src/postamble_minimal.js index 68d7bb38daf6b..b45b2724ee899 100644 --- a/src/postamble_minimal.js +++ b/src/postamble_minimal.js @@ -80,7 +80,23 @@ function run() { _main({{{ argc_argv() }}}).then(exitRuntime); #elif EXIT_RUNTIME // In regular exitRuntime mode, exit with the given return code from main(). - exitRuntime(_main({{{ argc_argv() }}})); + try { + exitRuntime(_main({{{ argc_argv() }}})); + } catch(e) { + var exitCode = e.match(/^exit\(\d+\)$/); + if (exitCode) { + throw e; + } +#if RUNTIME_DEBUG + dbg(`main() called ${e}.`); // e.g. "main() called exit(0)." +#endif + // Report to Module that the program exited. TODO: Find a way to not emit + // this code unconditionally, as it may not be needed by the user. In + // MINIMAL_RUNTIME, the use of Module object is discouraged, since it leads + // to non-DCEable patterns of code. This call is present here mainly for + // Emscripten test harness purposes. + Module['onExit']?.(exitCode[1]); + } #else // Run a persistent (never-exiting) application starting at main(). _main({{{ argc_argv() }}});