From 14f1bdb8d585a48162ccccee8e9352790168c51a Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 25 Mar 2024 13:06:21 +0100 Subject: [PATCH 01/20] Add `async iterable` type to WebIDL This commit lifts the async iterator processing logic from the `ReadableStreamFromIterable` operation in the Streams spec, to a new WebIDL type `async iterable`. This will clean up the streams spec, and enable a change in the Fetch spec to directly allow taking async iterable as request/response bodies, without having to pass them to `ReadableStream.from` first. --- index.bs | 193 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 187 insertions(+), 6 deletions(-) diff --git a/index.bs b/index.bs index d7ea1fa8..e8ef8bb4 100644 --- a/index.bs +++ b/index.bs @@ -68,6 +68,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 @@ -3350,6 +3351,7 @@ the following algorithm returns true.
interface-like
callback function
dictionary-like
+
async iterable
sequence-like
@@ -3365,6 +3367,7 @@ the following algorithm returns true. ● ● + ● boolean @@ -3378,6 +3381,7 @@ the following algorithm returns true. ● ● ● + ● numeric types @@ -3391,6 +3395,7 @@ the following algorithm returns true. ● ● ● + ● bigint @@ -3404,6 +3409,7 @@ the following algorithm returns true. ● ● ● + ● string types @@ -3417,6 +3423,7 @@ the following algorithm returns true. ● ● ● + ● object @@ -3430,6 +3437,7 @@ the following algorithm returns true. + symbol @@ -3443,6 +3451,7 @@ the following algorithm returns true. ● ● ● + ● interface-like @@ -3456,6 +3465,7 @@ the following algorithm returns true. ● ● ● + ● callback function @@ -3469,6 +3479,7 @@ the following algorithm returns true. (c) ● + ● dictionary-like @@ -3482,6 +3493,21 @@ the following algorithm returns true. ● + ● + + async iterable + + + + + + + + + + + + sequence-like @@ -3494,6 +3520,7 @@ the following algorithm returns true. + @@ -4059,7 +4086,7 @@ The following extended attributes are applicable to [=iterable declarations=]: -

Asynchronously iterable declarations

+

Asynchronously iterable declarations

An [=interface=] can be declared to be asynchronously iterable by using an asynchronously iterable declaration @@ -5665,6 +5692,7 @@ are known as object types. StringType Null identifier Null "sequence" "<" TypeWithExtendedAttributes ">" Null + "async iterable" "<" TypeWithExtendedAttributes ">" Null "object" Null "symbol" Null BufferRelatedType Null @@ -6166,6 +6194,26 @@ sequence is used. Any [=list=] can be implicitly treated as a sequence<|T|>, as long as it contains only [=list/items=] that are of type |T|. + + +

Async iterable types — async iterable<|T|>

+ +The async iterable<|T|> type is a parameterized +type whose values are references to objects that asynchronously yield zero or more values of type +|T|. + +Async iterables, unlike sequences, do not have a fixed length and can be infinite. Values are +asynchronously produced as the async iterable is iterated over. + +Async iterable 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. + +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.

Record types — record<|K|, |V|>

@@ -8064,6 +8112,122 @@ JavaScript Array values. +

Async iterable — async iterable<|T|>

+ +IDL async iterable<|T|> values are represented by JavaScript +[=Iterator=] records. + +
+ A JavaScript value |V| is [=converted to an IDL value|converted=] + to an IDL async iterable<T> value as follows: + + 1. If Type(|V|) is not Object, + [=JavaScript/throw=] a {{TypeError}}. + 1. Let |iteratorRecord| be [=?=] GetIterator(|V|, async). + 1. Return |iteratorRecord|. +
+ +An IDL async iterable<|T|> value can not be +[=converted to a JavaScript value=]. + +Note: Instead of returning an async iterable from an IDL operation, the operation should return an +[=interface=] that has an [=asynchronously iterable declaration=]. + +
Iterating async iterables
+ +
+ + To get the next value of an + async iterable<T> |iteratorRecord|, + perform the following steps: + + 1. Let |nextResult| be the result of calling IteratorNext(|iteratorRecord|). + 1. If |nextResult| is an abrupt completion, return [=a promise rejected with=] + |nextResult|.\[[Value]]. + 1. Let |nextPromise| be [=a promise resolved with=] |nextResult|.\[[Value]]. + 1. Return the result of [=reacting=] to |nextPromise| with with the following fulfillment + steps, given |iterResult|: + 1. If Type(|iterResult|) is not Object, [=JavaScript/throw=] a + {{TypeError}}. + 1. Let |done| be [=?=] IteratorComplete(|iterResult|). + 1. If |done| is true: + 1. Return [=end of iteration=]. + 1. Otherwise: + 1. Let |V| be [=?=] IteratorValue(|iterResult|). + 1. Let |value| be the result of [=converted to an IDL value|converting=] |V| to an IDL + value of type |T|. + 1. Return |value|. + +
+ +
+ + To finish iterating an + async iterable<T> |iteratorRecord|, + perform the following steps: + + 1. Let |iterator| be |iteratorRecord|.\[[Iterator]]. + 1. Let |returnMethod| be GetMethod(|iterator|, "return"). + 1. If |returnMethod| is an abrupt completion, return [=a promise rejected with=] + |returnMethod|.\[[Value]]. + 1. If |returnMethod| is undefined, return [=a promise resolved with=] + undefined. + 1. Let |returnResult| be Call(|returnMethod|.\[[Value]], |iterator|). + 1. If |returnResult| is an abrupt completion, return [=a promise rejected with=] + |returnResult|.\[[Value]]. + 1. Let |returnPromise| be [=a promise resolved with=] |returnResult|.\[[Value]]. + 1. Return the result of [=reacting=] to |returnPromise| with the following fulfillment steps, + given |returnPromiseResult|: + 1. If Type(|returnPromiseResult|) is not Object, [=JavaScript/throw=] a + {{TypeError}}. + 1. Return undefined. + +
+ +
+ + concatN is an [=operation=] that returns a promise that will be fulfilled with the + concatenation of all the strings yielded by the async iterable passed to it. It stops + concatenating and finishes the iterator once the async iterable has yielded N strings. + +
+        interface I {
+          Promise<DOMString> concat(async iterable<DOMString> strings, unsigned long maxN);
+        };
+    
+ +
+ + The concatN(|iterable|, |maxN|) method steps are: + + 1. Let |promise| be [=a new promise=]. + 1. Let |result| be the empty string. + 1. Let |n| be 0. + 1. Let |step| be a sequence of steps that will be used to process the async iterable: + 1. Let |next| be the result of getting the next value of |iterable|. + 1. [=React=] to |next|: + - If |next| was fulfilled with value |v|: + 1. If |v| is [=end of iteration=], [=resolve=] |promise| with |result|. + 1. Set |result| to the result of concatenating |result| and |v|. + 1. Set |n| to |n| + 1. + 1. If |n| is |maxN|, then: + 1. Let |finish| be the result of finishing iterating |iterable|. + 1. [=React=] to |finish|: + - If |finish| was fulfilled, [=resolve=] |promise| with |result|. + - If |finish| was rejected with reason |r|, [=reject=] |promise| with |r|. + 1. Otherwise: + 1. Call |step|. + - If |next| was rejected with reason |r|, [=reject=] |promise| with |r|. + 1. Call step. + 1. Return |promise|. + +
+
+ + + + +

