Skip to content

Commit

Permalink
Only define maybeExit helper if EXIT_RUNTIME is set. NFC (#18374)
Browse files Browse the repository at this point in the history
Previously it was being defined but with an empty body.  This change
make it more obvious to the reader that this function exists only
when EXIT_RUNTIME is set.
  • Loading branch information
sbc100 authored Dec 15, 2022
1 parent 8944037 commit c0c97c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 12 additions & 6 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -3508,7 +3508,7 @@ mergeInto(LibraryManager.library, {
// as ExitStatus and 'unwind' and prevent these from escaping to the top
// level.
$callUserCallback__deps: ['$handleException',
#if EXIT_RUNTIME || USE_PTHREADS
#if EXIT_RUNTIME
'$maybeExit',
#endif
],
Expand All @@ -3525,24 +3525,24 @@ mergeInto(LibraryManager.library, {
}
try {
func();
#if EXIT_RUNTIME || USE_PTHREADS
#if EXIT_RUNTIME
#if USE_PTHREADS && !EXIT_RUNTIME
if (ENVIRONMENT_IS_PTHREAD)
#endif
maybeExit();
#endif
#endif // EXIT_RUNTIME
} catch (e) {
handleException(e);
}
},

#if EXIT_RUNTIME
$maybeExit__deps: ['exit', '$handleException',
#if USE_PTHREADS
'_emscripten_thread_exit',
#endif
],
$maybeExit: function() {
#if EXIT_RUNTIME
#if PROXY_TO_PTHREAD
// In PROXY_TO_PTHREAD mode the main thread never implicitly exits, but
// waits for the proxied main function to exit.
Expand All @@ -3565,14 +3565,20 @@ mergeInto(LibraryManager.library, {
handleException(e);
}
}
#endif // EXIT_RUNTIME
},
#else
// Define as stub function in case legacy code has unconditionally dependency
// on this function. We also have at least one test that expects this
// library function to always exist.
$maybeExit: function() {},
#endif // EXIT_RUNTIME

#else // MINIMAL_RUNTIME
// MINIMAL_RUNTIME doesn't support the runtimeKeepalive stuff
$callUserCallback: function(func) {
func();
},
#endif
#endif // MINIMAL_RUNTIME

$safeSetTimeout__deps: ['$callUserCallback'],
$safeSetTimeout__docs: '/** @param {number=} timeout */',
Expand Down
4 changes: 2 additions & 2 deletions src/library_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ var LibraryBrowser = {
#if OFFSCREEN_FRAMEBUFFER
'emscripten_webgl_commit_frame',
#endif
#if !MINIMAL_RUNTIME
#if EXIT_RUNTIME && !MINIMAL_RUNTIME
'$maybeExit',
#endif
],
Expand Down Expand Up @@ -988,7 +988,7 @@ var LibraryBrowser = {
dbg('main loop exiting..');
#endif
{{{ runtimeKeepalivePop() }}}
#if !MINIMAL_RUNTIME
#if EXIT_RUNTIME && !MINIMAL_RUNTIME
maybeExit();
#endif
return false;
Expand Down

0 comments on commit c0c97c6

Please sign in to comment.