@@ -227,41 +227,41 @@ mergeInto(LibraryManager.library, {
227227 // see https://bugs.chromium.org/p/chromium/issues/detail?id=1167541
228228 // https://github.com/tc39/proposal-atomics-wait-async/blob/master/PROPOSAL.md
229229 // This polyfill performs polling with setTimeout() to observe a change in the target memory location.
230- emscripten_atomic_wait_async__postset : " if (!Atomics['waitAsync'] || jstoi_q((navigator.userAgent.match(/Chrom(e|ium)\\/([0-9]+)\\./)||[])[2]) < 91) { \n" +
231- " let __Atomics_waitAsyncAddresses = [/*[i32a, index, value, maxWaitMilliseconds, promiseResolve]*/];\n" +
232- " function __Atomics_pollWaitAsyncAddresses() {\n" +
233- " let now = performance.now();\n" +
234- " let l = __Atomics_waitAsyncAddresses.length;\n" +
235- " for(let i = 0; i < l; ++i) {\n" +
236- " let a = __Atomics_waitAsyncAddresses[i];\n" +
237- " let expired = (now > a[3]);\n" +
238- " let awoken = (Atomics.load(a[0], a[1]) != a[2]);\n" +
239- " if (expired || awoken) {\n" +
240- " __Atomics_waitAsyncAddresses[i--] = __Atomics_waitAsyncAddresses[--l];\n" +
241- " __Atomics_waitAsyncAddresses.length = l;\n" +
242- " a[4](awoken ? 'ok': 'timed-out');\n" +
243- " }\n" +
244- " }\n" +
245- " if (l) {\n" +
246- " // If we still have addresses to wait, loop the timeout handler to continue polling.\n" +
247- " setTimeout(__Atomics_pollWaitAsyncAddresses, 10);\n" +
248- " }\n" +
249- "}\n" +
230+ emscripten_atomic_wait_async__postset : ` if (!Atomics['waitAsync'] || jstoi_q((navigator.userAgent.match(/Chrom(e|ium)\\/([0-9]+)\\./)||[])[2]) < 91) {
231+ let __Atomics_waitAsyncAddresses = [/*[i32a, index, value, maxWaitMilliseconds, promiseResolve]*/];
232+ function __Atomics_pollWaitAsyncAddresses() {
233+ let now = performance.now();
234+ let l = __Atomics_waitAsyncAddresses.length;
235+ for(let i = 0; i < l; ++i) {
236+ let a = __Atomics_waitAsyncAddresses[i];
237+ let expired = (now > a[3]);
238+ let awoken = (Atomics.load(a[0], a[1]) != a[2]);
239+ if (expired || awoken) {
240+ __Atomics_waitAsyncAddresses[i--] = __Atomics_waitAsyncAddresses[--l];
241+ __Atomics_waitAsyncAddresses.length = l;
242+ a[4](awoken ? 'ok': 'timed-out');
243+ }
244+ }
245+ if (l) {
246+ // If we still have addresses to wait, loop the timeout handler to continue polling.
247+ setTimeout(__Atomics_pollWaitAsyncAddresses, 10);
248+ }
249+ }
250250#if ASSERTIONS
251- " if (!ENVIRONMENT_IS_WASM_WORKER) console.error ('Current environment does not support Atomics.waitAsync(): polyfilling it, but this is going to be suboptimal.');\n" +
251+ if (!ENVIRONMENT_IS_WASM_WORKER) err ('Current environment does not support Atomics.waitAsync(): polyfilling it, but this is going to be suboptimal.');
252252#endif
253- " Atomics['waitAsync'] = function(i32a, index, value, maxWaitMilliseconds) {\n" +
254- " let val = Atomics.load(i32a, index);\n" +
255- " if (val != value) return { async: false, value: 'not-equal' };\n" +
256- " if (maxWaitMilliseconds <= 0) return { async: false, value: 'timed-out' };\n" +
257- " maxWaitMilliseconds = performance.now() + (maxWaitMilliseconds || Infinity);\n" +
258- " let promiseResolve;\n" +
259- " let promise = new Promise((resolve) => { promiseResolve = resolve; });\n" +
260- " if (!__Atomics_waitAsyncAddresses[0]) setTimeout(__Atomics_pollWaitAsyncAddresses, 10);\n" +
261- " __Atomics_waitAsyncAddresses.push([i32a, index, value, maxWaitMilliseconds, promiseResolve]);\n" +
262- " return { async: true, value: promise };\n" +
263- "};\n" +
264- "}" ,
253+ Atomics['waitAsync'] = function(i32a, index, value, maxWaitMilliseconds) {
254+ let val = Atomics.load(i32a, index);
255+ if (val != value) return { async: false, value: 'not-equal' };
256+ if (maxWaitMilliseconds <= 0) return { async: false, value: 'timed-out' };
257+ maxWaitMilliseconds = performance.now() + (maxWaitMilliseconds || Infinity);
258+ let promiseResolve;
259+ let promise = new Promise((resolve) => { promiseResolve = resolve; });
260+ if (!__Atomics_waitAsyncAddresses[0]) setTimeout(__Atomics_pollWaitAsyncAddresses, 10);
261+ __Atomics_waitAsyncAddresses.push([i32a, index, value, maxWaitMilliseconds, promiseResolve]);
262+ return { async: true, value: promise };
263+ };
264+ }` ,
265265
266266 // These dependencies are artificial, issued so that we still get the waitAsync polyfill emitted
267267 // if code only calls emscripten_lock/semaphore_async_acquire()
0 commit comments