Skip to content

Commit 15d7908

Browse files
daeyeonaduh95
authored andcommittedMar 9, 2025
stream: fix sizeAlgorithm validation in WritableStream
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>
1 parent 7a554d9 commit 15d7908

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed
 

‎lib/internal/webstreams/writablestream.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,9 @@ function writableStreamDefaultControllerGetChunkSize(controller, chunk) {
11811181
sizeAlgorithm,
11821182
} = controller[kState];
11831183
if (sizeAlgorithm === undefined) {
1184-
assert(stream[kState].state === 'errored' || stream[kState].state === 'erroring');
1184+
assert(stream[kState].state === 'closed' ||
1185+
stream[kState].state === 'errored' ||
1186+
stream[kState].state === 'erroring');
11851187
return 1;
11861188
}
11871189

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
require('../common');
4+
const { test } = require('node:test');
5+
const assert = require('node:assert');
6+
7+
// https://github.com/nodejs/node/issues/57272
8+
9+
test('should throw error when writing after close', async (t) => {
10+
const writable = new WritableStream({
11+
write(chunk) {
12+
console.log(chunk);
13+
},
14+
});
15+
16+
const writer = writable.getWriter();
17+
18+
await writer.write('Hello');
19+
await writer.close();
20+
21+
await assert.rejects(
22+
async () => {
23+
await writer.write('World');
24+
},
25+
{
26+
name: 'TypeError',
27+
}
28+
);
29+
});

0 commit comments

Comments
 (0)
Please sign in to comment.