Records — record<|K|, |V|>

IDL [=record=]<|K|, |V|> values are represented by @@ -11174,6 +11338,23 @@ Note: The HTML Standard defines how a security check is performed. [[!HTML]] 1. Otherwise: if Type(|V|) is Object and there is an entry in |S| that has one of the following types at position |i| of its type list, + * a [=async iterable type=] + * a [=nullable type|nullable=] version of any of the above types + * an [=annotated type=] whose [=annotated types/inner type=] is one of the above types + * a [=union type=], [=nullable type|nullable=] union type, or [=annotated type|annotated=] union type + that has one of the above types in its [=flattened member types=] + + and after performing the following steps, + + 1. Let |method| be [=?=] GetMethod(|V|, {{@@asyncIterator}}). + + |method| is not undefined, then remove from |S| all + other entries. + + 1. Otherwise: if Type(|V|) is Object and + there is an entry in |S| that has one of the + following types at position |i| of its type list, + * a [=async iterable type=] * a [=sequence type=] * a [=frozen array type=] * a [=nullable type|nullable=] version of any of the above types @@ -11342,11 +11523,11 @@ Note: The HTML Standard defines how a security check is performed. [[!HTML]] Generally, the inspection of the value at the distinguishing argument index does not have any side effects, and the only side effects in the overload resolution algorithm are the result of converting the JavaScript values to IDL values. - (An exception exists when one of the overloads has a [=sequence type=] or [=frozen array type=] - at the distinguishing argument index. - In this case, we attempt to get the {{@@iterator}} property to determine the appropriate - overload, and perform the conversion of the distinguishing argument separately before continuing - with the next step.) + (An exception exists when one of the overloads has a [=async iterable type=], [=sequence type=] + or [=frozen array type=] at the distinguishing argument index. + In this case, we attempt to get the {{@@asyncIterator}} / {{@@iterator}} property to determine + the appropriate overload, and perform the conversion of the distinguishing argument separately + before continuing with the next step.) At this point, we have determined which overload to use. We now convert the remaining arguments, from the distinguishing argument onwards, From b7df1675f2e242a01436f067c0ce98cb861f3061 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 26 Mar 2024 14:01:55 +0100 Subject: [PATCH 02/20] Reason argument for close async iterable --- index.bs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/index.bs b/index.bs index e8ef8bb4..083942ba 100644 --- a/index.bs +++ b/index.bs @@ -8162,9 +8162,9 @@ Note: Instead of returning an async iterable from an IDL operation, the operatio
- To finish iterating an + To close an async iterable<T> |iteratorRecord|, - perform the following steps: + with a reason |reason|, perform the following steps: 1. Let |iterator| be |iteratorRecord|.\[[Iterator]]. 1. Let |returnMethod| be GetMethod(|iterator|, "return"). @@ -8172,7 +8172,7 @@ Note: Instead of returning an async iterable from an IDL operation, the operatio |returnMethod|.\[[Value]]. 1. If |returnMethod| is undefined, return [=a promise resolved with=] undefined. - 1. Let |returnResult| be Call(|returnMethod|.\[[Value]], |iterator|). + 1. Let |returnResult| be Call(|returnMethod|.\[[Value]], |iterator|, « |reason| »). 1. If |returnResult| is an abrupt completion, return [=a promise rejected with=] |returnResult|.\[[Value]]. 1. Let |returnPromise| be [=a promise resolved with=] |returnResult|.\[[Value]]. @@ -8188,7 +8188,7 @@ Note: Instead of returning an async iterable from an IDL operation, the operatio concatN is an [=operation=] that returns a promise that will be fulfilled with the concatenation of all the strings yielded by the async iterable passed to it. It stops - concatenating and finishes the iterator once the async iterable has yielded N strings. + concatenating and closes the iterator once the async iterable has yielded N strings.
         interface I {
@@ -8211,7 +8211,8 @@ Note: Instead of returning an async iterable from an IDL operation, the operatio
                 1.  Set |result| to the result of concatenating |result| and |v|.
                 1.  Set |n| to |n| + 1.
                 1.  If |n| is |maxN|, then:
-                    1.  Let |finish| be the result of finishing iterating |iterable|.
+                    1.  Let |finish| be the result of closing
+                        |iterable| with reason undefined.
                     1.  [=React=] to |finish|:
                         -   If |finish| was fulfilled, [=resolve=] |promise| with |result|.
                         -   If |finish| was rejected with reason |r|, [=reject=] |promise| with |r|.

From 0402e8526701ce6904a7a7d87ee107dc584e8ece Mon Sep 17 00:00:00 2001
From: Luca Casonato 
Date: Tue, 26 Mar 2024 14:04:21 +0100
Subject: [PATCH 03/20] fix typo

---
 index.bs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/index.bs b/index.bs
index 083942ba..47bff6e1 100644
--- a/index.bs
+++ b/index.bs
@@ -8145,7 +8145,7 @@ Note: Instead of returning an async iterable from an IDL operation, the operatio
     1.  If |nextResult| is an abrupt completion, return [=a promise rejected with=]
         |nextResult|.\[[Value]].
     1.  Let |nextPromise| be [=a promise resolved with=] |nextResult|.\[[Value]].
-    1.  Return the result of [=reacting=] to |nextPromise| with with the following fulfillment
+    1.  Return the result of [=reacting=] to |nextPromise| with the following fulfillment
         steps, given |iterResult|:
         1.  If Type(|iterResult|) is not Object, [=JavaScript/throw=] a
             {{TypeError}}.

From b6f73926005c0d3723b9db855b02b7c34138d1ce Mon Sep 17 00:00:00 2001
From: Luca Casonato 
Date: Thu, 28 Mar 2024 12:20:25 +0100
Subject: [PATCH 04/20] clarify the details of allowed positions for async
 iterables

---
 index.bs | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/index.bs b/index.bs
index 47bff6e1..22e3f05a 100644
--- a/index.bs
+++ b/index.bs
@@ -1662,6 +1662,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=]
@@ -6211,6 +6212,12 @@ async iterable being kept by that object. Similarly, any async iterable returned
 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 can not 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 may 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.
