stream: consolidate non-op algorithm callbacks

The start, pull, and write non-op algorithms are all raw callbacks with
an identical empty body now, so a single shared nonOpCallback replaces
nonOpStart, nonOpPull, and nonOpWrite.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/65138
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Matteo Collina authored and Antoine du Hamel committed 2026-08-27 14:17:04 +02:00
1 parent c577669825
commit 859ea01cb2
3 files changed
+19 -25

No files matched your search

+10 -11
View File
@@ -116,9 +116,8 @@ const {
kType,
lazyTransfer,
materializeQueue,
nonOpCallback,
nonOpCancel,
nonOpPull,
nonOpStart,
rejectedHandledRecord,
resetQueue,
resolvedRecord,
@@ -1447,7 +1446,7 @@ function readableStreamFromIterable(iterable) {
if (iterator === null || (typeof iterator !== 'object' && typeof iterator !== 'function')) {
throw new ERR_INVALID_STATE.TypeError('The iterator method must return an object');
}
const startAlgorithm = nonOpStart;
const startAlgorithm = nonOpCallback;
async function pullAlgorithm() {
const iterResult = await iterator.next();
@@ -1929,9 +1928,9 @@ function readableStreamDefaultTee(stream, cloneForBranch2) {
}
branch1 =
createReadableStream(nonOpStart, pullAlgorithm, cancel1Algorithm);
createReadableStream(nonOpCallback, pullAlgorithm, cancel1Algorithm);
branch2 =
createReadableStream(nonOpStart, pullAlgorithm, cancel2Algorithm);
createReadableStream(nonOpCallback, pullAlgorithm, cancel2Algorithm);
PromisePrototypeThen(
readerClosedPromise(reader).promise,
@@ -2217,9 +2216,9 @@ function readableByteStreamTee(stream) {
}
branch1 =
createReadableByteStream(nonOpStart, pull1Algorithm, cancel1Algorithm);
createReadableByteStream(nonOpCallback, pull1Algorithm, cancel1Algorithm);
branch2 =
createReadableByteStream(nonOpStart, pull2Algorithm, cancel2Algorithm);
createReadableByteStream(nonOpCallback, pull2Algorithm, cancel2Algorithm);
forwardReaderError(reader);
@@ -2862,10 +2861,10 @@ function setupReadableStreamDefaultControllerFromSource(
const cancel = source?.cancel;
const startAlgorithm = start ?
FunctionPrototypeBind(start, source, controller) :
nonOpStart;
nonOpCallback;
const pullAlgorithm = pull ?
createRawCallback1Param('source.pull', pull, source) :
nonOpPull;
nonOpCallback;
const cancelAlgorithm = cancel ?
createPromiseCallback1Param('source.cancel', cancel, source) :
nonOpCancel;
@@ -3743,10 +3742,10 @@ function setupReadableByteStreamControllerFromSource(
const autoAllocateChunkSize = source?.autoAllocateChunkSize;
const startAlgorithm = start ?
FunctionPrototypeBind(start, source, controller) :
nonOpStart;
nonOpCallback;
const pullAlgorithm = pull ?
createRawCallback1Param('source.pull', pull, source) :
nonOpPull;
nonOpCallback;
const cancelAlgorithm = cancel ?
createPromiseCallback1Param('source.cancel', cancel, source) :
nonOpCancel;
+6 -10
View File
@@ -418,17 +418,14 @@ function setPromiseHandled(promise) {
async function nonOpFlush() {}
function nonOpStart() {}
// nonOpPull and nonOpWrite are raw callbacks (see createRawCallback*):
// their non-thenable return takes the allocation-free fast path in
// Shared non-op for the start/pull/write algorithm callbacks, which all
// follow the raw-callback contract (see createRawCallback*): the
// non-thenable return takes the allocation-free fast path in
// thenAlgorithmResult().
function nonOpPull() {}
function nonOpCallback() {}
async function nonOpCancel() {}
function nonOpWrite() {}
let transfer;
function lazyTransfer() {
if (transfer === undefined)
@@ -465,11 +462,10 @@ module.exports = {
kType,
lazyTransfer,
materializeQueue,
nonOpCallback,
nonOpCancel,
nonOpFlush,
nonOpPull,
nonOpStart,
nonOpWrite,
peekQueueValue,
rejectedHandledRecord,
resetQueue,
+3 -4
View File
@@ -70,9 +70,8 @@ const {
kState,
kType,
lazyTransfer,
nonOpCallback,
nonOpCancel,
nonOpStart,
nonOpWrite,
peekQueueValue,
rejectedHandledRecord,
resetQueue,
@@ -1336,10 +1335,10 @@ function setupWritableStreamDefaultControllerFromSink(
const abort = sink?.abort;
const startAlgorithm = start ?
FunctionPrototypeBind(start, sink, controller) :
nonOpStart;
nonOpCallback;
const writeAlgorithm = write ?
createRawCallback2Params('sink.write', write, sink) :
nonOpWrite;
nonOpCallback;
const closeAlgorithm = close ?
createPromiseCallbackNoParams('sink.close', close, sink) :
nonOpCancel;