Skip to content

Commit 38de540

Browse files
committed
lib: check SharedArrayBuffer existence in fast-utf8-stream
1 parent 5bd2152 commit 38de540

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/internal/streams/fast-utf8-stream.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ const {
4949
const BUSY_WRITE_TIMEOUT = 100;
5050
const kEmptyBuffer = Buffer.allocUnsafe(0);
5151

52-
const kNil = new Int32Array(new SharedArrayBuffer(4));
52+
const haveSAB = typeof SharedArrayBuffer !== 'undefined';
53+
const kNil = haveSAB ? new Int32Array(new SharedArrayBuffer(4)) : null;
5354

5455
function sleep(ms) {
5556
// Also filters out NaN, non-number types, including empty strings, but allows bigints
@@ -61,8 +62,12 @@ function sleep(ms) {
6162
throw new ERR_INVALID_ARG_VALUE.RangeError('ms', ms,
6263
'must be a number greater than 0 and less than Infinity');
6364
}
64-
65-
AtomicsWait(kNil, 0, 0, Number(ms));
65+
if (haveSAB) {
66+
AtomicsWait(kNil, 0, 0, Number(ms));
67+
} else {
68+
const { sleep: _sleep } = internalBinding('util');
69+
_sleep(ms);
70+
}
6671
}
6772

6873
// 16 KB. Don't write more than docker buffer size.

0 commit comments

Comments
 (0)