Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/internal/streams/fast-utf8-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ const {
const BUSY_WRITE_TIMEOUT = 100;
const kEmptyBuffer = Buffer.allocUnsafe(0);

const kNil = new Int32Array(new SharedArrayBuffer(4));
const haveSAB = typeof SharedArrayBuffer !== 'undefined';
const kNil = haveSAB ? new Int32Array(new SharedArrayBuffer(4)) : null;
Comment on lines +52 to +53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the haveSAB variable useful?

Suggested change
const haveSAB = typeof SharedArrayBuffer !== 'undefined';
const kNil = haveSAB ? new Int32Array(new SharedArrayBuffer(4)) : null;
const kNil = SharedArrayBuffer && new Int32Array(new SharedArrayBuffer(4));

Copy link
Member Author

@codebytere codebytere Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aduh95 we need it below to choose sleep implementation, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use kNil for that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggested code would throw an error if SharedArrayBuffer is not defined.

Copy link
Contributor

@aduh95 aduh95 Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is declared above, it wouldn't throw even if undefined:


function sleep(ms) {
// Also filters out NaN, non-number types, including empty strings, but allows bigints
Expand All @@ -61,8 +62,12 @@ function sleep(ms) {
throw new ERR_INVALID_ARG_VALUE.RangeError('ms', ms,
'must be a number greater than 0 and less than Infinity');
}

AtomicsWait(kNil, 0, 0, Number(ms));
if (haveSAB) {
AtomicsWait(kNil, 0, 0, Number(ms));
} else {
const { sleep: _sleep } = internalBinding('util');
_sleep(ms);
}
}

// 16 KB. Don't write more than docker buffer size.
Expand Down
Loading