-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a brand check to pipeThrough() #966
Conversation
Require pipeThrough() to be called on a ReadableStream. Stop delegating to this.pipeTo(). Also throw exceptions if *this* or _writable_ are not streams or they are locked, or if *signal* is not an AbortSignal. Also require _readable_ to be a ReadableStream. Add a new abstract operation, ReadableStreamPipeTo(), which is used internally by pipeTo() and pipeThrough() and also can be referenced from other standards. Closes whatwg#961.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nits... will check the tests to ensure they test the changed semantics.
@@ -661,31 +661,31 @@ option. If <code><a for="underlying source">type</a></code> is set to <code>unde | |||
</div> | |||
|
|||
<h5 id="rs-pipe-through" method for="ReadableStream" lt="pipeThrough(transform, options)">pipeThrough({ | |||
<var ignore>writable</var>, <var ignore>readable</var> }, <var ignore>options</var>)</h5> | |||
<var ignore>writable</var>, <var ignore>readable</var> }, { <var>preventClose</var>, <var>preventAbort</var>, | |||
<var>preventCancel</var>, <var>signal</var> } = {})</h5> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also update the class definition to use this style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
_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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that these now throw sync exceptions instead of returning a rejected promise that gets ignored. This is probably the right thing to do...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alternative would be to error readable
. That would have the benefit that the whole pipe chain would be errored in the normal case, and so you'd get a rejection rather than an exception. But it wouldn't work properly if readable
was locked. It also would be a big departure from our behaviour up until now of passing through readable
unchanged.
On balance, I think throwing an exception here is the best approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, sync exceptions make the most sense. WebIDL says 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.
When merging this we should be sure to file browser bugs; see https://github.com/whatwg/meta/blob/master/MAINTAINERS.md#handling-pull-requests |
Reflect the new definition of pipeThrough
4d98b9e
to
781a711
Compare
I filed https://bugs.chromium.org/p/chromium/issues/detail?id=908747 for Chrome. Edge and Firefox don't have implementations. It would probably not be helpful to file issues saying "implement pipeThrough". Safari appears to have a semi-functional pipeThrough that delegates to a non-functional pipeTo. I've no idea what to do about that. |
LGTM, merge at will after the tests. I forgot about the implementation status, so yeah, probably it's OK to not do the bugs... |
…14193) Remove tests that ReadableStream.prototype.pipeThrough operates generically on its arguments. Add tests that it performs brand checks on |this|, |readable| and |writable|, and throws for other precondition failures. Also verify that it *doesn't* call pipeTo(). Also verify that preventClose, preventCancel and preventAbort work, since we can no longer test that it passes through to pipeTo(). Also change the expected length of the function from 2 to 1 to reflect that the options argument is optional. Corresponding standard changes are at whatwg/streams#966.
…ough() having a brand check, a=testonly Automatic update from web-platform-tests ReadableStream: modify tests for pipeThrough() having a brand check (#14193) Remove tests that ReadableStream.prototype.pipeThrough operates generically on its arguments. Add tests that it performs brand checks on |this|, |readable| and |writable|, and throws for other precondition failures. Also verify that it *doesn't* call pipeTo(). Also verify that preventClose, preventCancel and preventAbort work, since we can no longer test that it passes through to pipeTo(). Also change the expected length of the function from 2 to 1 to reflect that the options argument is optional. Corresponding standard changes are at whatwg/streams#966. -- wpt-commits: 4606e75ca8cd69830223f02e0fbd46fc160f431f wpt-pr: 14193
…ough() having a brand check, a=testonly Automatic update from web-platform-tests ReadableStream: modify tests for pipeThrough() having a brand check (#14193) Remove tests that ReadableStream.prototype.pipeThrough operates generically on its arguments. Add tests that it performs brand checks on |this|, |readable| and |writable|, and throws for other precondition failures. Also verify that it *doesn't* call pipeTo(). Also verify that preventClose, preventCancel and preventAbort work, since we can no longer test that it passes through to pipeTo(). Also change the expected length of the function from 2 to 1 to reflect that the options argument is optional. Corresponding standard changes are at whatwg/streams#966. -- wpt-commits: 4606e75ca8cd69830223f02e0fbd46fc160f431f wpt-pr: 14193
…ough() having a brand check, a=testonly Automatic update from web-platform-tests ReadableStream: modify tests for pipeThrough() having a brand check (#14193) Remove tests that ReadableStream.prototype.pipeThrough operates generically on its arguments. Add tests that it performs brand checks on |this|, |readable| and |writable|, and throws for other precondition failures. Also verify that it *doesn't* call pipeTo(). Also verify that preventClose, preventCancel and preventAbort work, since we can no longer test that it passes through to pipeTo(). Also change the expected length of the function from 2 to 1 to reflect that the options argument is optional. Corresponding standard changes are at whatwg/streams#966. -- wpt-commits: 4606e75ca8cd69830223f02e0fbd46fc160f431f wpt-pr: 14193
…ough() having a brand check, a=testonly Automatic update from web-platform-tests ReadableStream: modify tests for pipeThrough() having a brand check (#14193) Remove tests that ReadableStream.prototype.pipeThrough operates generically on its arguments. Add tests that it performs brand checks on |this|, |readable| and |writable|, and throws for other precondition failures. Also verify that it *doesn't* call pipeTo(). Also verify that preventClose, preventCancel and preventAbort work, since we can no longer test that it passes through to pipeTo(). Also change the expected length of the function from 2 to 1 to reflect that the options argument is optional. Corresponding standard changes are at whatwg/streams#966. -- wpt-commits: 4606e75ca8cd69830223f02e0fbd46fc160f431f wpt-pr: 14193
…ough() having a brand check, a=testonly Automatic update from web-platform-tests ReadableStream: modify tests for pipeThrough() having a brand check (#14193) Remove tests that ReadableStream.prototype.pipeThrough operates generically on its arguments. Add tests that it performs brand checks on |this|, |readable| and |writable|, and throws for other precondition failures. Also verify that it *doesn't* call pipeTo(). Also verify that preventClose, preventCancel and preventAbort work, since we can no longer test that it passes through to pipeTo(). Also change the expected length of the function from 2 to 1 to reflect that the options argument is optional. Corresponding standard changes are at whatwg/streams#966. -- wpt-commits: 4606e75ca8cd69830223f02e0fbd46fc160f431f wpt-pr: 14193 UltraBlame original commit: fcc10971a6e8c63b0ae33f833e472ba7459fd202
…ough() having a brand check, a=testonly Automatic update from web-platform-tests ReadableStream: modify tests for pipeThrough() having a brand check (#14193) Remove tests that ReadableStream.prototype.pipeThrough operates generically on its arguments. Add tests that it performs brand checks on |this|, |readable| and |writable|, and throws for other precondition failures. Also verify that it *doesn't* call pipeTo(). Also verify that preventClose, preventCancel and preventAbort work, since we can no longer test that it passes through to pipeTo(). Also change the expected length of the function from 2 to 1 to reflect that the options argument is optional. Corresponding standard changes are at whatwg/streams#966. -- wpt-commits: 4606e75ca8cd69830223f02e0fbd46fc160f431f wpt-pr: 14193 UltraBlame original commit: e1782a85a325a130ee1dd69b603f3015d5090ed1
…ough() having a brand check, a=testonly Automatic update from web-platform-tests ReadableStream: modify tests for pipeThrough() having a brand check (#14193) Remove tests that ReadableStream.prototype.pipeThrough operates generically on its arguments. Add tests that it performs brand checks on |this|, |readable| and |writable|, and throws for other precondition failures. Also verify that it *doesn't* call pipeTo(). Also verify that preventClose, preventCancel and preventAbort work, since we can no longer test that it passes through to pipeTo(). Also change the expected length of the function from 2 to 1 to reflect that the options argument is optional. Corresponding standard changes are at whatwg/streams#966. -- wpt-commits: 4606e75ca8cd69830223f02e0fbd46fc160f431f wpt-pr: 14193 UltraBlame original commit: fcc10971a6e8c63b0ae33f833e472ba7459fd202
…ough() having a brand check, a=testonly Automatic update from web-platform-tests ReadableStream: modify tests for pipeThrough() having a brand check (#14193) Remove tests that ReadableStream.prototype.pipeThrough operates generically on its arguments. Add tests that it performs brand checks on |this|, |readable| and |writable|, and throws for other precondition failures. Also verify that it *doesn't* call pipeTo(). Also verify that preventClose, preventCancel and preventAbort work, since we can no longer test that it passes through to pipeTo(). Also change the expected length of the function from 2 to 1 to reflect that the options argument is optional. Corresponding standard changes are at whatwg/streams#966. -- wpt-commits: 4606e75ca8cd69830223f02e0fbd46fc160f431f wpt-pr: 14193 UltraBlame original commit: e1782a85a325a130ee1dd69b603f3015d5090ed1
…ough() having a brand check, a=testonly Automatic update from web-platform-tests ReadableStream: modify tests for pipeThrough() having a brand check (#14193) Remove tests that ReadableStream.prototype.pipeThrough operates generically on its arguments. Add tests that it performs brand checks on |this|, |readable| and |writable|, and throws for other precondition failures. Also verify that it *doesn't* call pipeTo(). Also verify that preventClose, preventCancel and preventAbort work, since we can no longer test that it passes through to pipeTo(). Also change the expected length of the function from 2 to 1 to reflect that the options argument is optional. Corresponding standard changes are at whatwg/streams#966. -- wpt-commits: 4606e75ca8cd69830223f02e0fbd46fc160f431f wpt-pr: 14193 UltraBlame original commit: fcc10971a6e8c63b0ae33f833e472ba7459fd202
…ough() having a brand check, a=testonly Automatic update from web-platform-tests ReadableStream: modify tests for pipeThrough() having a brand check (#14193) Remove tests that ReadableStream.prototype.pipeThrough operates generically on its arguments. Add tests that it performs brand checks on |this|, |readable| and |writable|, and throws for other precondition failures. Also verify that it *doesn't* call pipeTo(). Also verify that preventClose, preventCancel and preventAbort work, since we can no longer test that it passes through to pipeTo(). Also change the expected length of the function from 2 to 1 to reflect that the options argument is optional. Corresponding standard changes are at whatwg/streams#966. -- wpt-commits: 4606e75ca8cd69830223f02e0fbd46fc160f431f wpt-pr: 14193 UltraBlame original commit: e1782a85a325a130ee1dd69b603f3015d5090ed1
Require pipeThrough() to be called on a ReadableStream. Stop delegating to
this.pipeTo().
Also throw exceptions if this or writable are not streams or they are
locked, or if signal is not an AbortSignal. Also require readable to be a
ReadableStream.
Add a new abstract operation, ReadableStreamPipeTo(), which is used internally
by pipeTo() and pipeThrough() and also can be referenced from other
standards.
Closes #961.
Preview | Diff