Skip to content

Commit

Permalink
stream: handle undefined chunks correctly in decode stream
Browse files Browse the repository at this point in the history
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: #55153
Reviewed-By: Mattias Buelens <mattias@buelens.com>
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
  • Loading branch information
Nahee-Park authored and targos committed Oct 4, 2024
1 parent aaea394 commit c7ed2ff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/internal/webstreams/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const { customInspect } = require('internal/webstreams/util');

const {
codes: {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_THIS,
},
} = require('internal/errors');
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 0 additions & 7 deletions test/wpt/status/encoding.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
},
Expand Down

0 comments on commit c7ed2ff

Please sign in to comment.