@@ -39,32 +39,16 @@ pub struct PromiseGroupRecord<'a> {
3939#[ repr( transparent) ]
4040pub struct PromiseGroup < ' a > ( BaseIndex < ' a , PromiseGroupRecord < ' static > > ) ;
4141
42- impl < ' a > PromiseGroupRecord < ' a > {
43- fn take (
44- & mut self ,
45- agent : & mut Agent ,
46- value : Value < ' a > ,
47- index : u32 ,
48- gc : NoGcScope < ' a , ' _ > ,
49- ) -> Option < ( Promise < ' a > , Array < ' a > ) > {
50- let value = value. bind ( gc) ;
51- let mut self_bound = self . bind ( gc) ;
52-
53- let elements: & mut [ Option < Value < ' static > > ] = self_bound. result_array . as_mut_slice ( agent) ;
54- elements[ index as usize ] = Some ( value. unbind ( ) ) ;
55-
42+ impl < ' a > PromiseGroupRecord < ' static > {
43+ fn take ( & mut self ) -> ( Array < ' a > , Option < Promise < ' a > > ) {
5644 // i. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
57- self_bound . remaining_elements_count = self_bound . remaining_elements_count . saturating_sub ( 1 ) ;
45+ self . remaining_elements_count = self . remaining_elements_count . saturating_sub ( 1 ) ;
5846
59- if self_bound. remaining_elements_count > 0 {
60- return None ;
47+ if self . remaining_elements_count > 0 {
48+ ( self . result_array . unbind ( ) , None )
49+ } else {
50+ ( self . result_array . unbind ( ) , Some ( self . promise . unbind ( ) ) )
6151 }
62-
63- //ii. If remainingElementsCount.[[Value]] = 0, then
64- return Some ( (
65- self_bound. promise . unbind ( ) ,
66- self_bound. result_array . unbind ( ) ,
67- ) ) ;
6852 }
6953}
7054
@@ -108,41 +92,22 @@ impl<'a> PromiseGroup<'a> {
10892 value : Value < ' a > ,
10993 mut gc : GcScope < ' a , ' _ > ,
11094 ) {
111- let promise_all = self . bind ( gc. nogc ( ) ) ;
95+ let promise_group = self . bind ( gc. nogc ( ) ) ;
11296 let value = value. bind ( gc. nogc ( ) ) ;
11397
114- let promise_group_record = promise_all. get_mut ( agent) ;
115- if let Some ( ( promise_to_resolve, result_array) ) =
116- promise_group_record. take ( agent, value. unbind ( ) , index, gc. nogc ( ) )
117- {
118- let promise_to_resolve = promise_to_resolve. bind ( gc. nogc ( ) ) ;
119- let result_array = result_array. bind ( gc. nogc ( ) ) ;
98+ let promise_group_record = promise_group. get_mut ( agent) ;
99+ let ( result_array, promise_to_resolve) = promise_group_record. take ( ) ;
120100
101+ let elements = result_array. as_mut_slice ( agent) ;
102+ elements[ index as usize ] = Some ( value. unbind ( ) ) ;
103+
104+ //ii. If remainingElementsCount.[[Value]] = 0, then
105+ if let Some ( promise_to_resolve) = promise_to_resolve {
121106 // 1. Let valuesArray be CreateArrayFromList(values).
122107 // 2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
123- let capability = PromiseCapability :: from_promise ( promise_to_resolve. unbind ( ) , true ) ;
108+ let capability = PromiseCapability :: from_promise ( promise_to_resolve, true ) ;
124109 capability. resolve ( agent, result_array. into_value ( ) . unbind ( ) , gc. reborrow ( ) ) ;
125110 }
126-
127- // let result_array = promise_all.get_result_array(agent, gc.nogc());
128-
129- // let elements = result_array.as_mut_slice(agent);
130- // elements[index as usize] = Some(value.unbind());
131-
132- // let mut data = promise_all.get_mut(agent).bind(gc.nogc());
133- // data.take_and_resolve(agent, gc.reborrow());
134-
135- // let data = promise_all.get_mut(agent);
136- // // i. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
137- // data.remaining_elements_count = data.remaining_elements_count.saturating_sub(1);
138-
139- // //ii. If remainingElementsCount.[[Value]] = 0, then
140- // if data.remaining_elements_count == 0 {
141- // // 1. Let valuesArray be CreateArrayFromList(values).
142- // // 2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
143- // let capability = PromiseCapability::from_promise(data.promise, true);
144- // capability.resolve(agent, result_array.into_value().unbind(), gc);
145- // }
146111 }
147112
148113 pub ( crate ) fn on_promise_all_rejected (
0 commit comments