Skip to content

Commit

Permalink
stream: fix sizeAlgorithm validation in WritableStream
Browse files Browse the repository at this point in the history
Signed-off-by: Daeyeon Jeong <daeyeon.dev@gmail.com>
PR-URL: #57280
Fixes: #57272
Refs: #56067
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Jason Zhang <xzha4350@gmail.com>
  • Loading branch information
daeyeon authored Mar 5, 2025
1 parent 345aa1f commit c566639
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/internal/webstreams/writablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,9 @@ function writableStreamDefaultControllerGetChunkSize(controller, chunk) {
sizeAlgorithm,
} = controller[kState];
if (sizeAlgorithm === undefined) {
assert(stream[kState].state === 'errored' || stream[kState].state === 'erroring');
assert(stream[kState].state === 'closed' ||
stream[kState].state === 'errored' ||
stream[kState].state === 'erroring');
return 1;
}

Expand Down
29 changes: 29 additions & 0 deletions test/parallel/test-whatwg-writablestream-close.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

require('../common');
const { test } = require('node:test');
const assert = require('node:assert');

// https://github.com/nodejs/node/issues/57272

test('should throw error when writing after close', async (t) => {
const writable = new WritableStream({
write(chunk) {
console.log(chunk);
},
});

const writer = writable.getWriter();

await writer.write('Hello');
await writer.close();

await assert.rejects(
async () => {
await writer.write('World');
},
{
name: 'TypeError',
}
);
});

0 comments on commit c566639

Please sign in to comment.