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

Assert that async iterator's reader is always active #1247

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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