Skip to content

Commit e0ae0bc

Browse files
Add ReadableStreamGenericReader interface mixin
1 parent 67a08f9 commit e0ae0bc

File tree

1 file changed

+79
-62
lines changed

1 file changed

+79
-62
lines changed

index.bs

Lines changed: 79 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ default-reader-asynciterator-prototype-internal-slots">Asynchronous iteration</h
973973
ignore>stream</var> and |iterator|, are:
974974

975975
1. Let |reader| be |iterator|'s [=ReadableStream async iterator/reader=].
976-
1. If |reader|.[=ReadableStreamDefaultReader/[[stream]]=] is undefined, return [=a promise rejected with=] a {{TypeError}}.
976+
1. If |reader|.[=ReadableStreamGenericReader/[[stream]]=] is undefined, return [=a promise rejected with=] a {{TypeError}}.
977977
1. Let |promise| be [=a new promise=].
978978
1. Let |readRequest| be a new [=read request=] with the following [=struct/items=]:
979979
: [=read request/chunk steps=], given |chunk|
@@ -996,7 +996,7 @@ default-reader-asynciterator-prototype-internal-slots">Asynchronous iteration</h
996996
ignore>stream</var>, |iterator|, and |arg|, are:
997997

998998
1. Let |reader| be |iterator|'s [=ReadableStream async iterator/reader=].
999-
1. If |reader|.[=ReadableStreamDefaultReader/[[stream]]=] is undefined, return [=a promise resolved with=] undefined.
999+
1. If |reader|.[=ReadableStreamGenericReader/[[stream]]=] is undefined, return [=a promise resolved with=] undefined.
10001000
1. Assert: |reader|.[=ReadableStreamDefaultReader/[[readRequests]]=] is [=list/is empty|empty=], as the async iterator machinery
10011001
guarantees that any previous calls to `next()` have settled before this is called.
10021002
1. If |iterator|'s [=ReadableStream async iterator/prevent cancel=] is false:
@@ -1007,6 +1007,62 @@ default-reader-asynciterator-prototype-internal-slots">Asynchronous iteration</h
10071007
1. Return [=a promise resolved with=] undefined.
10081008
</div>
10091009

1010+
<h3 id="generic-reader-mixin">The {{ReadableStreamGenericReader}} interface mixin</h3>
1011+
1012+
The {{ReadableStreamGenericReader}} interface mixin defines common internal slots, getters and
1013+
methods that are shared between {{ReadableStreamDefaultReader}} and {{ReadableStreamBYOBReader}}
1014+
objects.
1015+
1016+
<h4 id="generic-reader-mixin-definition">Interface definition</h4>
1017+
1018+
The Web IDL definition for the {{ReadableStreamGenericReader}} interface mixin is given as follows:
1019+
1020+
<xmp class="idl">
1021+
interface mixin ReadableStreamGenericReader {
1022+
readonly attribute Promise<void> closed;
1023+
1024+
Promise<void> cancel(optional any reason);
1025+
};
1026+
</xmp>
1027+
1028+
<h4 id="generic-reader-internal-slots">Internal slots</h4>
1029+
1030+
Instances of classes implementing the {{ReadableStreamGenericReader}} mixin are created with the
1031+
internal slots described in the following table:
1032+
1033+
<table dfn-for="ReadableStreamGenericReader">
1034+
<thead>
1035+
<tr>
1036+
<th>Internal Slot
1037+
<th>Description (<em>non-normative</em>)
1038+
<tbody>
1039+
<tr>
1040+
<td><dfn>\[[closedPromise]]</dfn>
1041+
<td class="non-normative">A promise returned by the reader's
1042+
{{ReadableStreamGenericReader/closed}} getter
1043+
<tr>
1044+
<td><dfn>\[[stream]]</dfn>
1045+
<td class="non-normative">A {{ReadableStream}} instance that owns this reader
1046+
</table>
1047+
1048+
<h4 id="generic-reader-prototype">Methods and properties</h4>
1049+
1050+
<div algorithm>
1051+
The <dfn id="generic-reader-closed" attribute for="ReadableStreamGenericReader">closed</dfn>
1052+
getter steps are:
1053+
1054+
1. Return [=this=].[=ReadableStreamGenericReader/[[closedPromise]]=].
1055+
</div>
1056+
1057+
<div algorithm>
1058+
The <dfn id="generic-reader-cancel" method for="ReadableStreamGenericReader">cancel(|reason|)</dfn>
1059+
method steps are:
1060+
1061+
1. If [=this=].[=ReadableStreamGenericReader/[[stream]]=] is undefined, return [=a promise rejected with=] a {{TypeError}}
1062+
exception.
1063+
1. Return ! [$ReadableStreamReaderGenericCancel$]([=this=], |reason|).
1064+
</div>
1065+
10101066
<h3 id="default-reader-class">The {{ReadableStreamDefaultReader}} class</h3>
10111067

