Skip to content

Commit 6e7ee0d

Browse files
committed
Use take in promise all settled
1 parent 7c0a212 commit 6e7ee0d

File tree

1 file changed

+8
-17
lines changed
  • nova_vm/src/ecmascript/builtins/control_abstraction_objects/promise_objects/promise_abstract_operations

1 file changed

+8
-17
lines changed

nova_vm/src/ecmascript/builtins/control_abstraction_objects/promise_objects/promise_abstract_operations/promise_group_record.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,11 @@ impl<'a> PromiseGroup<'a> {
130130
reaction_type: PromiseReactionType,
131131
index: u32,
132132
value: Value<'a>,
133-
gc: GcScope<'a, '_>,
133+
mut gc: GcScope<'a, '_>,
134134
) {
135-
let promise_all = self.bind(gc.nogc());
135+
let promise_group = self.bind(gc.nogc());
136136
let value = value.bind(gc.nogc());
137137

138-
let result_array = promise_all.get_result_array(agent, gc.nogc());
139-
140138
let obj = match reaction_type {
141139
PromiseReactionType::Fulfill => OrdinaryObject::create_object(
142140
agent,
@@ -179,28 +177,21 @@ impl<'a> PromiseGroup<'a> {
179177
.bind(gc.nogc()),
180178
};
181179

180+
let promise_group_record = promise_group.get_mut(agent);
181+
let (result_array, promise_to_resolve) = promise_group_record.take();
182+
182183
let elements = result_array.as_mut_slice(agent);
183184
elements[index as usize] = Some(obj.unbind().into_value());
184185

185-
let data = promise_all.get_mut(agent);
186-
187-
// 13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
188-
data.remaining_elements_count = data.remaining_elements_count.saturating_sub(1);
189-
190186
// 14. If remainingElementsCount.[[Value]] = 0, then
191-
if data.remaining_elements_count == 0 {
187+
if let Some(promise_to_resolve) = promise_to_resolve {
192188
// a. Let valuesArray be CreateArrayFromList(values).
193189
// b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
194-
let capability = PromiseCapability::from_promise(data.promise, true);
195-
capability.resolve(agent, result_array.into_value().unbind(), gc);
190+
let capability = PromiseCapability::from_promise(promise_to_resolve, true);
191+
capability.resolve(agent, result_array.into_value().unbind(), gc.reborrow());
196192
}
197193
}
198194

199-
pub(crate) fn get_result_array(self, agent: &Agent, gc: NoGcScope<'a, '_>) -> Array<'a> {
200-
let data = self.get(agent);
201-
data.result_array.bind(gc).unbind()
202-
}
203-
204195
pub(crate) const fn get_index(self) -> usize {
205196
self.0.into_index()
206197
}

0 commit comments

Comments
 (0)