stream: make checking pendingcb on WritableStream backward compatible

PR-URL: https://github.com/nodejs/node/pull/54142
Fixes: https://github.com/nodejs/node/issues/54131
Refs: https://github.com/nodejs/node/issues/54131
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
This commit is contained in:
jakecastelli 2024-08-05 22:00:29 +09:30 committed by GitHub
parent a8166880f1
commit fafc845089
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -214,7 +214,7 @@ function eos(stream, options, callback) {
!readable &&
(!willEmitClose || isReadable(stream)) &&
(writableFinished || isWritable(stream) === false) &&
(wState == null || wState.pendingcb === 0)
(wState == null || wState.pendingcb === undefined || wState.pendingcb === 0)
) {
process.nextTick(onclosed);
} else if (

View File

@ -687,3 +687,16 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
assert.strictEqual(stream._writableState.pendingcb, 0);
}));
}
{
const stream = new Duplex({
write(chunk, enc, cb) {}
});
stream.end('foo');
// Simulate an old stream implementation that doesn't have pendingcb
delete stream._writableState.pendingcb;
finished(stream, { readable: false }, common.mustCall());
}