Skip to content

Commit 8a7178c

Browse files
michaelficarraljharb
authored andcommitted
Editorial: use an AC in PerformPromiseAny (#3729)
1 parent 4d2116b commit 8a7178c

File tree

1 file changed

+18
-34
lines changed

1 file changed

+18
-34
lines changed

spec.html

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -49450,7 +49450,7 @@ <h1>Promise.any ( _iterable_ )</h1>
4945049450
<p>This function requires its *this* value to be a constructor function that supports the parameter conventions of the `Promise` constructor.</p>
4945149451
</emu-note>
4945249452

49453-
<emu-clause id="sec-performpromiseany" type="abstract operation">
49453+
<emu-clause id="sec-performpromiseany" oldids="sec-promise.any-reject-element-functions" type="abstract operation">
4945449454
<h1>
4945549455
PerformPromiseAny (
4945649456
_iteratorRecord_: an Iterator Record,
@@ -49463,54 +49463,38 @@ <h1>
4946349463
</dl>
4946449464
<emu-alg>
4946549465
1. Let _errors_ be a new empty List.
49466+
1. [declared="remainingElementsCount"] NOTE: _remainingElementsCount_ starts at 1 instead of 0 to ensure _resultCapability_.[[Reject]] is only called once, even in the presence of a misbehaving *"then"* which calls the passed callback before the input iterator is exhausted.
4946649467
1. Let _remainingElementsCount_ be the Record { [[Value]]: 1 }.
4946749468
1. Let _index_ be 0.
4946849469
1. Repeat,
4946949470
1. Let _next_ be ? IteratorStepValue(_iteratorRecord_).
4947049471
1. If _next_ is ~done~, then
4947149472
1. Set _remainingElementsCount_.[[Value]] to _remainingElementsCount_.[[Value]] - 1.
4947249473
1. If _remainingElementsCount_.[[Value]] = 0, then
49473-
1. Let _error_ be a newly created *AggregateError* object.
49474-
1. Perform ! DefinePropertyOrThrow(_error_, *"errors"*, PropertyDescriptor { [[Configurable]]: *true*, [[Enumerable]]: *false*, [[Writable]]: *true*, [[Value]]: CreateArrayFromList(_errors_) }).
49475-
1. Return ThrowCompletion(_error_).
49474+
1. Let _aggregateError_ be a newly created *AggregateError* object.
49475+
1. Perform ! DefinePropertyOrThrow(_aggregateError_, *"errors"*, PropertyDescriptor { [[Configurable]]: *true*, [[Enumerable]]: *false*, [[Writable]]: *true*, [[Value]]: CreateArrayFromList(_errors_) }).
49476+
1. Perform ? Call(_resultCapability_.[[Reject]], *undefined*, « _aggregateError_ »).
4947649477
1. Return _resultCapability_.[[Promise]].
4947749478
1. Append *undefined* to _errors_.
4947849479
1. Let _nextPromise_ be ? Call(_promiseResolve_, _constructor_, « _next_ »).
49479-
1. Let _stepsRejected_ be the algorithm steps defined in <emu-xref href="#sec-promise.any-reject-element-functions" title></emu-xref>.
49480-
1. Let _lengthRejected_ be the number of non-optional parameters of the function definition in <emu-xref href="#sec-promise.any-reject-element-functions" title></emu-xref>.
49481-
1. Let _onRejected_ be CreateBuiltinFunction(_stepsRejected_, _lengthRejected_, *""*, « [[AlreadyCalled]], [[Index]], [[Errors]], [[Capability]], [[RemainingElements]] »).
49480+
1. Let _rejectedSteps_ be a new Abstract Closure with parameters (_error_) that captures _errors_, _resultCapability_, and _remainingElementsCount_ and performs the following steps when called:
49481+
1. Let _F_ be the active function object.
49482+
1. If _F_.[[AlreadyCalled]] is *true*, return *undefined*.
49483+
1. Set _F_.[[AlreadyCalled]] to *true*.
49484+
1. Set _errors_[_F_.[[Index]]] to _error_.
49485+
1. Set _remainingElementsCount_.[[Value]] to _remainingElementsCount_.[[Value]] - 1.
49486+
1. If _remainingElementsCount_.[[Value]] = 0, then
49487+
1. Let _aggregateError_ be a newly created *AggregateError* object.
49488+
1. Perform ! DefinePropertyOrThrow(_aggregateError_, *"errors"*, PropertyDescriptor { [[Configurable]]: *true*, [[Enumerable]]: *false*, [[Writable]]: *true*, [[Value]]: CreateArrayFromList(_errors_) }).
49489+
1. Return ? Call(_resultCapability_.[[Reject]], *undefined*, « _aggregateError_ »).
49490+
1. Return *undefined*.
49491+
1. Let _onRejected_ be CreateBuiltinFunction(_rejectedSteps_, 1, *""*, « [[AlreadyCalled]], [[Index]] »).
4948249492
1. Set _onRejected_.[[AlreadyCalled]] to *false*.
4948349493
1. Set _onRejected_.[[Index]] to _index_.
49484-
1. Set _onRejected_.[[Errors]] to _errors_.
49485-
1. Set _onRejected_.[[Capability]] to _resultCapability_.
49486-
1. Set _onRejected_.[[RemainingElements]] to _remainingElementsCount_.
49494+
1. Set _index_ to _index_ + 1.
4948749495
1. Set _remainingElementsCount_.[[Value]] to _remainingElementsCount_.[[Value]] + 1.
4948849496
1. Perform ? Invoke(_nextPromise_, *"then"*, « _resultCapability_.[[Resolve]], _onRejected_ »).
49489-
1. Set _index_ to _index_ + 1.
49490-
</emu-alg>
49491-
</emu-clause>
49492-
49493-
<emu-clause id="sec-promise.any-reject-element-functions">
49494-
<h1>`Promise.any` Reject Element Functions</h1>
49495-
<p>A `Promise.any` reject element function is an anonymous built-in function that is used to reject a specific `Promise.any` element. Each `Promise.any` reject element function has [[Index]], [[Errors]], [[Capability]], [[RemainingElements]], and [[AlreadyCalled]] internal slots.</p>
49496-
<p>When a `Promise.any` reject element function is called with argument _x_, the following steps are taken:</p>
49497-
<emu-alg>
49498-
1. Let _F_ be the active function object.
49499-
1. If _F_.[[AlreadyCalled]] is *true*, return *undefined*.
49500-
1. Set _F_.[[AlreadyCalled]] to *true*.
49501-
1. Let _index_ be _F_.[[Index]].
49502-
1. Let _errors_ be _F_.[[Errors]].
49503-
1. Let _promiseCapability_ be _F_.[[Capability]].
49504-
1. Let _remainingElementsCount_ be _F_.[[RemainingElements]].
49505-
1. Set _errors_[_index_] to _x_.
49506-
1. Set _remainingElementsCount_.[[Value]] to _remainingElementsCount_.[[Value]] - 1.
49507-
1. If _remainingElementsCount_.[[Value]] = 0, then
49508-
1. Let _error_ be a newly created *AggregateError* object.
49509-
1. Perform ! DefinePropertyOrThrow(_error_, *"errors"*, PropertyDescriptor { [[Configurable]]: *true*, [[Enumerable]]: *false*, [[Writable]]: *true*, [[Value]]: CreateArrayFromList(_errors_) }).
49510-
1. Return ? Call(_promiseCapability_.[[Reject]], *undefined*, « _error_ »).
49511-
1. Return *undefined*.
4951249497
</emu-alg>
49513-
<p>The *"length"* property of a `Promise.any` reject element function is *1*<sub>𝔽</sub>.</p>
4951449498
</emu-clause>
4951549499
</emu-clause>
4951649500

0 commit comments

Comments
 (0)