Skip to content

Redefine fromAsync as “built-in async function” #50

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

Merged
merged 9 commits into from
May 15, 2025
Next Next commit
Spec: First pass at conforming to "built-in async method" system
  • Loading branch information
js-choi committed Apr 5, 2025
commit 44515a6d7e8d1d28a9b02b6774d4c28e9f2a5f3e
14 changes: 5 additions & 9 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ <h1><ins>Array.fromAsync ( _asyncItems_ [ , _mapper_ [ , _thisArg_ ] ] )</ins></
clause</a>.</p>
</emu-note>

<p>When the `fromAsync` method is called, the following steps are taken:</p>
<p>This async method performs the following steps when called:</p>
<emu-alg>
1. Let _C_ be the *this* value.
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
1. Let _fromAsyncClosure_ be a new Abstract Closure with no parameters that captures _C_, _asyncItems_, _mapper_, and _thisArg_ and performs the following steps when called:
1. Let _C_ be the *this* value.
1. If _mapper_ is *undefined*, let _mapping_ be *false*.
1. Else,
1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception.
Expand Down Expand Up @@ -99,7 +97,7 @@ <h1><ins>Array.fromAsync ( _asyncItems_ [ , _mapper_ [ , _thisArg_ ] ] )</ins></
1. Let _done_ be ? IteratorComplete(_nextResult_).
1. If _done_ is *true*,
1. Perform ? Set(_A_, *"length"*, 𝔽(_k_), *true*).
1. Return Completion Record { [[Type]]: ~return~, [[Value]]: _A_, [[Target]]: ~empty~ }.
1. Return _A_.
1. Let _nextValue_ be ? IteratorValue(_nextResult_).
1. If _mapping_ is *true*, then
1. Let _mappedValue_ be Call(_mapper_, _thisArg_, &laquo; _nextValue_, 𝔽(_k_) &raquo;).
Expand Down Expand Up @@ -130,12 +128,10 @@ <h1><ins>Array.fromAsync ( _asyncItems_ [ , _mapper_ [ , _thisArg_ ] ] )</ins></
1. Perform ? CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_).
1. Set _k_ to _k_ + 1.
1. Perform ? Set(_A_, *"length"*, 𝔽(_len_), *true*).
1. Return Completion Record { [[Type]]: ~return~, [[Value]]: _A_, [[Target]]: ~empty~ }.
1. Perform AsyncFunctionStart(_promiseCapability_, _fromAsyncClosure_).
1. Return _promiseCapability_.[[Promise]].
1. Return _A_.
</emu-alg>
<emu-note>
<p>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.</p>
<p>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.</p>
</emu-note>
</emu-clause>
</emu-clause>
Expand Down