Skip to content

Commit 297b697

Browse files
committed
Fix warns
1 parent 0c18b48 commit 297b697

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

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

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
promise_objects::promise_abstract_operations::promise_capability_records::PromiseCapability,
1212
},
1313
execution::Agent,
14-
types::Value,
14+
types::{IntoValue, Value},
1515
},
1616
engine::context::{Bindable, GcScope, NoGcScope},
1717
heap::{
@@ -23,6 +23,7 @@ use crate::{
2323
pub struct PromiseAllRecordHeapData<'a> {
2424
pub remaining_unresolved_promise_count: u32,
2525
pub result_array: Array<'a>,
26+
pub promise: Promise<'a>,
2627
}
2728

2829
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
@@ -35,12 +36,11 @@ impl<'a> PromiseAllRecordHeapData<'a> {
3536
agent: &mut Agent,
3637
index: u32,
3738
value: Value<'a>,
38-
gc: NoGcScope<'a, '_>,
39+
mut gc: GcScope<'a, '_>,
3940
) {
40-
eprintln!("Self memory address: {:p}", &self);
41-
// Update the result array at the specified index by reconstructing it
41+
value.bind(gc.nogc());
4242
let array_slice = self.result_array.as_slice(agent);
43-
let new_values: Vec<Value> = array_slice
43+
array_slice
4444
.iter()
4545
.enumerate()
4646
.map(|(i, opt_val)| {
@@ -50,26 +50,20 @@ impl<'a> PromiseAllRecordHeapData<'a> {
5050
opt_val.unwrap_or(Value::Undefined) // Keep existing or default
5151
}
5252
})
53-
.collect();
53+
.collect::<Vec<_>>();
5454

55-
eprintln!("Index: {:#?}", index);
56-
eprintln!("New values: {:#?}", new_values);
57-
eprintln!(
58-
"Remaining unresolved promise count: {:#?}",
59-
self.remaining_unresolved_promise_count
60-
);
61-
62-
self.result_array = Array::from_slice(agent, &new_values, gc);
63-
eprintln!("Result array memory address: {:p}", &self.result_array);
55+
// Update in place to avoid consuming the GC scope
56+
let elements = self.result_array.as_mut_slice(agent);
57+
elements[index as usize] = Some(value.unbind());
6458

6559
self.remaining_unresolved_promise_count -= 1;
6660
if self.remaining_unresolved_promise_count == 0 {
67-
eprintln!(
68-
"All promises fulfilled, should resolve main promise: {:#?}",
69-
self.result_array
61+
let capability = PromiseCapability::from_promise(self.promise, true);
62+
capability.resolve(
63+
agent,
64+
self.result_array.unbind().into_value(),
65+
gc.reborrow(),
7066
);
71-
// self.promise_capability
72-
// .resolve(agent, self.result_array, gc.into_nogc());
7367
}
7468
}
7569
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,12 @@ impl PromiseReactionJob {
304304

305305
// Bind to current scope and mutate
306306
let mut rec_bound = rec.unbind().bind(gc.nogc());
307-
rec_bound.on_promise_fufilled(agent, index, argument.unbind(), gc.nogc());
307+
rec_bound.on_promise_fufilled(
308+
agent,
309+
index,
310+
argument.clone(),
311+
gc.reborrow(),
312+
);
308313

309314
// Write back with 'static lifetime
310315
agent

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use core::ops::{Index, IndexMut};
77
use crate::{
88
ecmascript::{
99
builtins::{
10-
Array, async_generator_objects::AsyncGenerator,
10+
async_generator_objects::AsyncGenerator,
1111
control_abstraction_objects::async_function_objects::await_reaction::AwaitReaction,
1212
promise::Promise,
1313
promise_objects::promise_abstract_operations::promise_all_record::PromiseAllRecord,

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
use crate::ecmascript::abstract_operations::operations_on_objects::create_array_from_list;
6-
use crate::ecmascript::builtins::promise_objects::promise_abstract_operations::promise_all_record::{PromiseAllRecordHeapData, PromiseAllRecord};
5+
use crate::ecmascript::builtins::promise_objects::promise_abstract_operations::promise_all_record::PromiseAllRecordHeapData;
76
use crate::ecmascript::builtins::promise_objects::promise_abstract_operations::promise_reaction_records::PromiseReactionHandler;
87
use crate::ecmascript::builtins::promise_objects::promise_prototype::inner_promise_then;
9-
use crate::ecmascript::builtins::{create_builtin_function, Array, BuiltinFunctionArgs};
10-
use crate::ecmascript::fundamental_objects::function_objects::function_constructor::create_dynamic_function;
8+
use crate::ecmascript::builtins::Array;
119
use crate::{
1210
ecmascript::{
1311
abstract_operations::{
@@ -287,9 +285,12 @@ impl PromiseConstructor {
287285
};
288286

289287
let result_capability = PromiseCapability::new(agent, gc.nogc());
290-
291288
let second_capability = PromiseCapability::new(agent, gc.nogc());
292-
let result_promise = result_capability.promise();
289+
290+
let result_promise = PromiseCapability::new(agent, gc.nogc())
291+
.promise()
292+
.unbind()
293+
.bind(gc.nogc());
293294

294295
// let result_callback_closure: for<'a, 'b, 'c, 'd, 'e, '_gc> fn(
295296
// &'a mut Agent,
@@ -329,6 +330,7 @@ impl PromiseConstructor {
329330
let promise_all_record = agent.heap.create(PromiseAllRecordHeapData {
330331
remaining_unresolved_promise_count: 2,
331332
result_array,
333+
promise: result_promise,
332334
});
333335

334336
inner_promise_then(

0 commit comments

Comments
 (0)