@@ -344,14 +344,15 @@ LibraryJSEventLoop = {
344344 if ( globalThis . setImmediate ) {
345345 MainLoop . setImmediate = setImmediate ;
346346 } else {
347+ #if RUNTIME_DEBUG
348+ dbg ( 'using polyfil for setImmediate' ) ;
349+ #endif
347350 // Emulate setImmediate. (note: not a complete polyfill, we don't emulate clearImmediate() to keep code size to minimum, since not needed)
348351 var setImmediates = [ ] ;
349352 var emscriptenMainLoopMessageId = 'setimmediate' ;
350353 /** @param {Event } event */
351354 var MainLoop_setImmediate_messageHandler = ( event ) => {
352- // When called in current thread or Worker, the main loop ID is structured slightly different to accommodate for --proxy-to-worker runtime listening to Worker events,
353- // so check for both cases.
354- if ( event . data === emscriptenMainLoopMessageId || event . data . target === emscriptenMainLoopMessageId ) {
355+ if ( event . data === emscriptenMainLoopMessageId ) {
355356 event . stopPropagation ( ) ;
356357 setImmediates . shift ( ) ( ) ;
357358 }
@@ -360,10 +361,12 @@ LibraryJSEventLoop = {
360361 MainLoop . setImmediate = /** @type {function(function(): ?, ...?): number } */ ( ( func ) => {
361362 setImmediates . push ( func ) ;
362363 if ( ENVIRONMENT_IS_WORKER ) {
363- Module [ 'setImmediates' ] ??= [ ] ;
364- Module [ 'setImmediates' ] . push ( func ) ;
365- postMessage ( { target : emscriptenMainLoopMessageId } ) ; // In --proxy-to-worker, route the message via proxyClient.js
366- } else postMessage ( emscriptenMainLoopMessageId , "*" ) ; // On the main thread, can just send the message to itself.
364+ // The postMessge API in a Worker, sends message to the main
365+ // thread and does not support the `targetOrigin` (*) argument.
366+ postMessage ( emscriptenMainLoopMessageId ) ;
367+ } else {
368+ postMessage ( emscriptenMainLoopMessageId , '*' ) ;
369+ }
367370 } ) ;
368371 }
369372 }
0 commit comments