Re: [whatwg/encoding] Add TextEncoderStream and TextDecoderStream transform streams (#149)

MattiasBuelens requested changes on this pull request.

Good call using _convert to a BufferSource_, looks much nicer this way! 😄 

However, we now have an issue where detached buffers are no longer handled correctly. Should be easy enough to fix though.

> + <var>flushAlgorithm</var>).
+
+ <li><p>Set <var>dec</var>'s <a for=GenericTransformStream>transform</a> to <var>transform</var>.
+
+ <li><p>Return <var>dec</var>.
+</ol>
+
+<p>The <dfn id=concept-tds-decode-and-enqueue>decode and enqueue a chunk</dfn> algorithm, given a
+{{TextDecoderStream}} <var>dec</var> and a <var>chunk</var>, runs these steps:
+
+<ol>
+ <li><p>Let <var>bufferSource</var> be the result of
+ <a lt="converted to an IDL value">converting</a> <var>chunk</var> to a {{BufferSource}}. If this
+ throws an exception, then return a promise rejected with that exception.
+
+ <li><p><a>Push</a> a <a lt="get a copy of the buffer source">copy of</a> <var>bufferSource</var> to

In 6a65ad5da12cd43b24ee9459ea793d285f424912, we explicitly checked for `IsDetachedBuffer(arrayBuffer)` and returned a rejected promise if the buffer was detached. However, none of the three algorithms that make up [_convert to a BufferSource_](https://heycam.github.io/webidl/#es-buffer-source-types) check for detached buffers.

When [_get a copy of the buffer source_](https://heycam.github.io/webidl/#ref-for-dfn-get-buffer-source-copy%E2%91%A0) encounters a detached buffer, it throws a `TypeError` in step 7. This is not what we want: we want to return a rejected promise instead!

I think the easiest fix would be to add the following line to this step, similar to the previous step:
> If this throws an exception, then return a promise rejected with that exception.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/encoding/pull/149#pullrequestreview-144321438

Received on Wednesday, 8 August 2018 08:48:53 UTC