Skip to content

Commit

Permalink
Unify readyPromiseResolve calls
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Dec 9, 2024
1 parent c08204e commit 544dbe2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
5 changes: 4 additions & 1 deletion src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ addToLibrary({
if (keepRuntimeAlive() && !implicit) {
var msg = `program exited (with status: ${status}), but keepRuntimeAlive() is set (counter=${runtimeKeepaliveCounter}) due to an async operation, so halting execution but not exiting the runtime or preventing further async execution (you can use emscripten_force_exit, if you want to force a true shutdown)`;
#if MODULARIZE
readyPromiseReject(msg);
if (!runtimeInitialized) {
readyPromiseReject(msg);
return;
}
#endif // MODULARIZE
err(msg);
}
Expand Down
15 changes: 2 additions & 13 deletions src/postamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,13 @@ function run() {

#if WASM_WORKERS
if (ENVIRONMENT_IS_WASM_WORKER) {
#if MODULARIZE
readyPromiseResolve(Module);
#endif // MODULARIZE
return initRuntime();
initRuntime();
return;
}
#endif

#if PTHREADS
if (ENVIRONMENT_IS_PTHREAD) {
#if MODULARIZE
// The promise resolve function typically gets called as part of the execution
// of `doRun` below. The workers/pthreads don't execute `doRun` so the
// creation promise can be resolved, marking the pthread-Module as initialized.
readyPromiseResolve(Module);
#endif // MODULARIZE
initRuntime();
startWorker(Module);
return;
Expand Down Expand Up @@ -213,9 +205,6 @@ function run() {
preMain();
#endif

#if MODULARIZE
readyPromiseResolve(Module);
#endif
#if expectToReceiveOnModule('onRuntimeInitialized')
Module['onRuntimeInitialized']?.();
#endif
Expand Down
25 changes: 17 additions & 8 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,7 @@ function preRun() {
callRuntimeCallbacks(__ATPRERUN__);
}

function initRuntime() {
#if RUNTIME_DEBUG
dbg('initRuntime');
#endif
function doInitRuntime() {
#if ASSERTIONS
assert(!runtimeInitialized);
#endif
Expand Down Expand Up @@ -237,6 +234,16 @@ function initRuntime() {
callRuntimeCallbacks(__ATINIT__);
}

function initRuntime() {
#if RUNTIME_DEBUG
dbg('initRuntime');
#endif
doInitRuntime();
#if MODULARIZE
readyPromiseResolve(Module);
#endif
}

#if HAS_MAIN
function preMain() {
#if STACK_OVERFLOW_CHECK
Expand Down Expand Up @@ -471,11 +478,13 @@ function abort(what) {
var e = new WebAssembly.RuntimeError(what);

#if MODULARIZE
readyPromiseReject(e);
if (!runtimeInitialized) {
// If the runtime has not yet been initializated then reject the
// ready promise instead of thowing the error;
readyPromiseReject(e);
return;
}
#endif
// Throw the error whether or not MODULARIZE is set because abort is used
// in code paths apart from instantiation where an exception is expected
// to be thrown when abort is called.
throw e;
}

Expand Down
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
54928
54786
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_no_asserts.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
30574
30432
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_strict.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
53724
53582

0 comments on commit 544dbe2

Please sign in to comment.