Skip to content

Commit

Permalink
Don't resolve ready promise until after runtime init
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Dec 9, 2024
1 parent 0e87f3d commit 1e05a29
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ 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) {
// If the runtime has not yet been initializated then reject the
// ready promise instead of logging the error here.
readyPromiseReject(msg);
} else
#endif // MODULARIZE
err(msg);
}
Expand Down
8 changes: 4 additions & 4 deletions src/postamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ function run() {

#if PTHREADS || WASM_WORKERS
if ({{{ ENVIRONMENT_IS_WORKER_THREAD() }}}) {
initRuntime();
#if MODULARIZE
readyPromiseResolve(Module);
#endif
initRuntime();
return;
}
#endif
Expand Down Expand Up @@ -195,14 +195,14 @@ function run() {
if (ABORT) return;

initRuntime();
#if MODULARIZE
readyPromiseResolve(Module);
#endif

#if HAS_MAIN
preMain();
#endif

#if MODULARIZE
readyPromiseResolve(Module);
#endif
#if expectToReceiveOnModule('onRuntimeInitialized')
Module['onRuntimeInitialized']?.();
#endif
Expand Down
10 changes: 6 additions & 4 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,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
54737
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 @@
30416
30225
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
53533

0 comments on commit 1e05a29

Please sign in to comment.