Skip to content

Commit 11a9777

Browse files
committed
Minor changes
1 parent 48f95ea commit 11a9777

File tree

2 files changed

+40
-18
lines changed

2 files changed

+40
-18
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@ pub struct PromiseAllRecordHeapData<'a> {
3030
pub struct PromiseAllRecord<'a>(pub(crate) BaseIndex<'a, PromiseAllRecordHeapData<'a>>);
3131

3232
impl<'a> PromiseAllRecordHeapData<'a> {
33-
pub(crate) fn new(agent: &mut Agent, num_promises: u32, gc: NoGcScope<'a, '_>) -> Self {
34-
let undefined_values = vec![Value::Undefined; num_promises as usize];
35-
let result_array = Array::from_slice(agent, &undefined_values, gc);
36-
Self {
37-
remaining_unresolved_promise_count: num_promises,
38-
result_array,
39-
}
40-
}
41-
4233
pub(crate) fn on_promise_fufilled(
4334
&mut self,
4435
agent: &mut Agent,
@@ -60,6 +51,8 @@ impl<'a> PromiseAllRecordHeapData<'a> {
6051
})
6152
.collect();
6253

54+
eprintln!("New values: {:#?}", new_values);
55+
6356
self.result_array = Array::from_slice(agent, &new_values, gc);
6457

6558
self.remaining_unresolved_promise_count -= 1;
@@ -68,6 +61,8 @@ impl<'a> PromiseAllRecordHeapData<'a> {
6861
"All promises fulfilled, should resolve main promise: {:#?}",
6962
self.result_array
7063
);
64+
// self.promise_capability
65+
// .resolve(agent, self.result_array, gc.into_nogc());
7166
}
7267
}
7368
}

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

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,24 @@ impl PromiseConstructor {
271271
));
272272
};
273273

274+
let Some(second_element) = array_slice[1] else {
275+
return Err(agent.throw_exception_with_static_message(
276+
ExceptionType::TypeError,
277+
"Second element is None",
278+
gc.into_nogc(),
279+
));
280+
};
281+
let Value::Promise(second_promise) = second_element.unbind() else {
282+
return Err(agent.throw_exception_with_static_message(
283+
ExceptionType::TypeError,
284+
"Second element is not a Promise",
285+
gc.into_nogc(),
286+
));
287+
};
288+
274289
let result_capability = PromiseCapability::new(agent, gc.nogc());
290+
291+
let second_capability = PromiseCapability::new(agent, gc.nogc());
275292
let result_promise = result_capability.promise();
276293

277294
// let result_callback_closure: for<'a, 'b, 'c, 'd, 'e, '_gc> fn(
@@ -307,27 +324,37 @@ impl PromiseConstructor {
307324
// gc.nogc(),
308325
// );
309326

310-
let args: [Value<'gc>; 1] = [Value::Undefined; 1];
311-
let result_array = Array::from_slice(agent, &args, gc.nogc());
327+
let undefined_values = vec![Value::Undefined; 2];
328+
let result_array = Array::from_slice(agent, &undefined_values, gc.nogc());
312329
let promise_all_record = agent.heap.create(PromiseAllRecordHeapData {
313-
remaining_unresolved_promise_count: 1,
330+
remaining_unresolved_promise_count: 2,
314331
result_array,
315332
});
316333

317-
let promise_all_handler = PromiseReactionHandler::PromiseAll {
318-
index: 0,
319-
promise_all: promise_all_record,
320-
};
321-
322334
inner_promise_then(
323335
agent,
324336
promise_to_await,
325-
promise_all_handler,
337+
PromiseReactionHandler::PromiseAll {
338+
index: 0,
339+
promise_all: promise_all_record,
340+
},
326341
PromiseReactionHandler::Empty,
327342
Some(result_capability),
328343
gc.nogc(),
329344
);
330345

346+
inner_promise_then(
347+
agent,
348+
second_promise,
349+
PromiseReactionHandler::PromiseAll {
350+
index: 1,
351+
promise_all: promise_all_record,
352+
},
353+
PromiseReactionHandler::Empty,
354+
Some(second_capability),
355+
gc.nogc(),
356+
);
357+
331358
Ok(result_promise.unbind().into_value())
332359
}
333360

0 commit comments

Comments
 (0)