Re: [whatwg/streams] Add a brand check to pipeThrough() (#966)

MattiasBuelens commented on this pull request.



> -     values are not permitted.
-     <p class="note"><emu-val>undefined</emu-val> is special-cased here to make it easier to debug errors such as
-     <code>rs.pipeThrough(writable, readable)</code> which otherwise would silently do nothing. <code><a
-     lt="pipeThrough()" for="ReadableStream">pipeThrough()</a></code> is
-     otherwise agnostic about the values that it passes through.</p>
-  1. Let _promise_ be ? Invoke(*this*, `"pipeTo"`, « _writable_, _options_ »).
-  1. If Type(_promise_) is Object and _promise_ has a [[PromiseIsHandled]] internal slot, set
-     _promise_.[[PromiseIsHandled]] to *true*.
+  1. If ! IsReadableStream(*this*) is *false*, throw a *TypeError* exception.
+  1. If ! IsWritableStream(_writable_) is *false*, throw a *TypeError* exception.
+  1. If ! IsReadableStream(_readable_) is *false*, throw a *TypeError* exception
+  1. Set _preventClose_ to ! ToBoolean(_preventClose_), set _preventAbort_ to ! ToBoolean(_preventAbort_), and set
+     _preventCancel_ to ! ToBoolean(_preventCancel_).
+  1. If _signal_ is not *undefined*, and _signal_ is not an instance of the `<a idl>AbortSignal</a>` interface, throw a
+     *TypeError* exception.
+  1. If ! IsReadableStreamLocked(*this*) is *true*, throw a *TypeError* exception.

Agreed, sync exceptions make the most sense. [WebIDL says](https://heycam.github.io/webidl/#dfn-create-operation-function) that you should return a rejected promise if the function's return type is a promise, and otherwise you should throw an exception. Since `pipeThrough` returns a `ReadableStream`, sync exceptions would be the correct choice. 🙂

> The alternative would be to error `readable`.

This seems like a bad alternative, for all the reasons you've mentioned. It would be very unexpected that a wrong *usage* of the stream would cause it to error.

-- 
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/pull/966#discussion_r236579380

Received on Tuesday, 27 November 2018 09:28:30 UTC