From 3111ed7011e03eef7ccf7a27d0d7657e6a4e1cc4 Mon Sep 17 00:00:00 2001 From: devstone <81923229+Nahee-Park@users.noreply.github.com> Date: Tue, 1 Oct 2024 02:54:43 +0900 Subject: [PATCH] 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 Reviewed-By: Matthew Aitken --- lib/internal/webstreams/encoding.js | 4 ++++ test/wpt/status/encoding.json | 7 ------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/internal/webstreams/encoding.js b/lib/internal/webstreams/encoding.js index b5533b4287b65a..f316222ccbf0e8 100644 --- a/lib/internal/webstreams/encoding.js +++ b/lib/internal/webstreams/encoding.js @@ -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); diff --git a/test/wpt/status/encoding.json b/test/wpt/status/encoding.json index e78a8b3c0791be..f9378d7195a2a7 100644 --- a/test/wpt/status/encoding.json +++ b/test/wpt/status/encoding.json @@ -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"] },