Skip to content

Commit e308730

Browse files
committed
Handle errors
1 parent 97b49c6 commit e308730

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,25 @@ impl<'a> PromiseAll<'a> {
4848
data.remaining_unresolved_promise_count =
4949
data.remaining_unresolved_promise_count.saturating_sub(1);
5050
if data.remaining_unresolved_promise_count == 0 {
51-
let capability = PromiseCapability::from_promise(data.promise, false);
51+
let capability = PromiseCapability::from_promise(data.promise, true);
5252
capability.resolve(agent, result_array.into_value().unbind(), gc);
5353
}
5454
}
5555

56+
pub(crate) fn on_promise_rejected(
57+
self,
58+
agent: &mut Agent,
59+
value: Value<'a>,
60+
gc: NoGcScope<'a, '_>,
61+
) {
62+
let value = value.bind(gc);
63+
let promise_all = self.bind(gc);
64+
let data = promise_all.get_mut(agent);
65+
66+
let capability = PromiseCapability::from_promise(data.promise, true);
67+
capability.reject(agent, value.unbind(), gc);
68+
}
69+
5670
pub(crate) fn get_result_array(self, agent: &Agent, gc: NoGcScope<'a, '_>) -> Array<'a> {
5771
let data = self.get(agent);
5872
data.result_array.bind(gc).unbind()

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,27 +278,32 @@ impl PromiseReactionJob {
278278
);
279279
return Ok(());
280280
}
281-
PromiseReactionType::Reject => {
282-
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « reason »).
283-
// b. Return unused.
284-
(
285-
Err(JsError::new(argument)),
286-
PromiseCapability::from_promise(promise, true),
287-
)
288-
}
281+
PromiseReactionType::Reject => (
282+
Err(JsError::new(argument)),
283+
PromiseCapability::from_promise(promise, true),
284+
),
289285
}
290286
}
291287
PromiseReactionHandler::PromiseAll { promise_all, index } => {
292288
let reaction_type = agent[reaction].reaction_type;
293289
let capability = agent[reaction].capability.clone().unwrap();
290+
let scoped_arg = argument.scope(agent, gc.nogc());
294291
match reaction_type {
295292
PromiseReactionType::Fulfill => {
296-
let arg_unbound = argument.unbind();
297-
promise_all.on_promise_fulfilled(agent, index, arg_unbound, gc.reborrow());
298-
(Ok(arg_unbound.bind(gc.nogc())), capability.bind(gc.nogc()))
293+
promise_all.on_promise_fulfilled(
294+
agent,
295+
index,
296+
scoped_arg.get(agent),
297+
gc.reborrow(),
298+
);
299+
(Ok(scoped_arg.get(agent)), capability.bind(gc.nogc()))
299300
}
300301
PromiseReactionType::Reject => {
301-
(Err(JsError::new(argument)), capability.bind(gc.nogc()))
302+
promise_all.on_promise_rejected(agent, scoped_arg.get(agent), gc.nogc());
303+
(
304+
Err(JsError::new(scoped_arg.get(agent))),
305+
capability.bind(gc.nogc()),
306+
)
302307
}
303308
}
304309
}

nova_vm/src/ecmascript/builtins/control_abstraction_objects/promise_objects/promise_constructor.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,10 @@ impl PromiseConstructor {
293293
index,
294294
promise_all: promise_all_record,
295295
},
296-
PromiseReactionHandler::Empty,
296+
PromiseReactionHandler::PromiseAll {
297+
index,
298+
promise_all: promise_all_record,
299+
},
297300
Some(capability.unbind()),
298301
gc.nogc(),
299302
);

0 commit comments

Comments
 (0)