Re: [whatwg/streams] Factor out condition to check pending operation (#672)

Commit message draft

Bug fix:
- `WritableStreamDefaultWriter` should be constructed with its `[[readyPromise]]` rejected if the stream has a pending `abort()` or is `"errored"`
- `abort()` should be rejected with the error passed to `controller.error()` called during a pending `write()`/`close()`. Not the rejection reason of the `write()`/`close()` (fix in `WritableStreamFinishPendingCloseWithError()`)

Promise resolution order change:
- Moved `[[readyPromise]]` resolution in `WritableStreamDefaultWriterRelease()` to be consistent with the other places
- Reject `[[readyPromise]]` before aborting pending `abort()`

Refactoring:
- Renamed `[[pendingWriteRequest]]` to `[[inflightWriteRequest]]`
- Changed `[[writing]]` users to use `[[inflightWriteRequest]]`
- Added `[[inflightCloseRequest]]` to replace `[[inClose]]`
- Renamed `[[pendingCloseRequest]]` to `[[closeRequest]]`
  - More aligned with `[[writeRequests]]`
  - Less confusing as it's role is not so similar to `[[pendingAbortRequest]]`
- Removed `"closing"` state and let the users investigate whether or not `[[closeRequest]]` is *undefined* instead
- Let WritableStream remember the last backpressure signal in `[[backpressure]]`
  - `eliminates WritableStreamDefaultControllerGetBackpressure()` calls
- Factored out common logic into `WritableStreamHasOperationMarkedInflight()`
- Factored `readyPromiseIsPending` calculation logic into `WritableStreamIsReadyForWrites()` (merged from #671)
  - Also moved the `readyPromiseIsPending` calculation to as earlier position as possible in the caller methods so that we're less likely to call the newly introduced method after changing some of state variables by mistake. However, while doing so, found that calling this method in `WritableStreamDefaultControllerError()` is problematic. Since `WritableStreamDefaultControllerError()` can be called while the instantiated controller is not yet set to the stream i.e. inside `sink.start()`. There's similar hack at the bottom of `WritableStreamDefaultControllerError()` though it seems no longer working (before c6c0a6e68a427be34f0bd1166c991f811379c32a, it was placed in `WritableStreamError()` and retrieving the controller from the stream instance, and therefore had the same issue).
  - Rather than getting bothered by these corner case handling now and in the future, this patch let the stream finish instantiation of a controller and then invoke `sink.start()`. The split logic is put in a method named `WritableStreamDefaultControllerStart()`. It's a part of the controller since it touches variables encapsulated in the controller. This change doesn't break the mechanism in the `WritableStreamDefaultController()`'s constructor to prevent it from being invoked manually.
- Factored out pending `abort()` rejection logic into `WritableStreamRejectPendingAbortRequest()`

Editorial:
- Moved `WritableStreamDefaultWriterEnsureReadyPromiseRejectedWith()` to the right section

-- 
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/672#issuecomment-275343563

Received on Thursday, 26 January 2017 09:30:15 UTC