Skip to content
This repository was archived by the owner on Jun 22, 2023. It is now read-only.

Commit 539ecb5

Browse files
committed
Polyfill: conform to ValidateSharedIntegerTypedArray support for BigInt64Array
1 parent 3d6e78f commit 539ecb5

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

polyfill.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,32 @@
6666
helpers.push(h);
6767
}
6868

69+
function ToBigInt64(value) {
70+
let n = BigInt(value);
71+
let int64bit = n % (2n ** 64n);
72+
if (int64bit > 2n ** 63n) {
73+
return int64bit - 2n ** 64n;
74+
}
75+
return int64bit;
76+
}
77+
6978
// Atomics.waitAsync always returns a promise. Throws standard errors
7079
// for parameter validation. The promise is resolved with a string as from
7180
// Atomics.wait, or, in the case something went completely wrong, it is
7281
// rejected with an error string.
7382

7483
Atomics.waitAsync = function (ia, index_, value_, timeout_) {
75-
if (typeof ia != "object" || !(ia instanceof Int32Array) || !(ia.buffer instanceof SharedArrayBuffer))
76-
throw new TypeError("Expected shared memory");
84+
if (typeof ia != "object" ||
85+
(!(ia instanceof Int32Array) && !(ia instanceof BigInt64Array)) ||
86+
!(ia.buffer instanceof SharedArrayBuffer)) {
87+
throw new TypeError("Expected shared memory");
88+
}
7789

7890
// These conversions only approximate the desired semantics but are
7991
// close enough for the polyfill.
80-
92+
let coersion = ia instanceof BigInt64Array ? (v => ToBigInt64(v)) : (v => v|0);
8193
let index = index_|0;
82-
let value = value_|0;
94+
let value = coersion(value_);
8395
let timeout = timeout_ === undefined ? Infinity : +timeout_;
8496

8597
// Range checking for the index.

0 commit comments

Comments
 (0)