Skip to content

stream: fix sizeAlgorithm validation in WritableStream #57280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
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
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',
}
);
});
Loading