Skip to content
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

Do not throw when calling RS's controller.error() #895

Merged
merged 2 commits into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 11 additions & 25 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,8 +1045,8 @@ noticeable asymmetry between the two branches, and limits the possible <a>chunks
1. Set _branch2_ to CreateReadableStream(_startAlgorithm_, _pullAlgorithm_, _cancel2Algorithm_).
1. <a>Upon rejection</a> of _reader_.[[closedPromise]] with reason _r_,
1. If _closedOrErrored_ is *false*, then:
1. Perform ! ReadableStreamDefaultControllerErrorIfNeeded(_branch1_.[[readableStreamController]], _r_).
1. Perform ! ReadableStreamDefaultControllerErrorIfNeeded(_branch2_.[[readableStreamController]], _r_).
1. Perform ! ReadableStreamDefaultControllerError(_branch1_.[[readableStreamController]], _r_).
1. Perform ! ReadableStreamDefaultControllerError(_branch2_.[[readableStreamController]], _r_).
1. Set _closedOrErrored_ to *true*.
1. Return « _branch1_, _branch2_ ».
</emu-alg>
Expand Down Expand Up @@ -1746,8 +1746,6 @@ desiredSize</h5>

<emu-alg>
1. If ! IsReadableStreamDefaultController(*this*) is *false*, throw a *TypeError* exception.
1. Let _stream_ be *this*.[[controlledReadableStream]].
1. If _stream_.[[state]] is not `"readable"`, throw a *TypeError* exception.
1. Perform ! ReadableStreamDefaultControllerError(*this*, _e_).
</emu-alg>

Expand Down Expand Up @@ -1806,7 +1804,7 @@ nothrow>ReadableStreamDefaultControllerCallPullIfNeeded ( <var>controller</var>
1. Set _controller_.[[pullAgain]] to *false*.
1. Perform ! ReadableStreamDefaultControllerCallPullIfNeeded(_controller_).
1. <a>Upon rejection</a> of _pullPromise_ with reason _e_,
1. Perform ! ReadableStreamDefaultControllerErrorIfNeeded(_controller_, _e_).
1. Perform ! ReadableStreamDefaultControllerError(_controller_, _e_).
</emu-alg>

<h4 id="readable-stream-default-controller-should-call-pull" aoid="ReadableStreamDefaultControllerShouldCallPull"
Expand Down Expand Up @@ -1854,12 +1852,12 @@ asserts).
1. Let _result_ be the result of performing _controller_.[[strategySizeAlgorithm]], passing in _chunk_, and
interpreting the result as an ECMAScript completion value.
1. If _result_ is an abrupt completion,
1. Perform ! ReadableStreamDefaultControllerErrorIfNeeded(_controller_, _result_.[[Value]]).
1. Perform ! ReadableStreamDefaultControllerError(_controller_, _result_.[[Value]]).
1. Return _result_.
1. Let _chunkSize_ be _result_.[[Value]].
1. Let _enqueueResult_ be EnqueueValueWithSize(_controller_, _chunk_, _chunkSize_).
1. If _enqueueResult_ is an abrupt completion,
1. Perform ! ReadableStreamDefaultControllerErrorIfNeeded(_controller_, _enqueueResult_.[[Value]]).
1. Perform ! ReadableStreamDefaultControllerError(_controller_, _enqueueResult_.[[Value]]).
1. Return _enqueueResult_.
1. Perform ! ReadableStreamDefaultControllerCallPullIfNeeded(_controller_).
</emu-alg>
Expand All @@ -1874,19 +1872,11 @@ an assert).

<emu-alg>
1. Let _stream_ be _controller_.[[controlledReadableStream]].
1. Assert: _stream_.[[state]] is `"readable"`.
1. If _stream_.[[state]] is not `"readable"`, return.
1. Perform ! ResetQueue(_controller_).
1. Perform ! ReadableStreamError(_stream_, _e_).
</emu-alg>

<h4 id="readable-stream-default-controller-error-if-needed" aoid="ReadableStreamDefaultControllerErrorIfNeeded"
nothrow>ReadableStreamDefaultControllerErrorIfNeeded ( <var>controller</var>, <var>e</var> )</h4>

<emu-alg>
1. If _controller_.[[controlledReadableStream]].[[state]] is `"readable"`, perform !
ReadableStreamDefaultControllerError(_controller_, _e_).
</emu-alg>

<h4 id="readable-stream-default-controller-get-desired-size" aoid="ReadableStreamDefaultControllerGetDesiredSize"
nothrow export>ReadableStreamDefaultControllerGetDesiredSize ( <var>controller</var> )</h4>