10121068
The {{ReadableStreamDefaultReader}} class represents a [=default reader=] designed to be vended by a
@@ -1021,12 +1077,10 @@ The Web IDL definition for the {{ReadableStreamDefaultReader}} class is given as
10211077
interface ReadableStreamDefaultReader {
10221078
constructor(ReadableStream stream);
10231079

1024-
readonly attribute Promise<void> closed;
1025-
1026-
Promise<void> cancel(optional any reason);
10271080
Promise<ReadableStreamDefaultReadResult> read();
10281081
void releaseLock();
10291082
};
1083+
ReadableStreamDefaultReader includes ReadableStreamGenericReader;
10301084

10311085
dictionary ReadableStreamDefaultReadResult {
10321086
any value;
@@ -1036,28 +1090,19 @@ dictionary ReadableStreamDefaultReadResult {
10361090

10371091
<h4 id="default-reader-internal-slots">Internal slots</h4>
10381092

1039-
Instances of {{ReadableStreamDefaultReader}} are created with the internal slots described in the
1040-
following table:
1093+
Instances of {{ReadableStreamDefaultReader}} are created with the internal slots defined by
1094+
{{ReadableStreamGenericReader}}, and those described in the following table:
10411095

10421096
<table dfn-for="ReadableStreamDefaultReader">
10431097
<thead>
10441098
<tr>
10451099
<th>Internal Slot
10461100
<th>Description (<em>non-normative</em>)
10471101
<tbody>
1048-
<tr>
1049-
<td><dfn>\[[closedPromise]]</dfn>
1050-
<td class="non-normative">A promise returned by the reader's
1051-
{{ReadableStreamDefaultReader/closed}} getter.
1052-
This fulfills the [=ReadableStreamGenericReader/[[closedPromise]]=] contract.
10531102
<tr>
10541103
<td><dfn>\[[readRequests]]</dfn>
10551104
<td class="non-normative">A [=list=] of [=read requests=], used when a [=consumer=] requests
10561105
[=chunks=] sooner than they are available
1057-
<tr>
1058-
<td><dfn>\[[stream]]</dfn>
1059-
<td class="non-normative">A {{ReadableStream}} instance that owns this reader
1060-
This fulfills the [=ReadableStreamGenericReader/[[stream]]=] contract.
10611106
</table>
10621107

10631108
A <dfn export>read request</dfn> is a [=struct=] containing three algorithms to perform in reaction
@@ -1133,14 +1178,14 @@ to filling the [=readable stream=]'s [=internal queue=] or changing its state. I
11331178
The <dfn id="default-reader-closed" attribute for="ReadableStreamDefaultReader">closed</dfn>
11341179
getter steps are:
11351180

1136-
1. Return [=this=].[=ReadableStreamDefaultReader/[[closedPromise]]=].
1181+
1. Return [=this=].[=ReadableStreamGenericReader/[[closedPromise]]=].
11371182
</div>
11381183

11391184
<div algorithm>
11401185
The <dfn id="default-reader-cancel" method for="ReadableStreamDefaultReader">cancel(|reason|)</dfn>
11411186
method steps are:
11421187

1143-
1. If [=this=].[=ReadableStreamDefaultReader/[[stream]]=] is undefined, return [=a promise rejected with=] a {{TypeError}}
1188+
1. If [=this=].[=ReadableStreamGenericReader/[[stream]]=] is undefined, return [=a promise rejected with=] a {{TypeError}}
11441189
exception.
11451190
1. Return ! [$ReadableStreamReaderGenericCancel$]([=this=], |reason|).
11461191
</div>
@@ -1149,7 +1194,7 @@ to filling the [=readable stream=]'s [=internal queue=] or changing its state. I
11491194
The <dfn id="default-reader-read" method for="ReadableStreamDefaultReader">read()</dfn>
11501195
method steps are:
11511196

1152-
1. If [=this=].[=ReadableStreamDefaultReader/[[stream]]=] is undefined, return [=a promise rejected with=] a {{TypeError}}
1197+
1. If [=this=].[=ReadableStreamGenericReader/[[stream]]=] is undefined, return [=a promise rejected with=] a {{TypeError}}
11531198
exception.
11541199
1. Let |promise| be [=a new promise=].
11551200
1. Let |readRequest| be a new [=read request=] with the following [=struct/items=]:
@@ -1172,7 +1217,7 @@ to filling the [=readable stream=]'s [=internal queue=] or changing its state. I
11721217
The <dfn id="default-reader-release-lock" method
11731218
for="ReadableStreamDefaultReader">releaseLock()</dfn> method steps are:
11741219

1175-
1. If [=this=].[=ReadableStreamDefaultReader/[[stream]]=] is undefined, return.
1220+
1. If [=this=].[=ReadableStreamGenericReader/[[stream]]=] is undefined, return.
11761221
1. If [=this=].[=ReadableStreamDefaultReader/[[readRequests]]=] is not [=list/is empty|empty=], throw a {{TypeError}} exception.
11771222
1. Perform ! [$ReadableStreamReaderGenericRelease$]([=this=]).
11781223
</div>
@@ -1191,12 +1236,10 @@ The Web IDL definition for the {{ReadableStreamBYOBReader}} class is given as fo
11911236
interface ReadableStreamBYOBReader {
11921237
constructor(ReadableStream stream);
11931238

1194-
readonly attribute Promise<void> closed;
1195-
1196-
Promise<void> cancel(optional any reason);
11971239
Promise<ReadableStreamBYOBReadResult> read(ArrayBufferView view);
11981240
void releaseLock();
11991241
};
1242+
ReadableStreamBYOBReader includes ReadableStreamGenericReader;
12001243

12011244
dictionary ReadableStreamBYOBReadResult {
12021245
ArrayBufferView value;
@@ -1206,28 +1249,19 @@ dictionary ReadableStreamBYOBReadResult {
12061249

12071250
<h4 id="byob-reader-internal-slots">Internal slots</h4>
12081251

1209-
Instances of {{ReadableStreamBYOBReader}} are created with the internal slots described in the
1210-
following table:
1252+
Instances of {{ReadableStreamBYOBReader}} are created with the internal slots defined by
1253+
{{ReadableStreamGenericReader}}, and those described in the following table:
12111254

12121255
<table dfn-for="ReadableStreamBYOBReader">
12131256
<thead>
12141257
<tr>
12151258
<th>Internal Slot
12161259
<th>Description (<em>non-normative</em>)
12171260
<tbody>
1218-
<tr>
1219-
<td><dfn>\[[closedPromise]]</dfn>
1220-
<td class="non-normative">A promise returned by the reader's
1221-
{{ReadableStreamBYOBReader/closed}} getter.
1222-
This fulfills the [=ReadableStreamGenericReader/[[closedPromise]]=] contract.
12231261
<tr>
12241262
<td><dfn>\[[readIntoRequests]]</dfn>
12251263
<td class="non-normative">A [=list=] of [=read-into requests=], used when a [=consumer=] requests
12261264
[=chunks=] sooner than they are available
1227-
<tr>
1228-
<td><dfn>\[[stream]]</dfn>
1229-
<td class="non-normative">A {{ReadableStream}} instance that owns this reader.
1230-
This fulfills the [=ReadableStreamGenericReader/[[stream]]=] contract.
12311265
</table>
12321266

12331267
A <dfn export>read-into request</dfn> is a [=struct=] containing three algorithms to perform in
@@ -1314,14 +1348,14 @@ value: newViewOnSameMemory, done: true }</code> for closed streams, instead of t
13141348
The <dfn id="byob-reader-closed" attribute for="ReadableStreamBYOBReader">closed</dfn>
13151349
getter steps are:
13161350

1317-
1. Return [=this=].[=ReadableStreamBYOBReader/[[closedPromise]]=].
1351+
1. Return [=this=].[=ReadableStreamGenericReader/[[closedPromise]]=].
13181352
</div>
13191353

13201354
<div algorithm>
13211355
The <dfn id="byob-reader-cancel" method for="ReadableStreamBYOBReader">cancel(|reason|)</dfn>
13221356
method steps are:
13231357

1324-
1. If [=this=].[=ReadableStreamBYOBReader/[[stream]]=] is undefined, return [=a promise rejected with=] a {{TypeError}}
1358+
1. If [=this=].[=ReadableStreamGenericReader/[[stream]]=] is undefined, return [=a promise rejected with=] a {{TypeError}}
13251359
exception.
13261360
1. Return ! [$ReadableStreamReaderGenericCancel$]([=this=], |reason|).
13271361
</div>
@@ -1333,7 +1367,7 @@ value: newViewOnSameMemory, done: true }</code> for closed streams, instead of t
13331367
1. If |view|.\[[ByteLength]] is 0, return [=a promise rejected with=] a {{TypeError}} exception.
13341368
1. If |view|.\[[ViewedArrayBuffer]].\[[ArrayBufferByteLength]] is 0, return [=a promise rejected
13351369
with=] a {{TypeError}} exception.
1336-
1. If [=this=].[=ReadableStreamBYOBReader/[[stream]]=] is undefined, return [=a promise rejected with=] a {{TypeError}}
1370+
1. If [=this=].[=ReadableStreamGenericReader/[[stream]]=] is undefined, return [=a promise rejected with=] a {{TypeError}}
13371371
exception.
13381372
1. Let |promise| be [=a new promise=].
13391373
1. Let |readIntoRequest| be a new [=read-into request=] with the following [=struct/items=]:
@@ -1356,7 +1390,7 @@ value: newViewOnSameMemory, done: true }</code> for closed streams, instead of t
13561390
The <dfn id="byob-reader-release-lock" method
13571391
for="ReadableStreamBYOBReader">releaseLock()</dfn> method steps are:
13581392

1359-
1. If [=this=].[=ReadableStreamBYOBReader/[[stream]]=] is undefined, return.
1393+
1. If [=this=].[=ReadableStreamGenericReader/[[stream]]=] is undefined, return.
13601394
1. If [=this=].[=ReadableStreamBYOBReader/[[readIntoRequests]]=] is not [=list/is empty|empty=], throw a {{TypeError}}
13611395
exception.
13621396
1. Perform ! [$ReadableStreamReaderGenericRelease$]([=this=]).
@@ -1523,7 +1557,7 @@ counterparts for BYOB controllers, as discussed in [[#rs-abstract-ops-used-by-co
15231557
id="rs-default-controller-private-pull">\[[PullSteps]](|readRequest|)</dfn> implements the
15241558
[$ReadableStreamController/[[PullSteps]]$] contract. It performs the following steps:
15251559

1526-
1. Let |stream| be [=this=].[=ReadableStreamBYOBReader/[[stream]]=].
1560+
1. Let |stream| be [=this=].[=ReadableStreamGenericReader/[[stream]]=].
15271561
1. If [=this=].\[[queue]] is not [=list/is empty|empty=],
15281562
1. Let |chunk| be ! [$DequeueValue$]([=this=]).
15291563
1. If [=this=].\[[closeRequested]] is true and [=this=].\[[queue]] [=list/is empty=],
@@ -1736,7 +1770,7 @@ has the following [=struct/items=]:
17361770
steps are:
17371771

17381772
1. If [=this=].\[[closeRequested]] is true, throw a {{TypeError}} exception.
1739-
1. If [=this=].[=ReadableStreamBYOBReader/[[stream]]=].[=ReadableStream/[[state]]=] is not "`readable`", throw a {{TypeError}} exception.
1773+
1. If [=this=].[=ReadableStreamGenericReader/[[stream]]=].[=ReadableStream/[[state]]=] is not "`readable`", throw a {{TypeError}} exception.
17401774
1. Perform ? [$ReadableByteStreamControllerClose$]([=this=]).
17411775
</div>
17421776

@@ -1748,7 +1782,7 @@ for="ReadableByteStreamController">enqueue(|chunk|)</dfn> method steps are:
17481782
1. If |chunk|.\[[ViewedArrayBuffer]].\[[ArrayBufferByteLength]] is 0, throw a {{TypeError}}
17491783
exception.
17501784
1. If [=this=].\[[closeRequested]] is true, throw a {{TypeError}} exception.
1751-
1. If [=this=].[=ReadableStreamBYOBReader/[[stream]]=].[=ReadableStream/[[state]]=] is not "`readable`", throw a {{TypeError}} exception.
1785+
1. If [=this=].[=ReadableStreamGenericReader/[[stream]]=].[=ReadableStream/[[state]]=] is not "`readable`", throw a {{TypeError}} exception.
17521786
1. Return ! [$ReadableByteStreamControllerEnqueue$]([=this=], |chunk|).
17531787
</div>
17541788

@@ -2189,7 +2223,7 @@ create them does not matter.
21892223
[$ReadableStreamDefaultControllerEnqueue$](|branch2|.[=ReadableStream/[[controller]]=], |value2|).
21902224

21912225
<p class="note">The microtask delay here is necessary because it takes at least a microtask to
2192-
detect errors, when we use |reader|.[=ReadableStreamDefaultReader/[[closedPromise]]=] below. We want errors in |stream| to
2226+
detect errors, when we use |reader|.[=ReadableStreamGenericReader/[[closedPromise]]=] below. We want errors in |stream| to
21932227
error both branches immediately, so we cannot let successful synchronously-available reads
21942228
happen ahead of asynchronously-available errors.
21952229

@@ -2228,7 +2262,7 @@ create them does not matter.
22282262
|cancel1Algorithm|).
22292263
1. Set |branch2| to ! [$CreateReadableStream$](|startAlgorithm|, |pullAlgorithm|,
22302264
|cancel2Algorithm|).
2231-
1. [=Upon rejection=] of |reader|.[=ReadableStreamDefaultReader/[[closedPromise]]=] with reason |r|,
2265+
1. [=Upon rejection=] of |reader|.[=ReadableStreamGenericReader/[[closedPromise]]=] with reason |r|,
22322266
1. Perform ! [$ReadableStreamDefaultControllerError$](|branch1|.[=ReadableStream/[[controller]]=], |r|).
22332267
1. Perform ! [$ReadableStreamDefaultControllerError$](|branch2|.[=ReadableStream/[[controller]]=], |r|).
22342268
1. [=Resolve=] |cancelPromise| with undefined.
@@ -2413,23 +2447,6 @@ the {{ReadableStream}}'s public API.
24132447

24142448
<h4 id="rs-reader-abstract-ops">Readers</h4>
24152449

2416-
Instances of {{ReadableStreamDefaultReader}} and {{ReadableStreamBYOBReader}} are created with the
2417-
internal slots described in the following table:
2418-
2419-
<table dfn-for="ReadableStreamGenericReader">
2420-
<thead>
2421-
<tr>
2422-
<th>Internal Slot
2423-
<th>Description (<em>non-normative</em>)
2424-
<tbody>
2425-
<tr>
2426-
<td><dfn>\[[closedPromise]]</dfn>
2427-
<td class="non-normative">A promise returned by the reader's <code>closed</code> getter
2428-
<tr>
2429-
<td><dfn>\[[stream]]</dfn>
2430-
<td class="non-normative">A {{ReadableStream}} instance that owns this reader
2431-
</table>
2432-
24332450
The following abstract operations support the implementation and manipulation of
24342451
{{ReadableStreamDefaultReader}} and {{ReadableStreamBYOBReader}} instances.
24352452

@@ -2481,7 +2498,7 @@ The following abstract operations support the implementation and manipulation of
24812498
id="readable-stream-byob-reader-read">ReadableStreamBYOBReaderRead(|reader|, |view|,
24822499
|readIntoRequest|)</dfn> performs the following steps:
24832500

2484-
1. Let |stream| be |reader|.[=ReadableStreamBYOBReader/[[stream]]=].
2501+
1. Let |stream| be |reader|.[=ReadableStreamGenericReader/[[stream]]=].
24852502
1. Assert: |stream| is not undefined.
24862503
1. Set |stream|.[=ReadableStream/[[disturbed]]=] to true.
24872504
1. If |stream|.[=ReadableStream/[[state]]=] is "`errored`", perform |readIntoRequest|'s [=read-into request/error
@@ -2495,7 +2512,7 @@ The following abstract operations support the implementation and manipulation of
24952512
id="readable-stream-default-reader-read">ReadableStreamDefaultReaderRead(|reader|,
24962513
|readRequest|)</dfn> performs the following steps:
24972514

2498-
1. Let |stream| be |reader|.[=ReadableStreamDefaultReader/[[stream]]=].
2515+
1. Let |stream| be |reader|.[=ReadableStreamGenericReader/[[stream]]=].
24992516
1. Assert: |stream| is not undefined.
25002517
1. Set |stream|.[=ReadableStream/[[disturbed]]=] to true.
25012518
1. If |stream|.[=ReadableStream/[[state]]=] is "`closed`", perform |readRequest|'s [=read request/close steps=].

0 commit comments

Comments
 (0)