From 44515a6d7e8d1d28a9b02b6774d4c28e9f2a5f3e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=2E=C2=A0S=2E=C2=A0Choi?= Array.fromAsync ( _asyncItems_ [ , _mapper_ [ , _thisArg_ ] ] )
clause.
When the `fromAsync` method is called, the following steps are taken:
+This async method performs the following steps when called:
The `fromAsync` function is an intentionally generic factory method; it does not require that its *this* value be the Array constructor. Therefore it can be transferred to or inherited by any other constructors that may be called with a single numeric argument.
+This method is an intentionally generic factory method; it does not require that its *this* value be the Array constructor. Therefore it can be transferred to or inherited by any other constructors that may be called with a single numeric argument.
This proposal depends on the pull request tc39/ecma262#2942: “support built-in async functions”.
-See Common Iteration Interfaces (
See Common Iteration Interfaces (
means the same thing as:
-title: ES Array.fromAsync (2022) +title: ES Array.fromAsync (2025) status: proposal stage: 3 (Conditional on Editor Review) location: https://github.com/js-choi/proposal-array-async-from From b1f7dc1aae0f781addba33c7e9bbda05fe43236b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=C2=A0S=2E=C2=A0Choi?=Date: Thu, 1 May 2025 07:31:06 -0600 Subject: [PATCH 8/9] editorial: Add aoid attribute for IfAbruptCloseAsyncIterator --- spec.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec.html b/spec.html index 1518eb9..f40fca5 100644 --- a/spec.html +++ b/spec.html @@ -1,5 +1,5 @@ -title: ES Array.fromAsync (2025) +title: ES Array.fromAsync status: proposal stage: 3 (Conditional on Editor Review) location: https://github.com/js-choi/proposal-array-async-from @@ -24,7 +24,7 @@Abstract Operations
@@ -65,18 +63,19 @@ Operations on Iterator Objects
-+ IfAbruptCloseAsyncIterator ( _value_, _iteratorRecord_ )
IfAbruptCloseAsyncIterator is a shorthand for a sequence of algorithm steps that use an Iterator Record. An algorithm step of the form:
From 04d43c0de2f2be60f59dae32d1c4d9a534c2a4fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=C2=A0S=2E=C2=A0Choi?= Date: Thu, 1 May 2025 14:22:07 -0500 Subject: [PATCH 9/9] Editorial changes to match Array.from spec, esformat * IfAbruptCloseAsyncIterator now directly uses the return value of AsyncIteratorClose. This is an editorial change. * Editorial formatting changes have been done, e.g., avoiding unnecessary HTML entities and making if/else subclauses use blocks if any alternative branch uses blocks. --- spec.html | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/spec.html b/spec.html index f40fca5..6d3fae5 100644 --- a/spec.html +++ b/spec.html @@ -26,19 +26,17 @@ Operations on Iterator Objects
+ IfAbruptCloseAsyncIterator ( _value_, _iteratorRecord_ )
-IfAbruptCloseAsyncIterator is a shorthand for a sequence of algorithm steps that use an Iterator Record. An algorithm step of the form:
+IfAbruptCloseAsyncIterator is a shorthand for a sequence of algorithm steps that use an Iterator Record. An algorithm step of the form:
1. IfAbruptCloseAsyncIterator(_value_, _iteratorRecord_). means the same thing as:
1. Assert: _value_ is a Completion Record. - 1. If _value_ is an abrupt completion, then - 1. Perform ? AsyncIteratorClose(_iteratorRecord_, _value_). - 1. Return _value_. - 1. Else if _value_ is a Completion Record, set _value_ to _value_.[[Value]]. + 1. If _value_ is an abrupt completion, return ? AsyncIteratorClose(_iteratorRecord_, _value_). + 1. Else, set _value_ to ! _value_. -Array.fromAsync ( _asyncItems_ [ , _mapper_ [ , _thisArg_ ] ] )
This async method performs the following steps when called:
1. Let _C_ be the *this* value. - 1. If _mapper_ is *undefined*, let _mapping_ be *false*. + 1. If _mapper_ is *undefined*, then + 1. Let _mapping_ be *false*. 1. Else, 1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception. 1. Let _mapping_ be *true*. - 1. Let _usingAsyncIterator_ be ? GetMethod(_asyncItems_, @@asyncIterator). + 1. Let _usingAsyncIterator_ be ? GetMethod(_asyncItems_, %Symbol.asyncIterator%). 1. If _usingAsyncIterator_ is *undefined*, then - 1. Let _usingSyncIterator_ be ? GetMethod(_asyncItems_, @@iterator). + 1. Let _usingSyncIterator_ be ? GetMethod(_asyncItems_, %Symbol.iterator%). 1. Let _iteratorRecord_ be *undefined*. 1. If _usingAsyncIterator_ is not *undefined*, then 1. Set _iteratorRecord_ to ? GetIteratorFromMethod(_asyncItems_, _usingAsyncIterator_). 1. Else if _usingSyncIterator_ is not *undefined*, then - 1. Set _iteratorRecord_ to ? CreateAsyncFromSyncIterator(? GetIteratorFromMethod(_asyncItems_, _usingSyncIterator_)). + 1. Set _iteratorRecord_ to CreateAsyncFromSyncIterator(? GetIteratorFromMethod(_asyncItems_, _usingSyncIterator_)). 1. If _iteratorRecord_ is not *undefined*, then 1. If IsConstructor(_C_) is *true*, then 1. Let _A_ be ? Construct(_C_). @@ -84,7 +83,7 @@ Array.fromAsync ( _asyncItems_ [ , _mapper_ [ , _thisArg_ ] ] ) 1. Let _A_ be ! ArrayCreate(0). 1. Let _k_ be 0. 1. Repeat, - 1. If _k_ ≥ 253 - 1, then + 1. If _k_ ≥ 253 - 1, then 1. Let _error_ be ThrowCompletion(a newly created *TypeError* object). 1. Return ? AsyncIteratorClose(_iteratorRecord_, _error_). 1. Let _Pk_ be ! ToString(đť”˝(_k_)). @@ -92,25 +91,26 @@
Array.fromAsync ( _asyncItems_ [ , _mapper_ [ , _thisArg_ ] ] ) 1. Set _nextResult_ to ? Await(_nextResult_). 1. If _nextResult_ is not an Object, throw a *TypeError* exception. 1. Let _done_ be ? IteratorComplete(_nextResult_). - 1. If _done_ is *true*, + 1. If _done_ is *true*, then 1. Perform ? Set(_A_, *"length"*, đť”˝(_k_), *true*). 1. Return _A_. 1. Let _nextValue_ be ? IteratorValue(_nextResult_). 1. If _mapping_ is *true*, then - 1. Let _mappedValue_ be Call(_mapper_, _thisArg_, « _nextValue_, đť”˝(_k_) »). + 1. Let _mappedValue_ be Completion(Call(_mapper_, _thisArg_, « _nextValue_, đť”˝(_k_) »)). 1. IfAbruptCloseAsyncIterator(_mappedValue_, _iteratorRecord_). - 1. Set _mappedValue_ to Await(_mappedValue_). + 1. Set _mappedValue_ to Completion(Await(_mappedValue_)). 1. IfAbruptCloseAsyncIterator(_mappedValue_, _iteratorRecord_). - 1. Else, let _mappedValue_ be _nextValue_. - 1. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). - 1. If _defineStatus_ is an abrupt completion, return ? AsyncIteratorClose(_iteratorRecord_, _defineStatus_). + 1. Else, + 1. Let _mappedValue_ be _nextValue_. + 1. Let _defineStatus_ be Completion(CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_)). + 1. IfAbruptCloseAsyncIterator(_defineStatus_, _iteratorRecord_). 1. Set _k_ to _k_ + 1. 1. Else, 1. NOTE: _asyncItems_ is neither an AsyncIterable nor an Iterable so assume it is an array-like object. 1. Let _arrayLike_ be ! ToObject(_asyncItems_). 1. Let _len_ be ? LengthOfArrayLike(_arrayLike_). 1. If IsConstructor(_C_) is *true*, then - 1. Let _A_ be ? Construct(_C_, « đť”˝(_len_) »). + 1. Let _A_ be ? Construct(_C_, « đť”˝(_len_) »). 1. Else, 1. Let _A_ be ? ArrayCreate(_len_). 1. Let _k_ be 0. @@ -119,9 +119,10 @@
Array.fromAsync ( _asyncItems_ [ , _mapper_ [ , _thisArg_ ] ] ) 1. Let _kValue_ be ? Get(_arrayLike_, _Pk_). 1. Set _kValue_ to ? Await(_kValue_). 1. If _mapping_ is *true*, then - 1. Let _mappedValue_ be ? Call(_mapper_, _thisArg_, « _kValue_, đť”˝(_k_) »). + 1. Let _mappedValue_ be ? Call(_mapper_, _thisArg_, « _kValue_, đť”˝(_k_) »). 1. Set _mappedValue_ to ? Await(_mappedValue_). - 1. Else, let _mappedValue_ be _kValue_. + 1. Else, + 1. Let _mappedValue_ be _kValue_. 1. Perform ? CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). 1. Set _k_ to _k_ + 1. 1. Perform ? Set(_A_, *"length"*, đť”˝(_len_), *true*).