Skip to content

Commit

Permalink
Readable byte stream must call pull if needed after receiving new chunk
Browse files Browse the repository at this point in the history
After a readable byte stream receives a new chunk from the underlying source, the stream must call pull() (if needed). Otherwise, the stream may get stuck.

Add calls to ReadableByteStreamControllerCallPullIfNeeded at the end of ReadableByteStreamControllerEnqueue and ReadableByteStreamControllerRespondInternal to ensure this.

Fixes #877.
  • Loading branch information
MattiasBuelens authored and ricea committed Mar 22, 2018
1 parent 293de26 commit 3fddaf8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2428,6 +2428,7 @@ nothrow>ReadableByteStreamControllerEnqueue ( <var>controller</var>, <var>chunk<
1. Assert: ! IsReadableStreamLocked(_stream_) is *false*.
1. Perform ! ReadableByteStreamControllerEnqueueChunkToQueue(_controller_, _transferredBuffer_, _byteOffset_,
_byteLength_).
1. Perform ! ReadableByteStreamControllerCallPullIfNeeded(_controller_).
</emu-alg>

<h4 id="readable-byte-stream-controller-enqueue-chunk-to-queue" aoid="ReadableByteStreamControllerEnqueueChunkToQueue"
Expand Down Expand Up @@ -2654,6 +2655,7 @@ throws>ReadableByteStreamControllerRespondInternal ( <var>controller</var>, <var
1. Otherwise,
1. Assert: _stream_.[[state]] is `"readable"`.
1. Perform ? ReadableByteStreamControllerRespondInReadableState(_controller_, _bytesWritten_, _firstDescriptor_).
1. Perform ! ReadableByteStreamControllerCallPullIfNeeded(_controller_).
</emu-alg>

<h4 id="readable-byte-stream-controller-respond-with-new-view" aoid="ReadableByteStreamControllerRespondWithNewView"
Expand Down
4 changes: 4 additions & 0 deletions reference-implementation/lib/readable-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,8 @@ function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {

ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
}

ReadableByteStreamControllerCallPullIfNeeded(controller);
}

function ReadableByteStreamControllerShiftPendingPullInto(controller) {
Expand Down Expand Up @@ -1764,6 +1766,8 @@ function ReadableByteStreamControllerEnqueue(controller, chunk) {
assert(IsReadableStreamLocked(stream) === false);
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
}

ReadableByteStreamControllerCallPullIfNeeded(controller);
}

function ReadableByteStreamControllerError(controller, e) {
Expand Down
2 changes: 1 addition & 1 deletion reference-implementation/web-platform-tests

0 comments on commit 3fddaf8

Please sign in to comment.