WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 5ea7721

Browse files
michaelficarraljharb
authored andcommitted
Editorial: use an AC in PerformPromiseAll (#3722)
1 parent aefd096 commit 5ea7721

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

spec.html

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49264,7 +49264,7 @@ <h1>
4926449264
</emu-alg>
4926549265
</emu-clause>
4926649266

49267-
<emu-clause id="sec-performpromiseall" type="abstract operation">
49267+
<emu-clause id="sec-performpromiseall" oldids="sec-promise.all-resolve-element-functions" type="abstract operation">
4926849268
<h1>
4926949269
PerformPromiseAll (
4927049270
_iteratorRecord_: an Iterator Record,
@@ -49277,6 +49277,7 @@ <h1>
4927749277
</dl>
4927849278
<emu-alg>
4927949279
1. Let _values_ be a new empty List.
49280+
1. [declared="remainingElementsCount"] NOTE: _remainingElementsCount_ starts at 1 instead of 0 to ensure _resultCapability_.[[Resolve]] is only called once, even in the presence of a misbehaving *"then"* which calls the passed callback before the input iterator is exhausted.
4928049281
1. Let _remainingElementsCount_ be the Record { [[Value]]: 1 }.
4928149282
1. Let _index_ be 0.
4928249283
1. Repeat,
@@ -49289,40 +49290,24 @@ <h1>
4928949290
1. Return _resultCapability_.[[Promise]].
4929049291
1. Append *undefined* to _values_.
4929149292
1. Let _nextPromise_ be ? Call(_promiseResolve_, _constructor_, « _next_ »).
49292-
1. Let _steps_ be the algorithm steps defined in <emu-xref href="#sec-promise.all-resolve-element-functions" title></emu-xref>.
49293-
1. Let _length_ be the number of non-optional parameters of the function definition in <emu-xref href="#sec-promise.all-resolve-element-functions" title></emu-xref>.
49294-
1. Let _onFulfilled_ be CreateBuiltinFunction(_steps_, _length_, *""*, « [[AlreadyCalled]], [[Index]], [[Values]], [[Capability]], [[RemainingElements]] »).
49293+
1. Let _fulfilledSteps_ be a new Abstract Closure with parameters (_value_) that captures _values_, _resultCapability_, and _remainingElementsCount_ and performs the following steps when called:
49294+
1. Let _F_ be the active function object.
49295+
1. If _F_.[[AlreadyCalled]] is *true*, return *undefined*.
49296+
1. Set _F_.[[AlreadyCalled]] to *true*.
49297+
1. Let _index_ be _F_.[[Index]].
49298+
1. Set _values_[_index_] to _value_.
49299+
1. Set _remainingElementsCount_.[[Value]] to _remainingElementsCount_.[[Value]] - 1.
49300+
1. If _remainingElementsCount_.[[Value]] = 0, then
49301+
1. Let _valuesArray_ be CreateArrayFromList(_values_).
49302+
1. Return ? Call(_resultCapability_.[[Resolve]], *undefined*, « _valuesArray_ »).
49303+
1. Return *undefined*.
49304+
1. Let _onFulfilled_ be CreateBuiltinFunction(_fulfilledSteps_, 1, *""*, « [[AlreadyCalled]], [[Index]] »).
4929549305
1. Set _onFulfilled_.[[AlreadyCalled]] to *false*.
4929649306
1. Set _onFulfilled_.[[Index]] to _index_.
49297-
1. Set _onFulfilled_.[[Values]] to _values_.
49298-
1. Set _onFulfilled_.[[Capability]] to _resultCapability_.
49299-
1. Set _onFulfilled_.[[RemainingElements]] to _remainingElementsCount_.
49307+
1. Set _index_ to _index_ + 1.
4930049308
1. Set _remainingElementsCount_.[[Value]] to _remainingElementsCount_.[[Value]] + 1.
4930149309
1. Perform ? Invoke(_nextPromise_, *"then"*, « _onFulfilled_, _resultCapability_.[[Reject]] »).
49302-
1. Set _index_ to _index_ + 1.
49303-
</emu-alg>
49304-
</emu-clause>
49305-
49306-
<emu-clause id="sec-promise.all-resolve-element-functions">
49307-
<h1>`Promise.all` Resolve Element Functions</h1>
49308-
<p>A `Promise.all` resolve element function is an anonymous built-in function that is used to resolve a specific `Promise.all` element. Each `Promise.all` resolve element function has [[Index]], [[Values]], [[Capability]], [[RemainingElements]], and [[AlreadyCalled]] internal slots.</p>
49309-
<p>When a `Promise.all` resolve element function is called with argument _x_, the following steps are taken:</p>
49310-
<emu-alg>
49311-
1. Let _F_ be the active function object.
49312-
1. If _F_.[[AlreadyCalled]] is *true*, return *undefined*.
49313-
1. Set _F_.[[AlreadyCalled]] to *true*.
49314-
1. Let _index_ be _F_.[[Index]].
49315-
1. Let _values_ be _F_.[[Values]].
49316-
1. Let _promiseCapability_ be _F_.[[Capability]].
49317-
1. Let _remainingElementsCount_ be _F_.[[RemainingElements]].
49318-
1. Set _values_[_index_] to _x_.
49319-
1. Set _remainingElementsCount_.[[Value]] to _remainingElementsCount_.[[Value]] - 1.
49320-
1. If _remainingElementsCount_.[[Value]] = 0, then
49321-
1. Let _valuesArray_ be CreateArrayFromList(_values_).
49322-
1. Return ? Call(_promiseCapability_.[[Resolve]], *undefined*, « _valuesArray_ »).
49323-
1. Return *undefined*.
4932449310
</emu-alg>
49325-
<p>The *"length"* property of a `Promise.all` resolve element function is *1*<sub>𝔽</sub>.</p>
4932649311
</emu-clause>
4932749312
</emu-clause>
4932849313

0 commit comments

Comments
 (0)