Skip to content

Commit 97a44e1

Browse files
authored
Fix use of waitAsync and closure compiler warnings in WASM_WORKERS mode (#16907)
`waitAsync` seems to require an int32 rather than uint32 view. Without this change I get bunch of errors run from when running `browser.test_wasm_worker_lock_async_acquire`: `TypeError: [object Uint32Array] is not an int32 or BigInt64 typed array`
1 parent 3a3f357 commit 97a44e1

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/library_wasm_worker.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ mergeInto(LibraryManager.library, {
212212
// see https://bugs.chromium.org/p/chromium/issues/detail?id=1167541
213213
// https://github.com/tc39/proposal-atomics-wait-async/blob/master/PROPOSAL.md
214214
// This polyfill performs polling with setTimeout() to observe a change in the target memory location.
215-
emscripten_atomic_wait_async__postset: "if (!Atomics['waitAsync'] || parseInt((navigator.userAgent.match(/Chrom(e|ium)\\/([0-9]+)\\./)||[])[2]) < 91) { \n"+
215+
emscripten_atomic_wait_async__postset: "if (!Atomics['waitAsync'] || jstoi_q((navigator.userAgent.match(/Chrom(e|ium)\\/([0-9]+)\\./)||[])[2]) < 91) { \n"+
216216
"let __Atomics_waitAsyncAddresses = [/*[i32a, index, value, maxWaitMilliseconds, promiseResolve]*/];\n"+
217217
"function __Atomics_pollWaitAsyncAddresses() {\n"+
218218
" let now = performance.now();\n"+
@@ -259,7 +259,7 @@ mergeInto(LibraryManager.library, {
259259
_emscripten_atomic_live_wait_asyncs: '{}',
260260
_emscripten_atomic_live_wait_asyncs_counter: '0',
261261

262-
emscripten_atomic_wait_async__deps: ['_emscripten_atomic_wait_states', '_emscripten_atomic_live_wait_asyncs', '_emscripten_atomic_live_wait_asyncs_counter'],
262+
emscripten_atomic_wait_async__deps: ['_emscripten_atomic_wait_states', '_emscripten_atomic_live_wait_asyncs', '_emscripten_atomic_live_wait_asyncs_counter', '$jstoi_q'],
263263
emscripten_atomic_wait_async: function(addr, val, asyncWaitFinished, userData, maxWaitMilliseconds) {
264264
let wait = Atomics['waitAsync'](HEAP32, addr >> 2, val, maxWaitMilliseconds);
265265
if (!wait.async) return __emscripten_atomic_wait_states.indexOf(wait.value);
@@ -340,9 +340,9 @@ mergeInto(LibraryManager.library, {
340340
};
341341
let tryAcquireLock = () => {
342342
do {
343-
let val = Atomics.compareExchange(HEAPU32, lock >> 2, 0/*zero represents lock being free*/, 1/*one represents lock being acquired*/);
343+
var val = Atomics.compareExchange(HEAP32, lock >> 2, 0/*zero represents lock being free*/, 1/*one represents lock being acquired*/);
344344
if (!val) return dispatch(0, 0/*'ok'*/);
345-
var wait = Atomics['waitAsync'](HEAPU32, lock >> 2, val, maxWaitMilliseconds);
345+
var wait = Atomics['waitAsync'](HEAP32, lock >> 2, val, maxWaitMilliseconds);
346346
} while(wait.value === 'not-equal');
347347
#if ASSERTIONS
348348
assert(wait.async || wait.value === 'timed-out');
@@ -362,12 +362,12 @@ mergeInto(LibraryManager.library, {
362362
let tryAcquireSemaphore = () => {
363363
let val = num;
364364
do {
365-
let ret = Atomics.compareExchange(HEAPU32, sem >> 2,
365+
let ret = Atomics.compareExchange(HEAP32, sem >> 2,
366366
val, /* We expect this many semaphore resoures to be available*/
367367
val - num /* Acquire 'num' of them */);
368368
if (ret == val) return dispatch(ret/*index of resource acquired*/, 0/*'ok'*/);
369369
val = ret;
370-
let wait = Atomics['waitAsync'](HEAPU32, sem >> 2, ret, maxWaitMilliseconds);
370+
let wait = Atomics['waitAsync'](HEAP32, sem >> 2, ret, maxWaitMilliseconds);
371371
} while(wait.value === 'not-equal');
372372
#if ASSERTIONS
373373
assert(wait.async || wait.value === 'timed-out');

tests/test_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5224,7 +5224,7 @@ def test_wasm_worker_lock_wait2(self):
52245224
# Tests emscripten_lock_async_acquire() function.
52255225
@also_with_minimal_runtime
52265226
def test_wasm_worker_lock_async_acquire(self):
5227-
self.btest(test_file('wasm_worker/lock_async_acquire.c'), expected='0', args=['-sWASM_WORKERS'])
5227+
self.btest(test_file('wasm_worker/lock_async_acquire.c'), expected='0', args=['--closure=1', '-sWASM_WORKERS'])
52285228

52295229
# Tests emscripten_lock_busyspin_wait_acquire() in Worker and main thread.
52305230
@also_with_minimal_runtime

tests/test_other.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11901,6 +11901,10 @@ def test_shared_memory_preprocessor_flags(self):
1190111901
def test_wasm_worker_preprocessor_flags(self):
1190211902
self.run_process([EMCC, '-c', test_file('wasm_worker/wasm_worker_preprocessor_flags.c'), '-sWASM_WORKERS'])
1190311903

11904+
@also_with_minimal_runtime
11905+
def test_wasm_worker_closure(self):
11906+
self.run_process([EMCC, test_file('wasm_worker/lock_async_acquire.c'), '-O2', '-sWASM_WORKERS', '--closure=1'])
11907+
1190411908
def test_debug_opt_warning(self):
1190511909
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-O2', '-g', '-Werror'])
1190611910
self.assertContained('error: running limited binaryen optimizations because DWARF info requested (or indirectly required) [-Wlimited-postlink-optimizations]', err)

0 commit comments

Comments
 (0)