@@ -257,7 +257,8 @@ if (ENVIRONMENT_IS_WASM_WORKER) {
257
257
// https://github.com/tc39/proposal-atomics-wait-async/blob/master/PROPOSAL.md
258
258
// This polyfill performs polling with setTimeout() to observe a change in the
259
259
// target memory location.
260
- emscripten_atomic_wait_async__postset : `if (!Atomics.waitAsync || (typeof navigator !== 'undefined' && navigator.userAgent && jstoi_q((navigator.userAgent.match(/Chrom(e|ium)\\/([0-9]+)\\./)||[])[2]) < 91)) {
260
+ $polyfillWaitAsync__deps : [ '$jstoi_q' ] ,
261
+ $polyfillWaitAsync__postset : `if (!Atomics.waitAsync || (typeof navigator !== 'undefined' && navigator.userAgent && jstoi_q((navigator.userAgent.match(/Chrom(e|ium)\\/([0-9]+)\\./)||[])[2]) < 91)) {
261
262
let __Atomics_waitAsyncAddresses = [/*[i32a, index, value, maxWaitMilliseconds, promiseResolve]*/];
262
263
function __Atomics_pollWaitAsyncAddresses() {
263
264
let now = performance.now();
@@ -292,20 +293,19 @@ Atomics.waitAsync = (i32a, index, value, maxWaitMilliseconds) => {
292
293
return { async: true, value: promise };
293
294
};
294
295
}` ,
295
-
296
- // These dependencies are artificial, issued so that we still get the
297
- // waitAsync polyfill emitted if code only calls
298
- // emscripten_lock/semaphore_async_acquire() but not
299
- // emscripten_atomic_wait_async() directly.
300
- emscripten_lock_async_acquire__deps : [ 'emscripten_atomic_wait_async' ] ,
301
- emscripten_semaphore_async_acquire__deps : [ 'emscripten_atomic_wait_async' ] ,
302
-
303
296
#endif
304
297
305
- $liveAtomicWaitAsyncs : '{}' ,
306
- $liveAtomicWaitAsyncCounter : '0' ,
298
+ $polyfillWaitAsync__internal : true ,
299
+ $polyfillWaitAsync : ( ) => {
300
+ // nop, used for its postset to ensure `Atomics.waitAsync()` polyfill is
301
+ // included exactly once and only included when needed.
302
+ // Any function using Atomics.waitAsync should depend on this.
303
+ } ,
304
+
305
+ $liveAtomicWaitAsyncs : { } ,
306
+ $liveAtomicWaitAsyncCounter : 0 ,
307
307
308
- emscripten_atomic_wait_async__deps : [ '$atomicWaitStates' , '$liveAtomicWaitAsyncs' , '$liveAtomicWaitAsyncCounter' , '$jstoi_q ' ] ,
308
+ emscripten_atomic_wait_async__deps : [ '$atomicWaitStates' , '$liveAtomicWaitAsyncs' , '$liveAtomicWaitAsyncCounter' , '$polyfillWaitAsync ' ] ,
309
309
emscripten_atomic_wait_async : ( addr , val , asyncWaitFinished , userData , maxWaitMilliseconds ) => {
310
310
let wait = Atomics . waitAsync ( HEAP32 , { { { getHeapOffset ( 'addr' , 'i32' ) } } } , val , maxWaitMilliseconds ) ;
311
311
if ( ! wait . async ) return atomicWaitStates . indexOf ( wait . value ) ;
@@ -385,6 +385,7 @@ Atomics.waitAsync = (i32a, index, value, maxWaitMilliseconds) => {
385
385
return Atomics . isLockFree ( width ) ;
386
386
} ,
387
387
388
+ emscripten_lock_async_acquire__deps : [ '$polyfillWaitAsync' ] ,
388
389
emscripten_lock_async_acquire : ( lock , asyncWaitFinished , userData , maxWaitMilliseconds ) => {
389
390
let dispatch = ( val , ret ) => {
390
391
setTimeout ( ( ) => {
@@ -406,6 +407,7 @@ Atomics.waitAsync = (i32a, index, value, maxWaitMilliseconds) => {
406
407
tryAcquireLock ( ) ;
407
408
} ,
408
409
410
+ emscripten_semaphore_async_acquire__deps : [ '$polyfillWaitAsync' ] ,
409
411
emscripten_semaphore_async_acquire : ( sem , num , asyncWaitFinished , userData , maxWaitMilliseconds ) => {
410
412
let dispatch = ( idx , ret ) => {
411
413
setTimeout ( ( ) => {
0 commit comments