Re: [whatwg/encoding] UTF-8 does not reset state when returning error (Issue #359)

hsivonen left a comment (whatwg/encoding#359)

https://github.com/web-platform-tests/wpt/blob/51a3177fe0cdf3777c84a909d249abc7ea9ddcf9/encoding/textdecoder-mistakes.any.js#L387 wants to leave stuff in the I/O queue after throwing.

The caller cannot have received the conversion up to the error, since throwing hides it: The caller doesn't get to implement its own replacement policy, because it couldn't recover the conversion before the error. That is, having something in the queue after throw isn't useful, but it could be a problem.

At least reset on throw leaves the decoder in a predictable state after throwing.

Furthermore, in Gecko, `TextDecoder` does not actually maintain I/O queue on the heap in a way that could allow the I/O queue to continue to exist in a non-empty state after return or throw. Introducing this would pessimize performance and, considering the above observation about lack of usefulness, for no good reason.

So I think we should reset the decoder when throwing.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/encoding/issues/359#issuecomment-6980176216
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/encoding/issues/359/6980176216@github.com>

Received on Wednesday, 18 November 2026 13:37:02 UTC