Re: [whatwg/streams] Setting Object.prototype.then permits interfering with pipeTo() internals (#933)

I identified another issue which I think rules out the "just fix pipeTo()" approach. `Response.prototype.blob` and friends are specified as performing [read all bytes](https://fetch.spec.whatwg.org/#ref-for-concept-read-all-bytes-from-readablestream). But in Blink's implementation we bypass the stream implementation unless the input actually came from the stream.

However, because **read all bytes** uses `ReadableStreamDefaultReaderRead` and this issue makes calls to `ReadableStreamDefaultReaderRead` observable, Blink is currently non-conformant. Making Blink conformant to the standard as it is currently written would have an unacceptable performance overhead. So I think we need to make `ReadableStreamDefaultReaderRead` unobservable in the standard.

> I guess a halfway solution is to change everything to use null-prototype iter-result objects, but have read() then re-allocate to a non-null object and transfer the value/done.

I like this very much. Concretely I'd change

> 1. Return ! [ReadableStreamDefaultReaderRead](https://streams.spec.whatwg.org/#readable-stream-default-reader-read)(**this**).

to 

> 1. Return the result of [transforming](https://www.w3.org/2001/tag/doc/promises-guide/#transforming-by)  ! [ReadableStreamDefaultReaderRead](https://streams.spec.whatwg.org/#readable-stream-default-reader-read)(**this**) with a fulfillment handler which takes the argument _result_ and returns ! [CreateIterResultObject](https://tc39.github.io/ecma262/#sec-createiterresultobject)(! [Get](https://tc39.github.io/ecma262/#sec-get-o-p)(_result_, `"value"`), ! [Get](https://tc39.github.io/ecma262/#sec-get-o-p)(_result_, `"done"`)).

Which is great except for the "efficiency problem", ie. a real implementation is going to want to create the object with the desired prototype to start with, but in order to match the behaviour of the standard they'd have to include a redundant microtask execution.

I don't know what to do about this.

-- 
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/streams/issues/933#issuecomment-400941378

Received on Thursday, 28 June 2018 07:36:18 UTC