Skip to content

Commit

Permalink
Fix TextDecoderStream's behavior when processing the end of stream
Browse files Browse the repository at this point in the history
This change fixes TextDecoderStream's "flush and enqueue" algorithm to handle the end of the stream in the same way as a call to TextDecoder's decode() method with no parameters.

Tests: web-platform-tests/wpt#29481.

Fixes #263.
  • Loading branch information
Andreu Botella authored Jun 24, 2021
1 parent 5c7f056 commit b74cc91
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions encoding.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1810,23 +1810,35 @@ steps:
<li><p>Let <var>output</var> be the <a for=/>I/O queue</a> of scalar values
« <a>end-of-queue</a> ».

<li><p>Let <var>result</var> be the result of <a>processing an item</a> with <a>end-of-queue</a>,
<var>decoder</var>'s <a for=TextDecoderCommon>decoder</a>, <var>decoder</var>'s
<a for=TextDecoderCommon>I/O queue</a>, <var>output</var>, and <var>decoder</var>'s
<a for=TextDecoderCommon>error mode</a>.

<li>
<p>If <var>result</var> is <a>finished</a>, then:
<p>While true:

<ol>
<li><p>Let <var>outputChunk</var> be the result of running <a>serialize I/O queue</a> with
<var>decoder</var> and <var>output</var>.
<li><p>Let <var>item</var> be the result of <a>reading</a> from <var>decoder</var>'s
<a for=TextDecoderCommon>I/O queue</a>.

<li><p>If <var>outputChunk</var> is non-empty, then <a for=TransformStream>enqueue</a>
<var>outputChunk</var> in <var>decoder</var>'s <a for=GenericTransformStream>transform</a>.
</ol>
<li><p>Let <var>result</var> be the result of <a>processing an item</a> with <var>item</var>,
<var>decoder</var>'s <a for=TextDecoderCommon>decoder</a>, <var>decoder</var>'s
<a for=TextDecoderCommon>I/O queue</a>, <var>output</var>, and <var>decoder</var>'s
<a for=TextDecoderCommon>error mode</a>.

<li><p>Otherwise, <a>throw</a> a {{TypeError}}.
<li>
<p>If <var>result</var> is <a>finished</a>, then:

<ol>
<li><p>Let <var>outputChunk</var> be the result of running <a>serialize I/O queue</a> with
<var>decoder</var> and <var>output</var>.

<li><p>If <var>outputChunk</var> is non-empty, then <a for=TransformStream>enqueue</a>
<var>outputChunk</var> in <var>decoder</var>'s <a for=GenericTransformStream>transform</a>.

<li><p>Return.
</ol>
</li>

<li><p>Otherwise, if <var>result</var> is <a>error</a>, <a>throw</a> a {{TypeError}}.
</ol>
</li>
</ol>


Expand Down

0 comments on commit b74cc91

Please sign in to comment.