Expand Down Expand Up @@ -1951,7 +1941,7 @@ throws>SetUpReadableStreamDefaultController(<var>stream</var>, <var>controller</
1. Assert: _controller_.[[pullAgain]] is *false*.
1. Perform ! ReadableStreamDefaultControllerCallPullIfNeeded(_controller_).
1. <a>Upon rejection</a> of _startPromise_ with reason _r_,
1. Perform ! ReadableStreamDefaultControllerErrorIfNeeded(_controller_, _r_).
1. Perform ! ReadableStreamDefaultControllerError(_controller_, _r_).
</emu-alg>

<h4 id="set-up-readable-stream-default-controller-from-underlying-source"
Expand Down Expand Up @@ -2169,8 +2159,6 @@ ReadableByteStreamController()</h4>

<emu-alg>
1. If ! IsReadableByteStreamController(*this*) is *false*, throw a *TypeError* exception.
1. Let _stream_ be *this*.[[controlledReadableByteStream]].
1. If _stream_.[[state]] is not `"readable"`, throw a *TypeError* exception.
1. Perform ! ReadableByteStreamControllerError(*this*, _e_).
</emu-alg>

Expand Down Expand Up @@ -2343,8 +2331,7 @@ nothrow>ReadableByteStreamControllerCallPullIfNeeded ( <var>controller</var> )</
1. Set _controller_.[[pullAgain]] to *false*.
1. Perform ! ReadableByteStreamControllerCallPullIfNeeded(_controller_).
1. <a>Upon rejection</a> of _pullPromise_ with reason _e_,
1. If _controller_.[[controlledReadableByteStream]].[[state]] is `"readable"`, perform
! ReadableByteStreamControllerError(_controller_, _e_).
1. Perform ! ReadableByteStreamControllerError(_controller_, _e_).
</emu-alg>

<h4 id="readable-byte-stream-controller-clear-pending-pull-intos"
Expand Down Expand Up @@ -2451,7 +2438,7 @@ nothrow>ReadableByteStreamControllerError ( <var>controller</var>, <var>e</var>

<emu-alg>
1. Let _stream_ be _controller_.[[controlledReadableByteStream]].
1. Assert: _stream_.[[state]] is `"readable"`.
1. If _stream_.[[state]] is not `"readable"`, return.
1. Perform ! ReadableByteStreamControllerClearPendingPullIntos(_controller_).
1. Perform ! ResetQueue(_controller_).
1. Perform ! ReadableStreamError(_stream_, _e_).
Expand Down Expand Up @@ -2730,7 +2717,7 @@ throws>SetUpReadableByteStreamController ( <var>stream</var>, <var>controller</v
1. Assert: _controller_.[[pullAgain]] is *false*.
1. Perform ! ReadableByteStreamControllerCallPullIfNeeded(_controller_).
1. <a>Upon rejection</a> of _startPromise_ with reason _r_,
1. If _stream_.[[state]] is `"readable"`, perform ! ReadableByteStreamControllerError(_controller_, _r_).
1. Perform ! ReadableByteStreamControllerError(_controller_, _r_).
</emu-alg>

<h4 id="set-up-readable-byte-stream-controller-from-underlying-source"
Expand Down Expand Up @@ -4420,8 +4407,7 @@ throws.</p>
<var>e</var> )</h4>

<emu-alg>
1. If _stream_.[[readable]].[[state]] is `"readable"`, perform !
ReadableStreamDefaultControllerError(_stream_.[[readable]].[[readableStreamController]], _e_).
1. Perform ! ReadableStreamDefaultControllerError(_stream_.[[readable]].[[readableStreamController]], _e_).
1. Perform ! TransformStreamErrorWritableAndUnblockWrite(_stream_, _e_).
</emu-alg>

Expand Down
44 changes: 14 additions & 30 deletions reference-implementation/lib/readable-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ function ReadableStreamTee(stream, cloneForBranch2) {
return;
}

ReadableStreamDefaultControllerErrorIfNeeded(branch1._readableStreamController, r);
ReadableStreamDefaultControllerErrorIfNeeded(branch2._readableStreamController, r);
ReadableStreamDefaultControllerError(branch1._readableStreamController, r);
ReadableStreamDefaultControllerError(branch2._readableStreamController, r);
closedOrErrored = true;
});

Expand Down Expand Up @@ -913,11 +913,6 @@ class ReadableStreamDefaultController {
throw defaultControllerBrandCheckException('error');
}

