stream: handle undefined chunks correctly in decode stream

Align TextDecoderStream behavior with WPT requirements by treating
undefined chunks as errors. This change ensures that TextDecoderStream
properly handles unexpected chunk types and throws an error when
receiving undefined input.

This update addresses the failing WPT for decode stream error handling.

PR-URL: https://github.com/nodejs/node/pull/55153
Reviewed-By: Mattias Buelens <mattias@buelens.com>
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
This commit is contained in:
devstone 2024-10-01 02:54:43 +09:00 committed by Michaël Zasso
parent aaea3944e5
commit c7ed2ff920
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600
2 changed files with 4 additions and 7 deletions

View File

@ -20,6 +20,7 @@ const { customInspect } = require('internal/webstreams/util');
const {
codes: {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_THIS,
},
} = require('internal/errors');
@ -133,6 +134,9 @@ class TextDecoderStream {
this.#handle = new TextDecoder(encoding, options);
this.#transform = new TransformStream({
transform: (chunk, controller) => {
if (chunk === undefined) {
throw new ERR_INVALID_ARG_TYPE('chunk', 'string', chunk);
}
const value = this.#handle.decode(chunk, { stream: true });
if (value)
controller.enqueue(value);

View File

@ -66,13 +66,6 @@
"streams/decode-utf8.any.js": {
"requires": ["small-icu"]
},
"streams/decode-bad-chunks.any.js": {
"fail": {
"expected": [
"chunk of type undefined should error the stream"
]
}
},
"streams/decode-non-utf8.any.js": {
"requires": ["full-icu"]
},