Skip to content

Commit 32ac920

Browse files
committed
Avoid nesting in worker.js
1 parent 8301d5e commit 32ac920

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

src/worker.js

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -225,54 +225,52 @@ this.onmessage = function(e) {
225225
#endif
226226
Module['PThread'].threadExit(result);
227227
} catch(ex) {
228-
if (ex != 'unwind') {
228+
if (ex == 'unwind') {
229229
#if ASSERTIONS
230-
// FIXME(sbc): Figure out if this is still needed or useful. Its not
231-
// clear to me how this check could ever fail. In order to get into
232-
// this try/catch block at all we have already called bunch of
233-
// functions on `Module`.. why is this one special?
234-
if (typeof(Module['_emscripten_futex_wake']) !== "function") {
235-
err("Thread Initialisation failed.");
236-
throw ex;
237-
}
230+
// keep the pthread alive for asynchronous events.
231+
err('Pthread 0x' + Module['_pthread_self']().toString(16) + ' completed its pthread main entry point with an unwind, keeping the pthread worker alive for asynchronous operation.');
238232
#endif
239-
// ExitStatus not present in MINIMAL_RUNTIME
240-
#if !MINIMAL_RUNTIME
241-
if (ex instanceof Module['ExitStatus']) {
242-
if (Module['getNoExitRuntime']()) {
233+
return;
234+
}
243235
#if ASSERTIONS
244-
err('Pthread 0x' + Module['_pthread_self']().toString(16) + ' called exit(), staying alive due to noExitRuntime.');
236+
// FIXME(sbc): Figure out if this is still needed or useful. Its not
237+
// clear to me how this check could ever fail. In order to get into
238+
// this try/catch block at all we have already called bunch of
239+
// functions on `Module`.. why is this one special?
240+
if (typeof(Module['_emscripten_futex_wake']) !== "function") {
241+
err("Thread Initialisation failed.");
242+
throw ex;
243+
}
245244
#endif
246-
} else {
245+
// ExitStatus not present in MINIMAL_RUNTIME
246+
#if !MINIMAL_RUNTIME
247+
if (ex instanceof Module['ExitStatus']) {
248+
if (Module['getNoExitRuntime']()) {
247249
#if ASSERTIONS
248-
err('Pthread 0x' + Module['_pthread_self']().toString(16) + ' called exit(), calling threadExit.');
250+
err('Pthread 0x' + Module['_pthread_self']().toString(16) + ' called exit(), staying alive due to noExitRuntime.');
249251
#endif
250-
Module['PThread'].threadExit(ex.status);
251-
}
252-
}
253-
else
252+
} else {
253+
#if ASSERTIONS
254+
err('Pthread 0x' + Module['_pthread_self']().toString(16) + ' called exit(), calling threadExit.');
254255
#endif
255-
{
256-
Module['PThread'].threadExit(-2);
257-
throw ex;
256+
Module['PThread'].threadExit(ex.status);
258257
}
259-
#if ASSERTIONS
260-
} else {
261-
// else e == 'unwind', and we should fall through here and keep the pthread alive for asynchronous events.
262-
err('Pthread 0x' + Module['_pthread_self']().toString(16) + ' completed its pthread main entry point with an unwind, keeping the pthread worker alive for asynchronous operation.');
258+
}
259+
else
263260
#endif
261+
{
262+
Module['PThread'].threadExit(-2);
263+
throw ex;
264264
}
265265
}
266266
} else if (e.data.cmd === 'cancel') { // Main thread is asking for a pthread_cancel() on this thread.
267-
if (Module['_pthread_self']()) {
267+
if (Module['_pthread_self']())
268268
Module['PThread'].threadExit(-1/*PTHREAD_CANCELED*/);
269-
}
270269
} else if (e.data.target === 'setimmediate') {
271270
// no-op
272271
} else if (e.data.cmd === 'processThreadQueue') {
273-
if (Module['_pthread_self']()) { // If this thread is actually running?
272+
if (Module['_pthread_self']()) // If this thread is actually running?
274273
Module['_emscripten_current_thread_process_queued_calls']();
275-
}
276274
} else {
277275
err('worker.js received unknown command ' + e.data.cmd);
278276
err(e.data);

0 commit comments

Comments
 (0)