const stream = this._controlledReadableStream;
if (stream._state !== 'readable') {
throw new TypeError(`The stream is ${stream._state} and so cannot be errored`);
}

ReadableStreamDefaultControllerError(this, e);
}

Expand Down Expand Up @@ -988,7 +983,7 @@ function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
return undefined;
},
e => {
ReadableStreamDefaultControllerErrorIfNeeded(controller, e);
ReadableStreamDefaultControllerError(controller, e);
}
)
.catch(rethrowAssertionErrorRejection);
Expand Down Expand Up @@ -1045,14 +1040,14 @@ function ReadableStreamDefaultControllerEnqueue(controller, chunk) {
try {
chunkSize = controller._strategySizeAlgorithm(chunk);
} catch (chunkSizeE) {
ReadableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE);
ReadableStreamDefaultControllerError(controller, chunkSizeE);
throw chunkSizeE;
}

try {
EnqueueValueWithSize(controller, chunk, chunkSize);
} catch (enqueueE) {
ReadableStreamDefaultControllerErrorIfNeeded(controller, enqueueE);
ReadableStreamDefaultControllerError(controller, enqueueE);
throw enqueueE;
}
}
Expand All @@ -1065,19 +1060,15 @@ function ReadableStreamDefaultControllerEnqueue(controller, chunk) {
function ReadableStreamDefaultControllerError(controller, e) {
const stream = controller._controlledReadableStream;

assert(stream._state === 'readable');
if (stream._state !== 'readable') {
return;
}

ResetQueue(controller);

ReadableStreamError(stream, e);
}

function ReadableStreamDefaultControllerErrorIfNeeded(controller, e) {
if (controller._controlledReadableStream._state === 'readable') {
ReadableStreamDefaultControllerError(controller, e);
}
}

function ReadableStreamDefaultControllerGetDesiredSize(controller) {
const stream = controller._controlledReadableStream;
const state = stream._state;
Expand Down Expand Up @@ -1145,7 +1136,7 @@ function SetUpReadableStreamDefaultController(
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
},
r => {
ReadableStreamDefaultControllerErrorIfNeeded(controller, r);
ReadableStreamDefaultControllerError(controller, r);
}
)
.catch(rethrowAssertionErrorRejection);
Expand Down Expand Up @@ -1297,11 +1288,6 @@ class ReadableByteStreamController {
throw byteStreamControllerBrandCheckException('error');
}

const stream = this._controlledReadableByteStream;
if (stream._state !== 'readable') {
throw new TypeError(`The stream is ${stream._state} and so cannot be errored`);
}

ReadableByteStreamControllerError(this, e);
}

Expand Down Expand Up @@ -1421,9 +1407,7 @@ function ReadableByteStreamControllerCallPullIfNeeded(controller) {
}
},
e => {
if (controller._controlledReadableByteStream._state === 'readable') {
ReadableByteStreamControllerError(controller, e);
}
ReadableByteStreamControllerError(controller, e);
}
)
.catch(rethrowAssertionErrorRejection);
Expand Down Expand Up @@ -1785,7 +1769,9 @@ function ReadableByteStreamControllerEnqueue(controller, chunk) {
function ReadableByteStreamControllerError(controller, e) {
const stream = controller._controlledReadableByteStream;

assert(stream._state === 'readable');
if (stream._state !== 'readable') {
return;
}

ReadableByteStreamControllerClearPendingPullIntos(controller);

Expand Down Expand Up @@ -1879,9 +1865,7 @@ function SetUpReadableByteStreamController(stream, controller, startAlgorithm, p
ReadableByteStreamControllerCallPullIfNeeded(controller);
},
r => {
if (stream._state === 'readable') {
ReadableByteStreamControllerError(controller, r);
}
ReadableByteStreamControllerError(controller, r);
}
)
.catch(rethrowAssertionErrorRejection);
Expand Down
4 changes: 1 addition & 3 deletions reference-implementation/lib/transform-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ function IsTransformStream(x) {
function TransformStreamError(stream, e) {
verbose('TransformStreamError()');

if (stream._readable._state === 'readable') {
ReadableStreamDefaultControllerError(stream._readable._readableStreamController, e);
}
ReadableStreamDefaultControllerError(stream._readable._readableStreamController, e);
TransformStreamErrorWritableAndUnblockWrite(stream, e);
}

Expand Down
2 changes: 1 addition & 1 deletion reference-implementation/web-platform-tests