Skip to content

Commit 2764704

Browse files
authored
Merge pull request #30 from tc39/do-not-capture-per-loop-values
2 parents eb84db1 + 7ff8dd5 commit 2764704

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

spec.emu

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,40 +92,48 @@ contributors: Alexander J. Vincent, Ashley Claymore, Chris de Almeida, Jordan Ha
9292
1. Append *undefined* to _values_.
9393
1. Let _nextPromise_ be ? Call(_promiseResolve_, _constructor_, « _value_ »).
9494
1. Let _alreadyCalled_ be the Record { [[Value]]: *false* }.
95-
1. Let _onFulfilled_ be a new Abstract Closure with parameters (_x_) that captures _variant_, _alreadyCalled_, _index_, _keys_, _values_, _resultCapability_, and _remainingElementsCount_ and performs the following steps when called:
96-
1. If _alreadyCalled_.[[Value]] is *true*, return *undefined*.
97-
1. Set _alreadyCalled_.[[Value]] to *true*.
95+
1. Let _onFulfilledSteps_ be a new Abstract Closure with parameters (_x_) that captures _variant_, _keys_, _values_, _resultCapability_, and _remainingElementsCount_ and performs the following steps when called:
96+
1. Let _F_ be the active function object.
97+
1. If _F_.[[AlreadyCalled]].[[Value]] is *true*, return *undefined*.
98+
1. Set _F_.[[AlreadyCalled]].[[Value]] to *true*.
99+
1. Let _thisIndex_ be _F_.[[Index]].
98100
1. If _variant_ is ~all~, then
99-
1. Set _values_[_index_] to _x_.
101+
1. Set _values_[_thisIndex_] to _x_.
100102
1. Else,
101103
1. Assert: _variant_ is ~all-settled~.
102104
1. Let _obj_ be OrdinaryObjectCreate(%Object.prototype%).
103105
1. Perform ! CreateDataPropertyOrThrow(_obj_, *"status"*, *"fulfilled"*).
104106
1. Perform ! CreateDataPropertyOrThrow(_obj_, *"value"*, _x_).
105-
1. Set _values_[_index_] to _obj_.
107+
1. Set _values_[_thisIndex_] to _obj_.
106108
1. Set _remainingElementsCount_.[[Value]] to _remainingElementsCount_.[[Value]] - 1.
107109
1. If _remainingElementsCount_.[[Value]] = 0, then
108110
1. Let _result_ be CreateKeyedPromiseCombinatorResultObject(_keys_, _values_).
109111
1. Return ? Call(_resultCapability_.[[Resolve]], *undefined*, « _result_ »).
110112
1. Return *undefined*.
111-
1. Set _onFulfilled_.[[Length]] to 1.
113+
1. Let _onFulfilled_ be CreateBuiltinFunction(_onFulfilledSteps_, 1, *""*, « [[AlreadyCalled]], [[Index]] »).
114+
1. Set _onFulfilled_.[[AlreadyCalled]] to _alreadyCalled_.
115+
1. Set _onFulfilled_.[[Index]] to _index_.
112116
1. If _variant_ is ~all~, then
113117
1. Let _onRejected_ be _resultCapability_.[[Reject]].
114118
1. Else,
115119
1. Assert: _variant_ is ~all-settled~.
116-
1. Let _onRejected_ be a new Abstract Closure with parameters (_x_) that captures _alreadyCalled_, _index_, _keys_, _values_, _resultCapability_, and _remainingElementsCount_ and performs the following steps when called:
117-
1. If _alreadyCalled_.[[Value]] is *true*, return *undefined*.
118-
1. Set _alreadyCalled_.[[Value]] to *true*.
120+
1. Let _onRejectedSteps_ be a new Abstract Closure with parameters (_x_) that captures _keys_, _values_, _resultCapability_, and _remainingElementsCount_ and performs the following steps when called:
121+
1. Let _F_ be the active function object.
122+
1. If _F_.[[AlreadyCalled]].[[Value]] is *true*, return *undefined*.
123+
1. Set _F_.[[AlreadyCalled]].[[Value]] to *true*.
124+
1. Let _thisIndex_ be _F_.[[Index]].
119125
1. Let _obj_ be OrdinaryObjectCreate(%Object.prototype%).
120126
1. Perform ! CreateDataPropertyOrThrow(_obj_, *"status"*, *"rejected"*).
121127
1. Perform ! CreateDataPropertyOrThrow(_obj_, *"reason"*, _x_).
122-
1. Set _values_[_index_] to _obj_.
128+
1. Set _values_[_thisIndex_] to _obj_.
123129
1. Set _remainingElementsCount_.[[Value]] to _remainingElementsCount_.[[Value]] - 1.
124130
1. If _remainingElementsCount_.[[Value]] = 0, then
125131
1. Let _result_ be CreateKeyedPromiseCombinatorResultObject(_keys_, _values_).
126132
1. Return ? Call(_resultCapability_.[[Resolve]], *undefined*, « _result_ »).
127133
1. Return *undefined*.
128-
1. Set _onRejected_.[[Length]] to 1.
134+
1. Let _onRejected_ be CreateBuiltinFunction(_onRejectedSteps_, 1, *""*, « [[AlreadyCalled]], [[Index]] »).
135+
1. Set _onRejected_.[[AlreadyCalled]] to _alreadyCalled_.
136+
1. Set _onRejected_.[[Index]] to _index_.
129137
1. Set _remainingElementsCount_.[[Value]] to _remainingElementsCount_.[[Value]] + 1.
130138
1. Perform ? Invoke(_nextPromise_, *"then"*, « _onFulfilled_, _onRejected_ »).
131139
1. Set _index_ to _index_ + 1.

0 commit comments

Comments
 (0)