@@ -8114,8 +8121,8 @@ JavaScript Array values.
 
 

Async iterable — async iterable<|T|>

-IDL async iterable<|T|> values are represented by JavaScript -[=Iterator=] records. +IDL async iterable<|T|> values are represented by a JavaScript +object and a JavaScript [=Iterator=] record.
A JavaScript value |V| is [=converted to an IDL value|converted=] @@ -8127,11 +8134,12 @@ IDL async iterable<|T|> values are represe 1. Return |iteratorRecord|.
-An IDL async iterable<|T|> value can not be -[=converted to a JavaScript value=]. +
+ An IDL async iterable<|T|> value is + [=converted to a JavaScript value|converted=] to a JavaScript object as follows: -Note: Instead of returning an async iterable from an IDL operation, the operation should return an -[=interface=] that has an [=asynchronously iterable declaration=]. + 1. Return the JavaScript object that represents the same async iterable as the IDL value. +
Iterating async iterables
From 6363f6cc3d9aee3ab28260341d35c9292ac277c6 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 7 May 2024 14:08:42 +0200 Subject: [PATCH 05/20] fix ci --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 22e3f05a..ab8f37d0 100644 --- a/index.bs +++ b/index.bs @@ -8135,7 +8135,7 @@ object and a JavaScript [=Iterator=] record.
- An IDL async iterable<|T|> value is + An IDL async iterable<|T> value is [=converted to a JavaScript value|converted=] to a JavaScript object as follows: 1. Return the JavaScript object that represents the same async iterable as the IDL value. From 5533589f036f80ab6dbcff63ba1c5bad8dba03d2 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Thu, 18 Jul 2024 12:04:48 +0200 Subject: [PATCH 06/20] iterable -> iterable + iterator --- index.bs | 98 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 25 deletions(-) diff --git a/index.bs b/index.bs index ab8f37d0..1a01117f 100644 --- a/index.bs +++ b/index.bs @@ -6200,13 +6200,9 @@ only [=list/items=] that are of type |T|.

Async iterable types — async iterable<|T|>

The async iterable<|T|> type is a parameterized -type whose values are references to objects that asynchronously yield zero or more values of type -|T|. +type whose values are references to objects that can produce an [=async iterator=]. -Async iterables, unlike sequences, do not have a fixed length and can be infinite. Values are -asynchronously produced as the async iterable is iterated over. - -Async iterable are passed by reference in language bindings where they are represented by an object. +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 @@ -6222,6 +6218,20 @@ 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. +
Async iterator objects
+ +An async iterator<|T|> value is a reference to an object +that can produce a sequence of values asynchronously. The async iterator value is is a parameterized +by a type |T|, which defines the types of values produced by this async iterator. + +Async iterators, unlike sequences, do not have a fixed length and can be infinite. Values are +asynchronously produced as the async iterator is iterated over. + +Async iterators are values, not types, and thus cannot be used as a type in IDL. They can only be +created from [=async iterables=]. Thus, async iterators can not be used as the type of an IDL +operation parameter, an IDL interface attribute, or an IDL dictionary member. Instead an +[=async iterable=] should be used. +

Record types — record<|K|, |V|>

A record type is a parameterized type whose values are [=ordered maps=] with @@ -8122,7 +8132,8 @@ JavaScript Array values.

Async iterable — async iterable<|T|>

