Skip to content

Commit 5f640c4

Browse files
Nahee-Parktargos
authored andcommitted
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: #55153 Reviewed-By: Mattias Buelens <mattias@buelens.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
1 parent b8cc62b commit 5f640c4

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

lib/internal/webstreams/encoding.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const { customInspect } = require('internal/webstreams/util');
2020

2121
const {
2222
codes: {
23+
ERR_INVALID_ARG_TYPE,
2324
ERR_INVALID_THIS,
2425
},
2526
} = require('internal/errors');
@@ -133,6 +134,9 @@ class TextDecoderStream {
133134
this.#handle = new TextDecoder(encoding, options);
134135
this.#transform = new TransformStream({
135136
transform: (chunk, controller) => {
137+
if (chunk === undefined) {
138+
throw new ERR_INVALID_ARG_TYPE('chunk', 'string', chunk);
139+
}
136140
const value = this.#handle.decode(chunk, { stream: true });
137141
if (value)
138142
controller.enqueue(value);

test/wpt/status/encoding.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,6 @@
6666
"streams/decode-utf8.any.js": {
6767
"requires": ["small-icu"]
6868
},
69-
"streams/decode-bad-chunks.any.js": {
70-
"fail": {
71-
"expected": [
72-
"chunk of type undefined should error the stream"
73-
]
74-
}
75-
},
7669
"streams/decode-non-utf8.any.js": {
7770
"requires": ["full-icu"]
7871
},

0 commit comments

Comments
 (0)