[streams] Implement teeing, plus a bunch of stage-setting tweaks (#311)

This PR supercedes #302. It is based on the same algorithm, but fully formalized and moved into the spec.

To get it formalized, I had to do a lot of cleanup around other abstract operations---mostly factoring out abstract operations from places that used to be accessible only through the public API. This should help create a better version of https://github.com/yutakahirano/fetch-with-streams/pull/28, for example. Each of the commits should be pretty simple to review individually.

The only real decisions that I want to highlight are:

- From https://github.com/whatwg/streams/pull/302#issuecomment-83484519, I chose "both cancels reject".
- The public `rs.tee()` method does not do any cloning; the TeeReadableStream abstract operation takes a second parameter that lets you decide whether to do structured cloning or not. Presumably for uses that will share across threads, like much of fetch, we'll need cloning.
- Should we expose `rs.tee()` at all? I mostly exposed it because otherwise my unit testing setup was not able to test it :P. But I can work around that, certainly. Maybe it is best to leave it off for now? I am a bit afraid that having non-cloning `rs.tee()` available would be a footgun for fetch body streams, given that many of the things you do with fetch body streams involve shuffling them off to another thread. Or do we assume that if you're going to do such things, you'll use the whole `response` object, and if you do `response.body.tee()`, you know what you're getting in to? That also seems plausible.
You can view, comment on, or merge this pull request online at:

  https://github.com/whatwg/streams/pull/311

-- Commit Summary --

  * Factor out a new CloseReadableStream abstract operation
  * Factor out a new EnqueueInReadableStream abstract operation
  * Tidy up precondition checking in ErrorReadableStream
  * Add and update notes on using abstract ops from other specs
  * Factor out ReadFromReadableStreamReader abstract operation
  * Tweak spec mechanics of WritableStream Error Functions
  * Implement readable stream teeing

-- File Changes --

    M index.bs (371)
    M reference-implementation/lib/helpers.js (11)
    M reference-implementation/lib/readable-stream.js (353)
    M reference-implementation/lib/writable-stream.js (66)
    M reference-implementation/test/brand-checks.js (9)
    A reference-implementation/test/readable-stream-tee.js (170)

-- Patch Links --

https://github.com/whatwg/streams/pull/311.patch
https://github.com/whatwg/streams/pull/311.diff

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/311

Received on Tuesday, 31 March 2015 23:09:13 UTC