@@ -9,14 +9,15 @@ use crate::{
9
9
promise_objects:: promise_abstract_operations:: promise_capability_records:: PromiseCapability ,
10
10
} ,
11
11
execution:: Agent ,
12
- types:: { IntoValue , Value } ,
12
+ types:: { BUILTIN_STRING_MEMORY , IntoValue , OrdinaryObject , Value } ,
13
13
} ,
14
14
engine:: {
15
15
context:: { Bindable , GcScope , NoGcScope , bindable_handle} ,
16
16
rootable:: { HeapRootData , HeapRootRef , Rootable } ,
17
17
} ,
18
18
heap:: {
19
- CompactionLists , CreateHeapData , Heap , HeapMarkAndSweep , WorkQueues , indexes:: BaseIndex ,
19
+ CompactionLists , CreateHeapData , Heap , HeapMarkAndSweep , ObjectEntry , WorkQueues ,
20
+ indexes:: BaseIndex ,
20
21
} ,
21
22
} ;
22
23
@@ -44,18 +45,40 @@ impl<'a> PromiseAllSettled<'a> {
44
45
45
46
let result_array = promise_all. get_result_array ( agent, gc. nogc ( ) ) ;
46
47
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
+
47
70
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 ( ) ) ;
49
72
50
73
let data = promise_all. get_mut ( agent) ;
51
74
52
- // i . Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
75
+ // 13 . Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
53
76
data. remaining_elements_count = data. remaining_elements_count . saturating_sub ( 1 ) ;
54
77
55
- //ii . If remainingElementsCount.[[Value]] = 0, then
78
+ // 14 . If remainingElementsCount.[[Value]] = 0, then
56
79
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 »).
59
82
let capability = PromiseCapability :: from_promise ( data. promise , true ) ;
60
83
capability. resolve ( agent, result_array. into_value ( ) . unbind ( ) , gc) ;
61
84
}
@@ -64,15 +87,52 @@ impl<'a> PromiseAllSettled<'a> {
64
87
pub ( crate ) fn on_promise_rejected (
65
88
self ,
66
89
agent : & mut Agent ,
90
+ index : u32 ,
67
91
value : Value < ' a > ,
68
- gc : NoGcScope < ' a , ' _ > ,
92
+ gc : GcScope < ' a , ' _ > ,
69
93
) {
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
+
72
124
let data = promise_all. get_mut ( agent) ;
73
125
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
+ }
76
136
}
77
137
78
138
pub ( crate ) fn get_result_array ( self , agent : & Agent , gc : NoGcScope < ' a , ' _ > ) -> Array < ' a > {
0 commit comments