Skip to content

Commit 1e05a29

Browse files
committed
Don't resolve ready promise until after runtime init
1 parent 0e87f3d commit 1e05a29

6 files changed

+18
-12
lines changed

src/library.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ addToLibrary({
128128
if (keepRuntimeAlive() && !implicit) {
129129
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)`;
130130
#if MODULARIZE
131-
readyPromiseReject(msg);
131+
if (!runtimeInitialized) {
132+
// If the runtime has not yet been initializated then reject the
133+
// ready promise instead of logging the error here.
134+
readyPromiseReject(msg);
135+
} else
132136
#endif // MODULARIZE
133137
err(msg);
134138
}

src/postamble.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ function run() {
163163

164164
#if PTHREADS || WASM_WORKERS
165165
if ({{{ ENVIRONMENT_IS_WORKER_THREAD() }}}) {
166+
initRuntime();
166167
#if MODULARIZE
167168
readyPromiseResolve(Module);
168169
#endif
169-
initRuntime();
170170
return;
171171
}
172172
#endif
@@ -195,14 +195,14 @@ function run() {
195195
if (ABORT) return;
196196

197197
initRuntime();
198+
#if MODULARIZE
199+
readyPromiseResolve(Module);
200+
#endif
198201

199202
#if HAS_MAIN
200203
preMain();
201204
#endif
202205

203-
#if MODULARIZE
204-
readyPromiseResolve(Module);
205-
#endif
206206
#if expectToReceiveOnModule('onRuntimeInitialized')
207207
Module['onRuntimeInitialized']?.();
208208
#endif

src/preamble.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,13 @@ function abort(what) {
473473
var e = new WebAssembly.RuntimeError(what);
474474

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

Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
54928
1+
54737
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
30416
1+
30225
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
53724
1+
53533

0 commit comments

Comments
 (0)