Skip to content

Commit 27d725b

Browse files
authored
Fix -sEXIT_RUNTIME in MINIMAL_RUNTIME build mode. (#25321)
Fix -sEXIT_RUNTIME in MINIMAL_RUNTIME build mode. Fixes 13 tests in minimal0 suite, e.g. minimal0.test_static_variable.
1 parent 9565865 commit 27d725b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ jobs:
746746
wasmfs.test_fs_llseek_rawfs
747747
wasmfs.test_freetype
748748
minimal0.test_utf
749+
minimal0.test_static_variable
749750
minimal0.test_stack_overflow
750751
omitexports0.test_asyncify_longjmp
751752
omitexports0.test_emscripten_api

src/postamble_minimal.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,26 @@ function run() {
8080
_main({{{ argc_argv() }}}).then(exitRuntime);
8181
#elif EXIT_RUNTIME
8282
// In regular exitRuntime mode, exit with the given return code from main().
83-
exitRuntime(_main({{{ argc_argv() }}}));
83+
try {
84+
exitRuntime(_main({{{ argc_argv() }}}));
85+
} catch(e) {
86+
var exitCode = e.match(/^exit\((\d+)\)$/);
87+
if (exitCode) {
88+
#if RUNTIME_DEBUG
89+
dbg(`main() called ${e}.`); // e.g. "main() called exit(0)."
90+
#endif
91+
#if expectToReceiveOnModule('onExit')
92+
// Report to Module that the program exited.
93+
Module['onExit']?.(exitCode[1]|0);
94+
#endif
95+
} else {
96+
#if RUNTIME_DEBUG
97+
dbg(`main() threw an exception: ${e}.`);
98+
#endif
99+
// Some other exception occurred - re-throw it.
100+
throw e;
101+
}
102+
}
84103
#else
85104
// Run a persistent (never-exiting) application starting at main().
86105
_main({{{ argc_argv() }}});

0 commit comments

Comments
 (0)