Skip to content

Commit

Permalink
Editorial: assert that async iterator's reader is always active
Browse files Browse the repository at this point in the history
Fixes #1246.
  • Loading branch information
MattiasBuelens authored Oct 19, 2022
1 parent 0fac034 commit 839a5a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
6 changes: 2 additions & 4 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,7 @@ default-reader-asynciterator-prototype-internal-slots">Asynchronous iteration</h
ignore>stream</var> and |iterator|, are:

1. Let |reader| be |iterator|'s [=ReadableStream async iterator/reader=].
1. If |reader|.[=ReadableStreamGenericReader/[[stream]]=] is undefined, return [=a promise rejected
with=] a {{TypeError}}.
1. Assert: |reader|.[=ReadableStreamGenericReader/[[stream]]=] is not undefined.
1. Let |promise| be [=a new promise=].
1. Let |readRequest| be a new [=read request=] with the following [=struct/items=]:
: [=read request/chunk steps=], given |chunk|
Expand All @@ -1036,8 +1035,7 @@ default-reader-asynciterator-prototype-internal-slots">Asynchronous iteration</h
ignore>stream</var>, |iterator|, and |arg|, are:

1. Let |reader| be |iterator|'s [=ReadableStream async iterator/reader=].
1. If |reader|.[=ReadableStreamGenericReader/[[stream]]=] is undefined, return [=a promise resolved
with=] undefined.
1. Assert: |reader|.[=ReadableStreamGenericReader/[[stream]]=] is not undefined.
1. Assert: |reader|.[=ReadableStreamDefaultReader/[[readRequests]]=] is [=list/is empty|empty=],
as the async iterator machinery guarantees that any previous calls to `next()` have settled
before this is called.
Expand Down
11 changes: 2 additions & 9 deletions reference-implementation/lib/ReadableStream-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ exports.implementation = class ReadableStreamImpl {

[idlUtils.asyncIteratorNext](iterator) {
const reader = iterator._reader;
if (reader._stream === undefined) {
return promiseRejectedWith(
new TypeError('Cannot get the next iteration result once the reader has been released')
);
}
assert(reader._stream !== undefined);

const promise = newPromise();
const readRequest = {
Expand All @@ -143,10 +139,7 @@ exports.implementation = class ReadableStreamImpl {

[idlUtils.asyncIteratorReturn](iterator, arg) {
const reader = iterator._reader;
if (reader._stream === undefined) {
return promiseResolvedWith(undefined);
}

assert(reader._stream !== undefined);
assert(reader._readRequests.length === 0);

if (iterator._preventCancel === false) {
Expand Down

0 comments on commit 839a5a6

Please sign in to comment.