diff --git a/src/library.js b/src/library.js index 607e18e68de0d..72ebd01841b88 100644 --- a/src/library.js +++ b/src/library.js @@ -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); } diff --git a/src/postamble.js b/src/postamble.js index c4c25cfb4a8d8..29853bf51fa43 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -163,10 +163,10 @@ function run() { #if PTHREADS || WASM_WORKERS if ({{{ ENVIRONMENT_IS_WORKER_THREAD() }}}) { + initRuntime(); #if MODULARIZE readyPromiseResolve(Module); #endif - initRuntime(); return; } #endif @@ -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 diff --git a/src/preamble.js b/src/preamble.js index af274a7ac888f..50c14df482bc3 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -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; } diff --git a/test/other/test_unoptimized_code_size.js.size b/test/other/test_unoptimized_code_size.js.size index 48f4d8dcae999..16401a0f98c99 100644 --- a/test/other/test_unoptimized_code_size.js.size +++ b/test/other/test_unoptimized_code_size.js.size @@ -1 +1 @@ -54928 +54737 diff --git a/test/other/test_unoptimized_code_size_no_asserts.js.size b/test/other/test_unoptimized_code_size_no_asserts.js.size index cec4a3ebfe845..2ee9a86dde1d8 100644 --- a/test/other/test_unoptimized_code_size_no_asserts.js.size +++ b/test/other/test_unoptimized_code_size_no_asserts.js.size @@ -1 +1 @@ -30416 +30225 diff --git a/test/other/test_unoptimized_code_size_strict.js.size b/test/other/test_unoptimized_code_size_strict.js.size index 5c3cf64221739..da9e77312a85e 100644 --- a/test/other/test_unoptimized_code_size_strict.js.size +++ b/test/other/test_unoptimized_code_size_strict.js.size @@ -1 +1 @@ -53724 +53533