-
Notifications
You must be signed in to change notification settings - Fork 179
Add async iterable<T>
type to WebIDL
#1397
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
Changes from 21 commits
14f1bdb
b7df167
0402e85
b6f7392
6363f6c
5533589
6559e06
3789832
6f284c1
dcbe738
bd86c51
f97033b
30fb12d
3469138
947fb78
118b446
ca5967b
11f9a9f
dc07972
dd56f97
9a79b42
6374863
70e9646
3c5164a
df3ec8d
5a0bb8e
df8383f
1b6489e
60c6648
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -34,6 +34,7 @@ urlPrefix: https://tc39.es/ecma262/; spec: ecmascript | |||||
type: argument | ||||||
text: NewTarget; url: sec-built-in-function-objects | ||||||
type: abstract-op | ||||||
text: CreateAsyncFromSyncIterator; url: sec-createasyncfromsynciterator | ||||||
text: Completion; url: sec-completion-record-specification-type | ||||||
text: IsInteger; url: sec-isinteger | ||||||
text: Type; url: sec-ecmascript-data-types-and-values | ||||||
|
@@ -68,6 +69,7 @@ urlPrefix: https://tc39.es/ecma262/; spec: ecmascript | |||||
text: internal slot | ||||||
text: own property; url: sec-own-property | ||||||
text: PromiseCapability; url: sec-promisecapability-records | ||||||
text: Iterator; url: sec-iterator-records | ||||||
text: element size; url: table-the-typedarray-constructors | ||||||
urlPrefix: https://tc39.es/proposal-resizablearraybuffer/; spec: RESIZABLE-BUFFERS-PROPOSAL | ||||||
type: abstract-op | ||||||
|
@@ -1671,6 +1673,7 @@ The type of the attribute, after resolving typedefs, must not be a | |||||
[=nullable type|nullable=] or non-nullable version of any of the following types: | ||||||
|
||||||
* a [=sequence type=] | ||||||
* an [=async iterable type=] | ||||||
* a [=dictionary type=] | ||||||
* a [=record type=] | ||||||
* a [=union type=] | ||||||
|
@@ -3360,6 +3363,7 @@ the following algorithm returns <i>true</i>. | |||||
<th><div><span>interface-like</span></div> | ||||||
<th><div><span>callback function</span></div> | ||||||
<th><div><span>dictionary-like</span></div> | ||||||
<th><div><span>async iterable</span></div> | ||||||
<th><div><span>sequence-like</span></div> | ||||||
</thead> | ||||||
<tr> | ||||||
|
@@ -3375,6 +3379,7 @@ the following algorithm returns <i>true</i>. | |||||
<td>● | ||||||
<td> | ||||||
<td>● | ||||||
<td>● | ||||||
<tr> | ||||||
<th>boolean | ||||||
<td class="belowdiagonal"> | ||||||
|
@@ -3388,6 +3393,7 @@ the following algorithm returns <i>true</i>. | |||||
<td>● | ||||||
<td>● | ||||||
<td>● | ||||||
<td>● | ||||||
<tr> | ||||||
<th>numeric types | ||||||
<td class="belowdiagonal"> | ||||||
|
@@ -3401,6 +3407,7 @@ the following algorithm returns <i>true</i>. | |||||
<td>● | ||||||
<td>● | ||||||
<td>● | ||||||
<td>● | ||||||
<tr> | ||||||
<th>bigint | ||||||
<td class="belowdiagonal"> | ||||||
|
@@ -3414,6 +3421,7 @@ the following algorithm returns <i>true</i>. | |||||
<td>● | ||||||
<td>● | ||||||
<td>● | ||||||
<td>● | ||||||
<tr> | ||||||
<th>string types | ||||||
<td class="belowdiagonal"> | ||||||
|
@@ -3427,6 +3435,7 @@ the following algorithm returns <i>true</i>. | |||||
<td>● | ||||||
<td>● | ||||||
<td>● | ||||||
<td>● | ||||||
<tr> | ||||||
<th>object | ||||||
<td class="belowdiagonal"> | ||||||
|
@@ -3440,6 +3449,7 @@ the following algorithm returns <i>true</i>. | |||||
<td> | ||||||
<td> | ||||||
<td> | ||||||
<td> | ||||||
<tr> | ||||||
<th>symbol | ||||||
<td class="belowdiagonal"> | ||||||
|
@@ -3453,6 +3463,7 @@ the following algorithm returns <i>true</i>. | |||||
<td>● | ||||||
<td>● | ||||||
<td>● | ||||||
<td>● | ||||||
<tr> | ||||||
<th>interface-like | ||||||
<td class="belowdiagonal"> | ||||||
|
@@ -3466,6 +3477,7 @@ the following algorithm returns <i>true</i>. | |||||
<td>● | ||||||
<td>● | ||||||
<td>● | ||||||
<td>● | ||||||
<tr> | ||||||
<th>callback function | ||||||
<td class="belowdiagonal"> | ||||||
|
@@ -3479,6 +3491,7 @@ the following algorithm returns <i>true</i>. | |||||
<td> | ||||||
<td>(c) | ||||||
<td>● | ||||||
<td>● | ||||||
<tr> | ||||||
<th>dictionary-like | ||||||
<td class="belowdiagonal"> | ||||||
|
@@ -3492,6 +3505,21 @@ the following algorithm returns <i>true</i>. | |||||
<td class="belowdiagonal"> | ||||||
<td> | ||||||
<td>● | ||||||
<td>● | ||||||
<tr> | ||||||
<th>async iterable | ||||||
<td class="belowdiagonal"> | ||||||
<td class="belowdiagonal"> | ||||||
<td class="belowdiagonal"> | ||||||
<td class="belowdiagonal"> | ||||||
<td class="belowdiagonal"> | ||||||
<td class="belowdiagonal"> | ||||||
<td class="belowdiagonal"> | ||||||
<td class="belowdiagonal"> | ||||||
<td class="belowdiagonal"> | ||||||
<td class="belowdiagonal"> | ||||||
<td> | ||||||
<td> | ||||||
<tr> | ||||||
<th>sequence-like | ||||||
<td class="belowdiagonal"> | ||||||
|
@@ -3504,6 +3532,7 @@ the following algorithm returns <i>true</i>. | |||||
<td class="belowdiagonal"> | ||||||
<td class="belowdiagonal"> | ||||||
<td class="belowdiagonal"> | ||||||
<td class="belowdiagonal"> | ||||||
<td> | ||||||
</table> | ||||||
|
||||||
|
@@ -4069,7 +4098,7 @@ The following extended attributes are applicable to [=iterable declarations=]: | |||||
</pre> | ||||||
|
||||||
|
||||||
<h4 id="idl-async-iterable">Asynchronously iterable declarations</h4> | ||||||
<h4 oldids="idl-async-iterable" id="idl-async-iterable-declaration">Asynchronously iterable declarations</h4> | ||||||
|
||||||
An [=interface=] can be declared to be asynchronously iterable by using an | ||||||
<dfn id="dfn-async-iterable-declaration" export>asynchronously iterable declaration</dfn> | ||||||
|
@@ -5676,6 +5705,7 @@ are known as <dfn id="dfn-object-type" export>object types</dfn>. | |||||
StringType Null | ||||||
identifier Null | ||||||
"sequence" "<" TypeWithExtendedAttributes ">" Null | ||||||
"async iterable" "<" TypeWithExtendedAttributes ">" Null | ||||||
"object" Null | ||||||
"symbol" Null | ||||||
BufferRelatedType Null | ||||||
|
@@ -6177,6 +6207,34 @@ sequence is used. | |||||
Any [=list=] can be implicitly treated as a <code>sequence<|T|></code>, as long as it contains | ||||||
only [=list/items=] that are of type |T|. | ||||||
|
||||||
<!-- Note: if we ever add synchronous iterable types, we should add a note here about why sequences and iterables are not the same. --> | ||||||
|
||||||
<h4 id="idl-async-iterable-type" lt="async iterable" dfn export>Async iterable types — async iterable<|T|></h4> | ||||||
|
||||||
The <dfn lt="async iterable type" export>async iterable type</dfn> is a parameterized | ||||||
type whose values are references to objects that can produce an asynchronously iterable, possibly infinite, | ||||||
sequence of values of type |T|. | ||||||
|
||||||
Unlike [=sequences=], which are fixed-length lists where all values are known in advance, the asynchronously | ||||||
iterable sequences created by async iterables are lazy. Their values may be produced asynchronously | ||||||
only during iteration, and thus the values or length might not be known at the time the async | ||||||
iterable is created. | ||||||
|
||||||
Async iterables are passed by reference in language bindings where they are represented by an object. | ||||||
This means that passing an async iterable to a [=platform object=] will result in a reference to the | ||||||
async iterable being kept by that object. Similarly, any async iterable returned from a platform | ||||||
object will be a reference to the same object and modifications made to it will be visible to the | ||||||
platform object. This is in contrast to sequences, which are always passed by value. | ||||||
|
||||||
Note: Async iterables cannot be constructed from IDL. If returned from an operation, or used as the | ||||||
type of a dictionary member, the async iterable will have originated from the host environment and | ||||||
have been turned into an IDL type via a language binding. Instead of returning an async iterable | ||||||
from an IDL operation, the operation might want to return an [=interface=] that has an | ||||||
[=asynchronously iterable declaration=]. | ||||||
|
||||||
Async iterables must not be used as the type of an [=attribute=] or [=constant=]. | ||||||
|
||||||
There is no way to represent an async iterable value in IDL. | ||||||
|
||||||
<h4 id="idl-record" lt="record" dfn export>Record types — record<|K|, |V|></h4> | ||||||
|
||||||
|
@@ -8115,6 +8173,162 @@ JavaScript Array values. | |||||
</div> | ||||||
|
||||||
|
||||||
<h4 id="js-async-iterable">Async iterable — async iterable<|T|></h4> | ||||||
lucacasonato marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
||||||
In the JavaScript binding, IDL [=async iterable type|async iterable=] values are represented by | ||||||
a [=struct=] with the following [=struct/items=]: | ||||||
|
||||||
* <dfn for="JS async iterable">object</dfn>, a JavaScript value | ||||||
* <dfn for="JS async iterable">method</dfn>, a JavaScript value | ||||||
* <dfn for="JS async iterable">type</dfn>, either "<code>sync</code>" or "<code>async</code>" | ||||||
|
||||||
|
||||||
<div id="js-to-async-iterable" algorithm="convert a JavaScript value to async iterable"> | ||||||
A JavaScript value |V| is [=converted to an IDL value|converted=] | ||||||
to an IDL <a lt="async iterable">async iterable<<var ignore>T</var>></a> value as follows: | ||||||
|
||||||
1. If <a abstract-op>Type</a>(|V|) is not Object, | ||||||
[=JavaScript/throw=] a <l spec=ecmascript>{{TypeError}}</l>. | ||||||
1. Let |method| be [=?=] <a abstract-op>GetMethod</a>(obj, {{%Symbol.asyncIterator%}}). | ||||||
1. If |method| is undefined: | ||||||
|
1. If |method| is undefined: | |
1. If |method| is <emu-val>undefined</emu-val>: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note you're still missing the instance two lines below.
Uh oh!
There was an error while loading. Please reload this page.