Skip to content

Commit 1e222c1

Browse files
committed
Updated promise all settled record
1 parent 9d27359 commit 1e222c1

File tree

2 files changed

+76
-12
lines changed

2 files changed

+76
-12
lines changed

nova_vm/src/builtin_strings

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ fromCharCode
150150
fromCodePoint
151151
fromEntries
152152
#[cfg(feature = "math")]fround
153+
fulfilled
153154
function
154155
Function
155156
Generator
@@ -320,6 +321,7 @@ race
320321
#[cfg(feature = "math")]random
321322
RangeError
322323
raw
324+
reason
323325
reduce
324326
reduceRight
325327
ReferenceError
@@ -328,6 +330,7 @@ Reflect
328330
#[cfg(feature = "regexp")]RegExp String Iterator
329331
register
330332
reject
333+
rejected
331334
repeat
332335
replace
333336
replaceAll
@@ -389,6 +392,7 @@ split
389392
#[cfg(feature = "math")]SQRT1_2
390393
#[cfg(feature = "math")]SQRT2
391394
startsWith
395+
status
392396
#[cfg(feature = "regexp")]sticky
393397
#[cfg(feature = "atomics")]store
394398
#[cfg(feature = "annex-b-string")]strike

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

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ use crate::{
99
promise_objects::promise_abstract_operations::promise_capability_records::PromiseCapability,
1010
},
1111
execution::Agent,
12-
types::{IntoValue, Value},
12+
types::{BUILTIN_STRING_MEMORY, IntoValue, OrdinaryObject, Value},
1313
},
1414
engine::{
1515
context::{Bindable, GcScope, NoGcScope, bindable_handle},
1616
rootable::{HeapRootData, HeapRootRef, Rootable},
1717
},
1818
heap::{
19-
CompactionLists, CreateHeapData, Heap, HeapMarkAndSweep, WorkQueues, indexes::BaseIndex,
19+
CompactionLists, CreateHeapData, Heap, HeapMarkAndSweep, ObjectEntry, WorkQueues,
20+
indexes::BaseIndex,
2021
},
2122
};
2223

@@ -44,18 +45,40 @@ impl<'a> PromiseAllSettled<'a> {
4445

4546
let result_array = promise_all.get_result_array(agent, gc.nogc());
4647

48+
// Let obj be OrdinaryObjectCreate(%Object.prototype%).
49+
// 10. Perform ! CreateDataPropertyOrThrow(obj, "status", "fulfilled").
50+
// 11. Perform ! CreateDataPropertyOrThrow(obj, "value", x).
51+
let obj = OrdinaryObject::create_object(
52+
agent,
53+
Some(
54+
agent
55+
.current_realm_record()
56+
.intrinsics()
57+
.object_prototype()
58+
.into(),
59+
),
60+
&[
61+
ObjectEntry::new_data_entry(
62+
BUILTIN_STRING_MEMORY.status.into(),
63+
BUILTIN_STRING_MEMORY.fulfilled.into(),
64+
),
65+
ObjectEntry::new_data_entry(BUILTIN_STRING_MEMORY.value.into(), value.unbind()),
66+
],
67+
)
68+
.bind(gc.nogc());
69+
4770
let elements = result_array.as_mut_slice(agent);
48-
elements[index as usize] = Some(value.unbind());
71+
elements[index as usize] = Some(obj.unbind().into_value());
4972

5073
let data = promise_all.get_mut(agent);
5174

52-
// i. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
75+
// 13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
5376
data.remaining_elements_count = data.remaining_elements_count.saturating_sub(1);
5477

55-
//ii. If remainingElementsCount.[[Value]] = 0, then
78+
// 14. If remainingElementsCount.[[Value]] = 0, then
5679
if data.remaining_elements_count == 0 {
57-
// 1. Let valuesArray be CreateArrayFromList(values).
58-
// 2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
80+
// a. Let valuesArray be CreateArrayFromList(values).
81+
// b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
5982
let capability = PromiseCapability::from_promise(data.promise, true);
6083
capability.resolve(agent, result_array.into_value().unbind(), gc);
6184
}
@@ -64,15 +87,52 @@ impl<'a> PromiseAllSettled<'a> {
6487
pub(crate) fn on_promise_rejected(
6588
self,
6689
agent: &mut Agent,
90+
index: u32,
6791
value: Value<'a>,
68-
gc: NoGcScope<'a, '_>,
92+
gc: GcScope<'a, '_>,
6993
) {
70-
let value = value.bind(gc);
71-
let promise_all = self.bind(gc);
94+
let promise_all = self.bind(gc.nogc());
95+
let value = value.bind(gc.nogc());
96+
97+
let result_array = promise_all.get_result_array(agent, gc.nogc());
98+
99+
// Let obj be OrdinaryObjectCreate(%Object.prototype%).
100+
// 10. Perform ! CreateDataPropertyOrThrow(obj, "status", "rejected").
101+
// 11. Perform ! CreateDataPropertyOrThrow(obj, "reason", x).
102+
let obj = OrdinaryObject::create_object(
103+
agent,
104+
Some(
105+
agent
106+
.current_realm_record()
107+
.intrinsics()
108+
.object_prototype()
109+
.into(),
110+
),
111+
&[
112+
ObjectEntry::new_data_entry(
113+
BUILTIN_STRING_MEMORY.status.into(),
114+
BUILTIN_STRING_MEMORY.rejected.into(),
115+
),
116+
ObjectEntry::new_data_entry(BUILTIN_STRING_MEMORY.reason.into(), value.unbind()),
117+
],
118+
)
119+
.bind(gc.nogc());
120+
121+
let elements = result_array.as_mut_slice(agent);
122+
elements[index as usize] = Some(obj.unbind().into_value());
123+
72124
let data = promise_all.get_mut(agent);
73125

74-
let capability = PromiseCapability::from_promise(data.promise, true);
75-
capability.reject(agent, value.unbind(), gc);
126+
// 13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
127+
data.remaining_elements_count = data.remaining_elements_count.saturating_sub(1);
128+
129+
// 14. If remainingElementsCount.[[Value]] = 0, then
130+
if data.remaining_elements_count == 0 {
131+
// a. Let valuesArray be CreateArrayFromList(values).
132+
// b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
133+
let capability = PromiseCapability::from_promise(data.promise, true);
134+
capability.resolve(agent, result_array.into_value().unbind(), gc);
135+
}
76136
}
77137

78138
pub(crate) fn get_result_array(self, agent: &Agent, gc: NoGcScope<'a, '_>) -> Array<'a> {

0 commit comments

Comments
 (0)