Skip to content

Commit 0c18b48

Browse files
committed
Mutate heap data
1 parent 11a9777 commit 0c18b48

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
execution::Agent,
1414
types::Value,
1515
},
16-
engine::context::{Bindable, NoGcScope},
16+
engine::context::{Bindable, GcScope, NoGcScope},
1717
heap::{
1818
CompactionLists, CreateHeapData, Heap, HeapMarkAndSweep, WorkQueues, indexes::BaseIndex,
1919
},
@@ -37,6 +37,7 @@ impl<'a> PromiseAllRecordHeapData<'a> {
3737
value: Value<'a>,
3838
gc: NoGcScope<'a, '_>,
3939
) {
40+
eprintln!("Self memory address: {:p}", &self);
4041
// Update the result array at the specified index by reconstructing it
4142
let array_slice = self.result_array.as_slice(agent);
4243
let new_values: Vec<Value> = array_slice
@@ -51,9 +52,15 @@ impl<'a> PromiseAllRecordHeapData<'a> {
5152
})
5253
.collect();
5354

55+
eprintln!("Index: {:#?}", index);
5456
eprintln!("New values: {:#?}", new_values);
57+
eprintln!(
58+
"Remaining unresolved promise count: {:#?}",
59+
self.remaining_unresolved_promise_count
60+
);
5561

5662
self.result_array = Array::from_slice(agent, &new_values, gc);
63+
eprintln!("Result array memory address: {:p}", &self.result_array);
5764

5865
self.remaining_unresolved_promise_count -= 1;
5966
if self.remaining_unresolved_promise_count == 0 {

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,27 @@ impl PromiseReactionJob {
292292
let capability = agent[reaction].capability.clone().unwrap().bind(gc.nogc());
293293
match agent[reaction].reaction_type {
294294
PromiseReactionType::Fulfill => {
295-
let mut promise_all_record = agent.heap.promise_all_records[promise_all];
296-
promise_all_record.on_promise_fufilled(agent, index, argument, gc.nogc());
295+
// Take out the record to drop the vec borrow before we use `agent`/`gc`
296+
let rec = {
297+
let slot = agent
298+
.heap
299+
.promise_all_records
300+
.get_mut(promise_all.get_index())
301+
.expect("PromiseAllRecord out of bounds");
302+
slot.take().expect("PromiseAllRecord slot empty")
303+
};
304+
305+
// Bind to current scope and mutate
306+
let mut rec_bound = rec.unbind().bind(gc.nogc());
307+
rec_bound.on_promise_fufilled(agent, index, argument.unbind(), gc.nogc());
308+
309+
// Write back with 'static lifetime
310+
agent
311+
.heap
312+
.promise_all_records
313+
.get_mut(promise_all.get_index())
314+
.unwrap()
315+
.replace(rec_bound.unbind());
297316

298317
(Ok(argument), capability)
299318
}

0 commit comments

Comments
 (0)