IDL async iterable<|T|> values are represented by a JavaScript -object and a JavaScript [=Iterator=] record. +object, a JavaScript method, and a flag indicating whether the method is expected to produce a +sync or async iterator.
A JavaScript value |V| is [=converted to an IDL value|converted=] @@ -8130,25 +8141,60 @@ object and a JavaScript [=Iterator=] record. 1. If Type(|V|) is not Object, [=JavaScript/throw=] a {{TypeError}}. - 1. Let |iteratorRecord| be [=?=] GetIterator(|V|, async). - 1. Return |iteratorRecord|. + 1. Let |method| be [=?=] GetMethod(obj, %Symbol.asyncIterator%). + 1. If |method| is undefined: + 1. Set |syncMethod| to [=?=] GetMethod(obj, %Symbol.iterator%). + 1. If |syncMethod| is undefined, [=JavaScript/throw=] a {{TypeError}}. + 1 Return the IDL async iterable value that represents a reference to the JavaScript object + |V|, the JavaScript method |syncMethod|, and the flag sync. + 1. Return the IDL async iterable value that represents a reference to the JavaScript object + |V|, the JavaScript method |method|, and the flag async.
- An IDL async iterable<|T> value is + An IDL async iterable<T> value is [=converted to a JavaScript value|converted=] to a JavaScript object as follows: 1. Return the JavaScript object that represents the same async iterable as the IDL value.
-
Iterating async iterables
+
Async iterators
+ +IDL async-iterator values are represented by JavaScript [=Iterator=] +records. + +Async iterators can only be created from an [=async iterable=] object. + +
Iterating async iterator
+ +[=Async iterables=] are not directly iterated over. They are first opened, to create a new +[=async iterator=], and then the [=async iterator=] is iterated over. + +
+ + To get the next value of an + async iterable<T> |iterable|, + perform the following steps: + + 1. Let |object| be the |iterable|'s JavaScript object. + 1. Let |method| be the |iterable|'s JavaScript method. + 1. Let |iterator| be [=?=] GetIteratorFromMethod(|object|, |method|). + 1. If |iterable| has a flag that shows that it is expected to produce a + sync iterator, then: + 1. Set |iterator| to CreateAsyncFromSyncIteator(|iterator|). + 1. Return an IDL [=async iterator=] value with type parameter |T| that represents |iterator|. + +
+ +
- To get the next value of an - async iterable<T> |iteratorRecord|, + To get the next value of an + async iterator<T> |iterator|, perform the following steps: + 1. Let |iteratorRecord| be the [=Iterator=] represented by |iterator|. 1. Let |nextResult| be the result of calling IteratorNext(|iteratorRecord|). 1. If |nextResult| is an abrupt completion, return [=a promise rejected with=] |nextResult|.\[[Value]]. @@ -8170,17 +8216,18 @@ object and a JavaScript [=Iterator=] record.
- To close an - async iterable<T> |iteratorRecord|, + To close an + async iterator<T> |iterator|, with a reason |reason|, perform the following steps: - 1. Let |iterator| be |iteratorRecord|.\[[Iterator]]. - 1. Let |returnMethod| be GetMethod(|iterator|, "return"). + 1. Let |iteratorRecord| be the [=Iterator=] represented by |iterator|. + 1. Let |iteratorObj| be |iteratorRecord|.\[[Iterator]]. + 1. Let |returnMethod| be GetMethod(|iteratorObj|, "return"). 1. If |returnMethod| is an abrupt completion, return [=a promise rejected with=] |returnMethod|.\[[Value]]. 1. If |returnMethod| is undefined, return [=a promise resolved with=] undefined. - 1. Let |returnResult| be Call(|returnMethod|.\[[Value]], |iterator|, « |reason| »). + 1. Let |returnResult| be Call(|returnMethod|.\[[Value]], |iteratorObj|, « |reason| »). 1. If |returnResult| is an abrupt completion, return [=a promise rejected with=] |returnResult|.\[[Value]]. 1. Let |returnPromise| be [=a promise resolved with=] |returnResult|.\[[Value]]. @@ -8211,23 +8258,24 @@ object and a JavaScript [=Iterator=] record. 1. Let |promise| be [=a new promise=]. 1. Let |result| be the empty string. 1. Let |n| be 0. + 1. Let |iterator| be the result of opening |iterable|. 1. Let |step| be a sequence of steps that will be used to process the async iterable: - 1. Let |next| be the result of getting the next value of |iterable|. + 1. Let |next| be the result of getting the next value of |iterator|. 1. [=React=] to |next|: - If |next| was fulfilled with value |v|: 1. If |v| is [=end of iteration=], [=resolve=] |promise| with |result|. 1. Set |result| to the result of concatenating |result| and |v|. 1. Set |n| to |n| + 1. 1. If |n| is |maxN|, then: - 1. Let |finish| be the result of closing - |iterable| with reason undefined. + 1. Let |finish| be the result of closing + |iterator| with reason undefined. 1. [=React=] to |finish|: - If |finish| was fulfilled, [=resolve=] |promise| with |result|. - If |finish| was rejected with reason |r|, [=reject=] |promise| with |r|. 1. Otherwise: 1. Call |step|. - If |next| was rejected with reason |r|, [=reject=] |promise| with |r|. - 1. Call step. + 1. Call |step|. 1. Return |promise|.
@@ -11347,7 +11395,7 @@ Note: The HTML Standard defines how a security check is performed. [[!HTML]] 1. Otherwise: if Type(|V|) is Object and there is an entry in |S| that has one of the following types at position |i| of its type list, - * a [=async iterable type=] + * an [=async iterable type=] * a [=nullable type|nullable=] version of any of the above types * an [=annotated type=] whose [=annotated types/inner type=] is one of the above types * a [=union type=], [=nullable type|nullable=] union type, or [=annotated type|annotated=] union type @@ -11363,7 +11411,7 @@ Note: The HTML Standard defines how a security check is performed. [[!HTML]] 1. Otherwise: if Type(|V|) is Object and there is an entry in |S| that has one of the following types at position |i| of its type list, - * a [=async iterable type=] + * an [=async iterable type=] * a [=sequence type=] * a [=frozen array type=] * a [=nullable type|nullable=] version of any of the above types @@ -11532,7 +11580,7 @@ Note: The HTML Standard defines how a security check is performed. [[!HTML]] Generally, the inspection of the value at the distinguishing argument index does not have any side effects, and the only side effects in the overload resolution algorithm are the result of converting the JavaScript values to IDL values. - (An exception exists when one of the overloads has a [=async iterable type=], [=sequence type=] + (An exception exists when one of the overloads has an [=async iterable type=], [=sequence type=] or [=frozen array type=] at the distinguishing argument index. In this case, we attempt to get the {{@@asyncIterator}} / {{@@iterator}} property to determine the appropriate overload, and perform the conversion of the distinguishing argument separately From 6559e0630dcd67c3a3e7dd3a622eb0554faf5e77 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Thu, 18 Jul 2024 13:25:50 +0200 Subject: [PATCH 07/20] fixes --- index.bs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.bs b/index.bs index 1a01117f..b78f3c0a 100644 --- a/index.bs +++ b/index.bs @@ -8145,7 +8145,7 @@ object, a JavaScript method, and a flag indicating whether the method is expecte 1. If |method| is undefined: 1. Set |syncMethod| to [=?=] GetMethod(obj, %Symbol.iterator%). 1. If |syncMethod| is undefined, [=JavaScript/throw=] a {{TypeError}}. - 1 Return the IDL async iterable value that represents a reference to the JavaScript object + 1. Return the IDL async iterable value that represents a reference to the JavaScript object |V|, the JavaScript method |syncMethod|, and the flag sync. 1. Return the IDL async iterable value that represents a reference to the JavaScript object |V|, the JavaScript method |method|, and the flag async. @@ -8158,9 +8158,9 @@ object, a JavaScript method, and a flag indicating whether the method is expecte 1. Return the JavaScript object that represents the same async iterable as the IDL value.
-
Async iterators
+
Async iterators
-IDL async-iterator values are represented by JavaScript [=Iterator=] +IDL async iterator values are represented by JavaScript [=Iterator=] records. Async iterators can only be created from an [=async iterable=] object. @@ -8172,7 +8172,7 @@ Async iterators can only be created from an [=async iterable=] object.
- To get the next value of an + To open an async iterable<T> |iterable|, perform the following steps: From 6f284c140e63b7557fcf269bf7a841bcc800880b Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Thu, 18 Jul 2024 15:54:12 +0200 Subject: [PATCH 08/20] fix --- index.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index edf3180b..2b086266 100644 --- a/index.bs +++ b/index.bs @@ -6232,8 +6232,8 @@ There is no way to represent an async iterable value in IDL.
Async iterator objects
An async iterator<|T|> value is a reference to an object -that can produce a sequence of values asynchronously. The async iterator value is is a parameterized -by a type |T|, which defines the types of values produced by this async iterator. +that can produce a sequence of values asynchronously. The async iterator value is parameterized by a +type |T|, which defines the types of values produced by this async iterator. Async iterators, unlike sequences, do not have a fixed length and can be infinite. Values are asynchronously produced as the async iterator is iterated over. From dcbe7388ed139f5c23788b0551b53122de789d77 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 23 Jul 2024 10:43:28 +0200 Subject: [PATCH 09/20] fix --- index.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.bs b/index.bs index 2b086266..3e3d2a23 100644 --- a/index.bs +++ b/index.bs @@ -6239,9 +6239,9 @@ Async iterators, unlike sequences, do not have a fixed length and can be infinit asynchronously produced as the async iterator is iterated over. Async iterators are values, not types, and thus cannot be used as a type in IDL. They can only be -created from [=async iterables=]. Thus, async iterators can not be used as the type of an IDL +created from [=async iterable types=]. Thus, async iterators can not be used as the type of an IDL operation parameter, an IDL interface attribute, or an IDL dictionary member. Instead an -[=async iterable=] should be used. +[=async iterable type=] should be used.

Record types — record<|K|, |V|>

@@ -8214,7 +8214,7 @@ object, a JavaScript method, and a flag indicating whether the method is expecte IDL async iterator values are represented by JavaScript [=Iterator=] records. -Async iterators can only be created from an [=async iterable=] object. +Async iterators can only be created from an [=async iterable type=].
Iterating async iterator
From bd86c51c8d4447df5f301d7e4be3c292c7182b96 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 23 Jul 2024 10:46:30 +0200 Subject: [PATCH 10/20] fix --- index.bs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 3e3d2a23..5506aa80 100644 --- a/index.bs +++ b/index.bs @@ -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: CreateAsyncFromSyncIteator; 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 @@ -11455,7 +11456,7 @@ Note: The HTML Standard defines how a security check is performed. [[!HTML]] and after performing the following steps, - 1. Let |method| be [=?=] GetMethod(|V|, {{@@asyncIterator}}). + 1. Let |method| be [=?=] GetMethod(|V|, {{%Symbol.asyncIterator%}}). |method| is not undefined, then remove from |S| all other entries. From f97033bdf68171e598762b9428b24ca9e386e408 Mon Sep 17 00:00:00 2001 From: Mattias Buelens Date: Thu, 25 Jul 2024 18:07:01 +0200 Subject: [PATCH 11/20] Fix typo --- index.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index 5506aa80..815f853d 100644 --- a/index.bs +++ b/index.bs @@ -34,7 +34,7 @@ urlPrefix: https://tc39.es/ecma262/; spec: ecmascript type: argument text: NewTarget; url: sec-built-in-function-objects type: abstract-op - text: CreateAsyncFromSyncIteator; url: sec-createasyncfromsynciterator + 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 @@ -8233,7 +8233,7 @@ Async iterators can only be created from an [=async iterable type=]. 1. Let |iterator| be [=?=] GetIteratorFromMethod(|object|, |method|). 1. If |iterable| has a flag that shows that it is expected to produce a sync iterator, then: - 1. Set |iterator| to CreateAsyncFromSyncIteator(|iterator|). + 1. Set |iterator| to CreateAsyncFromSyncIterator(|iterator|). 1. Return an IDL [=async iterator=] value with type parameter |T| that represents |iterator|.
From 30fb12d896faa0d0cb8a2e91f858c9ec2c08c19b Mon Sep 17 00:00:00 2001 From: Mattias Buelens Date: Thu, 25 Jul 2024 18:14:37 +0200 Subject: [PATCH 12/20] Fix link text --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 815f853d..bab8fc34 100644 --- a/index.bs +++ b/index.bs @@ -6209,7 +6209,7 @@ only [=list/items=] that are of type |T|. -

Async iterable types — async iterable<|T|>

+

Async iterable types — async iterable<|T|>

The async iterable<|T|> type is a parameterized type whose values are references to objects that can produce an [=async iterator=]. From 34691382b1ab4744b630117c1d79c0b895b346a5 Mon Sep 17 00:00:00 2001 From: Mattias Buelens Date: Thu, 25 Jul 2024 18:14:47 +0200 Subject: [PATCH 13/20] Fix duplicate dfn --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index bab8fc34..4bc2a61a 100644 --- a/index.bs +++ b/index.bs @@ -8210,7 +8210,7 @@ object, a JavaScript method, and a flag indicating whether the method is expecte 1. Return the JavaScript object that represents the same async iterable as the IDL value.
-
Async iterators
+
Async iterators
IDL async iterator values are represented by JavaScript [=Iterator=] records. From 947fb78b38a95acf55b37ab568f4ccf60381bc78 Mon Sep 17 00:00:00 2001 From: Mattias Buelens Date: Thu, 25 Jul 2024 18:15:46 +0200 Subject: [PATCH 14/20] Fix link id --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 4bc2a61a..3727614e 100644 --- a/index.bs +++ b/index.bs @@ -8210,7 +8210,7 @@ object, a JavaScript method, and a flag indicating whether the method is expecte 1. Return the JavaScript object that represents the same async iterable as the IDL value. -
Async iterators
+
Async iterators
IDL async iterator values are represented by JavaScript [=Iterator=] records. From 118b446822a9444bda821cbe825a5ecc09e7927b Mon Sep 17 00:00:00 2001 From: Mattias Buelens Date: Thu, 25 Jul 2024 18:17:23 +0200 Subject: [PATCH 15/20] Simplify --- index.bs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.bs b/index.bs index 3727614e..3c14da39 100644 --- a/index.bs +++ b/index.bs @@ -8212,8 +8212,7 @@ object, a JavaScript method, and a flag indicating whether the method is expecte
Async iterators
-IDL async iterator values are represented by JavaScript [=Iterator=] -records. +IDL [=async iterator=] values are represented by JavaScript [=Iterator=] records. Async iterators can only be created from an [=async iterable type=]. From 11f9a9f951ab334689d05eecbabdf99ab2ef635e Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 30 Jul 2024 14:36:29 +0200 Subject: [PATCH 16/20] review comments --- index.bs | 107 +++++++++++++++++++++++++++---------------------------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/index.bs b/index.bs index 3c14da39..ecb96302 100644 --- a/index.bs +++ b/index.bs @@ -6212,7 +6212,13 @@ only [=list/items=] that are of type |T|.

Async iterable types — async iterable<|T|>

The async iterable<|T|> type is a parameterized -type whose values are references to objects that can produce an [=async iterator=]. +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 @@ -6220,30 +6226,16 @@ async iterable being kept by that object. Similarly, any async iterable returned 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 can not be constructed from IDL. If returned from an operation, or used as the +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 may want to return an [=interface=] that has an +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. -
Async iterator objects
- -An async iterator<|T|> value is a reference to an object -that can produce a sequence of values asynchronously. The async iterator value is parameterized by a -type |T|, which defines the types of values produced by this async iterator. - -Async iterators, unlike sequences, do not have a fixed length and can be infinite. Values are -asynchronously produced as the async iterator is iterated over. - -Async iterators are values, not types, and thus cannot be used as a type in IDL. They can only be -created from [=async iterable types=]. Thus, async iterators can not be used as the type of an IDL -operation parameter, an IDL interface attribute, or an IDL dictionary member. Instead an -[=async iterable type=] should be used. -

Record types — record<|K|, |V|>

A record type is a parameterized type whose values are [=ordered maps=] with @@ -8183,13 +8175,17 @@ JavaScript Array values.

Async iterable — async iterable<|T|>

-IDL async iterable<|T|> values are represented by a JavaScript -object, a JavaScript method, and a flag indicating whether the method is expected to produce a -sync or async iterator. +In the JavaScript binding, IDL [=async iterable type|async iterable=] values are represented by +a [=struct=] with the following [=struct/items=]: + +* object, a JavaScript value +* method, a JavaScript value +* type, either "sync" or "async" +
A JavaScript value |V| is [=converted to an IDL value|converted=] - to an IDL async iterable<T> value as follows: + to an IDL async iterable<T> value as follows: 1. If Type(|V|) is not Object, [=JavaScript/throw=] a {{TypeError}}. @@ -8197,43 +8193,47 @@ object, a JavaScript method, and a flag indicating whether the method is expecte 1. If |method| is undefined: 1. Set |syncMethod| to [=?=] GetMethod(obj, {{%Symbol.iterator%}}). 1. If |syncMethod| is undefined, [=JavaScript/throw=] a {{TypeError}}. - 1. Return the IDL async iterable value that represents a reference to the JavaScript object - |V|, the JavaScript method |syncMethod|, and the flag sync. - 1. Return the IDL async iterable value that represents a reference to the JavaScript object - |V|, the JavaScript method |method|, and the flag async. + 1. Return an IDL [=async iterable=] value with [=JS async iterable/object=] set to |V|, + [=JS async iterable/method=] set to |syncMethod|, and [=JS async iterable/type=] set to + "sync". + 1. Return an IDL [=async iterable=] value with [=JS async iterable/object=] set to |V|, + [=JS async iterable/method=] set to |method|, and [=JS async iterable/type=] set to + "async".
- An IDL async iterable<T> value is + An IDL async iterable<T> value |V| is [=converted to a JavaScript value|converted=] to a JavaScript object as follows: - 1. Return the JavaScript object that represents the same async iterable as the IDL value. + 1. Return |V|'s [=JS async iterable/object=].
Async iterators
-IDL [=async iterator=] values are represented by JavaScript [=Iterator=] records. +Async iterator values are represented by a [=struct=] with the following [=struct/items=]: -Async iterators can only be created from an [=async iterable type=]. +* underlying record, an [=Iterator=] record +* type parameter, a IDL type representing the type of values produced by the async iterator -
Iterating async iterator
+An [=async iterable=] is not directly iterated over. Instead, it is first opened to create +a [=async iterator=]. The [=async iterator=] can be asynchronously iterated over to produce values. + +
Iterating async iterators
[=Async iterables=] are not directly iterated over. They are first opened, to create a new [=async iterator=], and then the [=async iterator=] is iterated over.
- To open an - async iterable<T> |iterable|, - perform the following steps: + To open an + async iterable<T> |iterable|: - 1. Let |object| be the |iterable|'s JavaScript object. - 1. Let |method| be the |iterable|'s JavaScript method. - 1. Let |iterator| be [=?=] GetIteratorFromMethod(|object|, |method|). - 1. If |iterable| has a flag that shows that it is expected to produce a - sync iterator, then: - 1. Set |iterator| to CreateAsyncFromSyncIterator(|iterator|). - 1. Return an IDL [=async iterator=] value with type parameter |T| that represents |iterator|. + 1. Let |iterator| be [=?=] GetIteratorFromMethod(|iterable|'s + [=JS async iterable/object=], |iterable|'s [=JS async iterable/method=]). + 1. If |iterable|'s [=JS async iterable/type=] is "sync", set |iterator| to + CreateAsyncFromSyncIterator(|iterator|). + 1. Return a [=async iterator=] value with [=JS async iterator/underlying record=] set to |iterator| and + [=JS async iterator/type parameter=] set to |T|.
@@ -8242,11 +8242,10 @@ Async iterators can only be created from an [=async iterable type=].
To get the next value of an - async iterator<T> |iterator|, - perform the following steps: + async iterator |iterator|: - 1. Let |iteratorRecord| be the [=Iterator=] represented by |iterator|. - 1. Let |nextResult| be the result of calling IteratorNext(|iteratorRecord|). + 1. Let |nextResult| be the result of calling + IteratorNext(|iterator|'s [=JS async iterator/underlying record=]). 1. If |nextResult| is an abrupt completion, return [=a promise rejected with=] |nextResult|.\[[Value]]. 1. Let |nextPromise| be [=a promise resolved with=] |nextResult|.\[[Value]]. @@ -8260,7 +8259,7 @@ Async iterators can only be created from an [=async iterable type=]. 1. Otherwise: 1. Let |V| be [=?=] IteratorValue(|iterResult|). 1. Let |value| be the result of [=converted to an IDL value|converting=] |V| to an IDL - value of type |T|. + value of type |iterator|'s [=JS async iterator/type parameter=]. 1. Return |value|.
@@ -8271,13 +8270,13 @@ Async iterators can only be created from an [=async iterable type=]. async iterator<T> |iterator|, with a reason |reason|, perform the following steps: - 1. Let |iteratorRecord| be the [=Iterator=] represented by |iterator|. - 1. Let |iteratorObj| be |iteratorRecord|.\[[Iterator]]. - 1. Let |returnMethod| be GetMethod(|iteratorObj|, "return"). + 1. Let |iteratorRecord| be |iterator|'s [=JS async iterator/underlying record=]. + 1. Let |iteratorObj| be |iteratorRecord|.\[[Iterator]] + 1. Let |returnMethod| be GetMethod(|iteratorObj|, "return"). 1. If |returnMethod| is an abrupt completion, return [=a promise rejected with=] |returnMethod|.\[[Value]]. 1. If |returnMethod| is undefined, return [=a promise resolved with=] - undefined. + {{undefined}}. 1. Let |returnResult| be Call(|returnMethod|.\[[Value]], |iteratorObj|, « |reason| »). 1. If |returnResult| is an abrupt completion, return [=a promise rejected with=] |returnResult|.\[[Value]]. @@ -8286,7 +8285,7 @@ Async iterators can only be created from an [=async iterable type=]. given |returnPromiseResult|: 1. If Type(|returnPromiseResult|) is not Object, [=JavaScript/throw=] a {{TypeError}}. - 1. Return undefined. + 1. Return {{undefined}}. @@ -8294,11 +8293,12 @@ Async iterators can only be created from an [=async iterable type=]. concatN is an [=operation=] that returns a promise that will be fulfilled with the concatenation of all the strings yielded by the async iterable passed to it. It stops - concatenating and closes the iterator once the async iterable has yielded N strings. + concatenating and closes the iterator once the async iterable has yielded maxN + strings.
         interface I {
-          Promise<DOMString> concat(async iterable<DOMString> strings, unsigned long maxN);
+          Promise<DOMString> concatN(async iterable<DOMString> strings, unsigned long maxN);  
         };
     
@@ -8319,7 +8319,7 @@ Async iterators can only be created from an [=async iterable type=]. 1. Set |n| to |n| + 1. 1. If |n| is |maxN|, then: 1. Let |finish| be the result of closing - |iterator| with reason undefined. + |iterator| with reason {{undefined}}. 1. [=React=] to |finish|: - If |finish| was fulfilled, [=resolve=] |promise| with |result|. - If |finish| was rejected with reason |r|, [=reject=] |promise| with |r|. @@ -8333,7 +8333,6 @@ Async iterators can only be created from an [=async iterable type=]. -

Records — record<|K|, |V|>

From dc079724ca70db1ef271120e5302ffd63bda36f0 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 30 Jul 2024 15:13:51 +0200 Subject: [PATCH 17/20] fix --- index.bs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/index.bs b/index.bs index ecb96302..f3912b51 100644 --- a/index.bs +++ b/index.bs @@ -6226,10 +6226,10 @@ async iterable being kept by that object. Similarly, any async iterable returned 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 +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 +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=]. @@ -8212,8 +8212,8 @@ a [=struct=] with the following [=struct/items=]: Async iterator values are represented by a [=struct=] with the following [=struct/items=]: -* underlying record, an [=Iterator=] record -* type parameter, a IDL type representing the type of values produced by the async iterator +* underlying record, a [=Iterator=] record +* type parameter, an IDL type representing the type of values produced by the async iterator An [=async iterable=] is not directly iterated over. Instead, it is first opened to create a [=async iterator=]. The [=async iterator=] can be asynchronously iterated over to produce values. @@ -8225,8 +8225,8 @@ a [=async iterator=]. The [=async iterator=] can be asynchronously iterated over
- To open an - async iterable<T> |iterable|: + To open an + async iterable<T> |iterable|: 1. Let |iterator| be [=?=] GetIteratorFromMethod(|iterable|'s [=JS async iterable/object=], |iterable|'s [=JS async iterable/method=]). @@ -8272,7 +8272,7 @@ a [=async iterator=]. The [=async iterator=] can be asynchronously iterated over 1. Let |iteratorRecord| be |iterator|'s [=JS async iterator/underlying record=]. 1. Let |iteratorObj| be |iteratorRecord|.\[[Iterator]] - 1. Let |returnMethod| be GetMethod(|iteratorObj|, "return"). + 1. Let |returnMethod| be GetMethod(|iteratorObj|, "return"). 1. If |returnMethod| is an abrupt completion, return [=a promise rejected with=] |returnMethod|.\[[Value]]. 1. If |returnMethod| is undefined, return [=a promise resolved with=] @@ -8294,11 +8294,11 @@ a [=async iterator=]. The [=async iterator=] can be asynchronously iterated over concatN is an [=operation=] that returns a promise that will be fulfilled with the concatenation of all the strings yielded by the async iterable passed to it. It stops concatenating and closes the iterator once the async iterable has yielded maxN - strings. + strings.
         interface I {
-          Promise<DOMString> concatN(async iterable<DOMString> strings, unsigned long maxN);  
+          Promise<DOMString> concatN(async iterable<DOMString> strings, unsigned long maxN);
         };
     
From dd56f977f356700fad005a8f254833543e6e8cfa Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 30 Jul 2024 16:06:53 +0200 Subject: [PATCH 18/20] an --- index.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index f3912b51..1549b227 100644 --- a/index.bs +++ b/index.bs @@ -8212,7 +8212,7 @@ a [=struct=] with the following [=struct/items=]: Async iterator values are represented by a [=struct=] with the following [=struct/items=]: -* underlying record, a [=Iterator=] record +* underlying record, an [=Iterator=] record * type parameter, an IDL type representing the type of values produced by the async iterator An [=async iterable=] is not directly iterated over. Instead, it is first opened to create @@ -8232,7 +8232,7 @@ a [=async iterator=]. The [=async iterator=] can be asynchronously iterated over [=JS async iterable/object=], |iterable|'s [=JS async iterable/method=]). 1. If |iterable|'s [=JS async iterable/type=] is "sync", set |iterator| to CreateAsyncFromSyncIterator(|iterator|). - 1. Return a [=async iterator=] value with [=JS async iterator/underlying record=] set to |iterator| and + 1. Return an [=async iterator=] value with [=JS async iterator/underlying record=] set to |iterator| and [=JS async iterator/type parameter=] set to |T|.
From 9a79b428c94094e7dd7fe60333c58b92013df67d Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Fri, 2 Aug 2024 14:48:58 +0200 Subject: [PATCH 19/20] fixes --- index.bs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/index.bs b/index.bs index 1549b227..727bf0d8 100644 --- a/index.bs +++ b/index.bs @@ -6211,7 +6211,7 @@ only [=list/items=] that are of type |T|.

Async iterable types — async iterable<|T|>

-The async iterable<|T|> type is a parameterized +The async iterable type is a parameterized type whose values are references to objects that can produce an asynchronously iterable, possibly infinite, sequence of values of type |T|. @@ -8202,26 +8202,20 @@ a [=struct=] with the following [=struct/items=]:
- An IDL async iterable<T> value |V| is + An IDL async iterable<T> value |V| is [=converted to a JavaScript value|converted=] to a JavaScript object as follows: 1. Return |V|'s [=JS async iterable/object=].
-
Async iterators
- -Async iterator values are represented by a [=struct=] with the following [=struct/items=]: - -* underlying record, an [=Iterator=] record -* type parameter, an IDL type representing the type of values produced by the async iterator +
Iterating async iterators
An [=async iterable=] is not directly iterated over. Instead, it is first opened to create a [=async iterator=]. The [=async iterator=] can be asynchronously iterated over to produce values. -
Iterating async iterators
- -[=Async iterables=] are not directly iterated over. They are first opened, to create a new -[=async iterator=], and then the [=async iterator=] is iterated over. +Async iterators are [=structs=] with the following [=struct/items=]: +* underlying record, an [=Iterator=] record +* type parameter, an IDL type representing the type of values produced by the async iterator
@@ -8242,9 +8236,9 @@ a [=async iterator=]. The [=async iterator=] can be asynchronously iterated over
To get the next value of an - async iterator |iterator|: + [=async iterator=] |iterator|: - 1. Let |nextResult| be the result of calling + 1. Let |nextResult| be IteratorNext(|iterator|'s [=JS async iterator/underlying record=]). 1. If |nextResult| is an abrupt completion, return [=a promise rejected with=] |nextResult|.\[[Value]]. @@ -8268,7 +8262,7 @@ a [=async iterator=]. The [=async iterator=] can be asynchronously iterated over To close an async iterator<T> |iterator|, - with a reason |reason|, perform the following steps: + with a reason |reason|: 1. Let |iteratorRecord| be |iterator|'s [=JS async iterator/underlying record=]. 1. Let |iteratorObj| be |iteratorRecord|.\[[Iterator]] From 63748632087af0abad7fe97a3fc32c6d936e3145 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 5 Aug 2024 09:22:44 +0200 Subject: [PATCH 20/20] review comments --- index.bs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.bs b/index.bs index 727bf0d8..ad773992 100644 --- a/index.bs +++ b/index.bs @@ -6211,7 +6211,7 @@ only [=list/items=] that are of type |T|.

Async iterable types — async iterable<|T|>

-The async iterable type is a parameterized +An async iterable type is a parameterized type whose values are references to objects that can produce an asynchronously iterable, possibly infinite, sequence of values of type |T|. @@ -8173,7 +8173,7 @@ JavaScript Array values.
-

Async iterable — async iterable<|T|>

+

Async iterables — async iterable<|T|>

In the JavaScript binding, IDL [=async iterable type|async iterable=] values are represented by a [=struct=] with the following [=struct/items=]: @@ -8211,7 +8211,7 @@ a [=struct=] with the following [=struct/items=]:
Iterating async iterators
An [=async iterable=] is not directly iterated over. Instead, it is first opened to create -a [=async iterator=]. The [=async iterator=] can be asynchronously iterated over to produce values. +an [=async iterator=]. The [=async iterator=] can be asynchronously iterated over to produce values. Async iterators are [=structs=] with the following [=struct/items=]: * underlying record, an [=Iterator=] record @@ -8265,7 +8265,7 @@ a [=async iterator=]. The [=async iterator=] can be asynchronously iterated over with a reason |reason|: 1. Let |iteratorRecord| be |iterator|'s [=JS async iterator/underlying record=]. - 1. Let |iteratorObj| be |iteratorRecord|.\[[Iterator]] + 1. Let |iteratorObj| be |iteratorRecord|.\[[Iterator]]. 1. Let |returnMethod| be GetMethod(|iteratorObj|, "return"). 1. If |returnMethod| is an abrupt completion, return [=a promise rejected with=] |returnMethod|.\[[Value]].