diff options
-rw-r--r-- | src/wasm2js.h | 9 | ||||
-rw-r--r-- | test/wasm2js/atomics_32.2asm.js | 9 | ||||
-rw-r--r-- | test/wasm2js/atomics_32.2asm.js.opt | 9 |
3 files changed, 21 insertions, 6 deletions
diff --git a/src/wasm2js.h b/src/wasm2js.h index 7c9bef0ba..615e47268 100644 --- a/src/wasm2js.h +++ b/src/wasm2js.h @@ -2856,9 +2856,14 @@ void Wasm2JSGlue::emitSpecialSupport() { } else if (import->base == ABI::wasm2js::ATOMIC_WAIT_I32) { out << R"( function wasm2js_atomic_wait_i32(ptr, expected, timeoutLow, timeoutHigh) { - if (timeoutLow != -1 || timeoutHigh != -1) throw 'unsupported timeout'; + var timeout = Infinity; + if (timeoutHigh >= 0) { + // Convert from nanoseconds to milliseconds + // Taken from convertI32PairToI53 in emscripten's library_int53.js + timeout = ((timeoutLow / 1e6) >>> 0) + timeoutHigh * (4294967296 / 1e6); + } var view = new Int32Array(bufferView.buffer); // TODO cache - var result = Atomics.wait(view, ptr, expected); + var result = Atomics.wait(view, ptr >> 2, expected, timeout); if (result == 'ok') return 0; if (result == 'not-equal') return 1; if (result == 'timed-out') return 2; diff --git a/test/wasm2js/atomics_32.2asm.js b/test/wasm2js/atomics_32.2asm.js index 89425ac94..6eb655e18 100644 --- a/test/wasm2js/atomics_32.2asm.js +++ b/test/wasm2js/atomics_32.2asm.js @@ -30,9 +30,14 @@ memorySegments[1] = base64DecodeToExistingUint8Array(new Uint8Array(6), 0, "d29y var f64ScratchView = new Float64Array(scratchBuffer); function wasm2js_atomic_wait_i32(ptr, expected, timeoutLow, timeoutHigh) { - if (timeoutLow != -1 || timeoutHigh != -1) throw 'unsupported timeout'; + var timeout = Infinity; + if (timeoutHigh >= 0) { + // Convert from nanoseconds to milliseconds + // Taken from convertI32PairToI53 in emscripten's library_int53.js + timeout = ((timeoutLow / 1e6) >>> 0) + timeoutHigh * (4294967296 / 1e6); + } var view = new Int32Array(bufferView.buffer); // TODO cache - var result = Atomics.wait(view, ptr, expected); + var result = Atomics.wait(view, ptr >> 2, expected, timeout); if (result == 'ok') return 0; if (result == 'not-equal') return 1; if (result == 'timed-out') return 2; diff --git a/test/wasm2js/atomics_32.2asm.js.opt b/test/wasm2js/atomics_32.2asm.js.opt index 94f25dc2c..f723aaf31 100644 --- a/test/wasm2js/atomics_32.2asm.js.opt +++ b/test/wasm2js/atomics_32.2asm.js.opt @@ -30,9 +30,14 @@ memorySegments[1] = base64DecodeToExistingUint8Array(new Uint8Array(6), 0, "d29y var f64ScratchView = new Float64Array(scratchBuffer); function wasm2js_atomic_wait_i32(ptr, expected, timeoutLow, timeoutHigh) { - if (timeoutLow != -1 || timeoutHigh != -1) throw 'unsupported timeout'; + var timeout = Infinity; + if (timeoutHigh >= 0) { + // Convert from nanoseconds to milliseconds + // Taken from convertI32PairToI53 in emscripten's library_int53.js + timeout = ((timeoutLow / 1e6) >>> 0) + timeoutHigh * (4294967296 / 1e6); + } var view = new Int32Array(bufferView.buffer); // TODO cache - var result = Atomics.wait(view, ptr, expected); + var result = Atomics.wait(view, ptr >> 2, expected, timeout); if (result == 'ok') return 0; if (result == 'not-equal') return 1; if (result == 'timed-out') return 2; |