Skip to content

Commit

Permalink
squash! more
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek authored and MattiasBuelens committed Jan 26, 2019
1 parent ca6d2b8 commit f39c70a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ prototype, are created with the internal slots described in the following table:
<h4 id="rs-asynciterator-prototype-next" method for="ReadableStreamAsyncIteratorPrototype">next()</h4>

<emu-alg>
1. If ! IsReadableStreamAsyncIterator(*this*) is *false*, <a>a promise rejected with</a> *TypeError* exception.
1. If ! IsReadableStreamAsyncIterator(*this*) is *false*, return <a>a promise rejected with</a> *TypeError* exception.
1. Let _reader_ be *this*.[[asyncIteratorReader]].
1. If _reader_.[[ownerReadableStream]] is *undefined*, return <a>a promise rejected with</a> a *TypeError* exception.
1. Return ! ReadableStreamDefaultReaderRead(_reader_, *true*).
Expand Down
20 changes: 13 additions & 7 deletions reference-implementation/lib/readable-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,36 +175,38 @@ const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async
const ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf({
next() {
if (IsReadableStreamAsyncIterator(this) === false) {
return Promise.reject(new TypeError());
return Promise.reject(streamAsyncIteratorBrandCheckException('next'));
}
const reader = this._asyncIteratorReader;
if (reader._ownerReadableStream === undefined) {
return Promise.reject(new TypeError());
return Promise.reject(readerLockException('next'));
}
return ReadableStreamDefaultReaderRead(reader, true);
},

return(value) {
if (IsReadableStreamAsyncIterator(this) === false) {
return Promise.reject(new TypeError());
return Promise.reject(streamAsyncIteratorBrandCheckException('next'));
}
const reader = this._asyncIteratorReader;
if (this.preventCancel === false) {
if (reader._ownerReadableStream === undefined) {
return Promise.reject(new TypeError());
return Promise.reject(readerLockException('next'));
}
if (reader._readRequests.length > 0) {
return Promise.reject(new TypeError());
return Promise.reject(new TypeError(
'Tried to release a reader lock when that reader has pending read() calls un-settled'));
}
const result = ReadableStreamReaderGenericCancel(reader, value);
ReadableStreamReaderGenericRelease(reader);
return result.then(() => ReadableStreamCreateReadResult(value, true, true));
}
if (reader._ownerReadableStream === undefined) {
return Promise.reject(new TypeError());
return Promise.reject(readerLockException('next'));
}
if (reader._readRequests.length > 0) {
return Promise.reject(new TypeError());
return Promise.reject(new TypeError(
'Tried to release a reader lock when that reader has pending read() calls un-settled'));
}
ReadableStreamReaderGenericRelease(reader);
return Promise.resolve(ReadableStreamCreateReadResult(value, true, true));
Expand Down Expand Up @@ -2128,6 +2130,10 @@ function streamBrandCheckException(name) {
return new TypeError(`ReadableStream.prototype.${name} can only be used on a ReadableStream`);
}

function streamAsyncIteratorBrandCheckException(name) {
return new TypeError(`ReadableStreamAsyncIterator.${name} can only be used on a ReadableSteamAsyncIterator`);
}

// Helper functions for the readers.

function readerLockException(name) {
Expand Down

0 comments on commit f39c70a

Please sign in to comment.