From bd0bf7838349b4a88960fb8845a6190fdc786d57 Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Fri, 1 Jul 2022 14:34:34 +0000 Subject: [PATCH] Fix remaining `Promise` bugs (#2156) This Pull Request changes the following: - Fix `Promise.then` length to 2. - Fix `all`, `allSettled` and `any` element lists to actually be shared between closures. - Fix `allSettled` reject element function to call resolve instead of reject. The remaining failing tests for `Promise` fail because of some errors in the arrow function parsing. --- boa_engine/src/builtins/promise/mod.rs | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/boa_engine/src/builtins/promise/mod.rs b/boa_engine/src/builtins/promise/mod.rs index 9d93344c3b..1acacec930 100644 --- a/boa_engine/src/builtins/promise/mod.rs +++ b/boa_engine/src/builtins/promise/mod.rs @@ -230,7 +230,7 @@ impl BuiltIn for Promise { None, Attribute::CONFIGURABLE, ) - .method(Self::then, "then", 1) + .method(Self::then, "then", 2) .method(Self::catch, "catch", 1) .method(Self::finally, "finally", 1) // @@ -399,14 +399,14 @@ impl Promise { #[unsafe_ignore_trace] already_called: Rc>, index: usize, - values: GcCell>, + values: Gc>>, capability_resolve: JsFunction, #[unsafe_ignore_trace] remaining_elements_count: Rc>, } // 1. Let values be a new empty List. - let values = GcCell::new(Vec::new()); + let values = Gc::new(GcCell::new(Vec::new())); // 2. Let remainingElementsCount be the Record { [[Value]]: 1 }. let remaining_elements_count = Rc::new(Cell::new(1)); @@ -439,7 +439,7 @@ impl Promise { if remaining_elements_count.get() == 0 { // 1. Let valuesArray be CreateArrayFromList(values). let values_array = crate::builtins::Array::create_array_from_list( - values.into_inner(), + values.borrow().iter().cloned(), context, ); @@ -517,7 +517,7 @@ impl Promise { if captures.remaining_elements_count.get() == 0 { // a. Let valuesArray be CreateArrayFromList(values). let values_array = crate::builtins::Array::create_array_from_list( - captures.values.clone().into_inner(), + captures.values.borrow().as_slice().iter().cloned(), context, ); @@ -640,14 +640,14 @@ impl Promise { #[unsafe_ignore_trace] already_called: Rc>, index: usize, - values: GcCell>, + values: Gc>>, capability: JsFunction, #[unsafe_ignore_trace] remaining_elements: Rc>, } // 1. Let values be a new empty List. - let values = GcCell::new(Vec::new()); + let values = Gc::new(GcCell::new(Vec::new())); // 2. Let remainingElementsCount be the Record { [[Value]]: 1 }. let remaining_elements_count = Rc::new(Cell::new(1)); @@ -680,7 +680,7 @@ impl Promise { if remaining_elements_count.get() == 0 { // 1. Let valuesArray be CreateArrayFromList(values). let values_array = crate::builtins::Array::create_array_from_list( - values.into_inner(), + values.borrow().as_slice().iter().cloned(), context, ); @@ -772,7 +772,7 @@ impl Promise { if captures.remaining_elements.get() == 0 { // a. Let valuesArray be CreateArrayFromList(values). let values_array = Array::create_array_from_list( - captures.values.clone().into_inner(), + captures.values.borrow().as_slice().iter().cloned(), context, ); @@ -852,7 +852,7 @@ impl Promise { if captures.remaining_elements.get() == 0 { // a. Let valuesArray be CreateArrayFromList(values). let values_array = Array::create_array_from_list( - captures.values.clone().into_inner(), + captures.values.borrow().as_slice().iter().cloned(), context, ); @@ -871,7 +871,7 @@ impl Promise { already_called: Rc::new(Cell::new(false)), index, values: values.clone(), - capability: result_capability.reject.clone(), + capability: result_capability.resolve.clone(), remaining_elements: remaining_elements_count.clone(), }, ) @@ -971,14 +971,14 @@ impl Promise { #[unsafe_ignore_trace] already_called: Rc>, index: usize, - errors: GcCell>, + errors: Gc>>, capability_reject: JsFunction, #[unsafe_ignore_trace] remaining_elements_count: Rc>, } // 1. Let errors be a new empty List. - let errors = GcCell::new(Vec::new()); + let errors = Gc::new(GcCell::new(Vec::new())); // 2. Let remainingElementsCount be the Record { [[Value]]: 1 }. let remaining_elements_count = Rc::new(Cell::new(1)); @@ -1028,7 +1028,7 @@ impl Promise { .enumerable(false) .writable(true) .value(Array::create_array_from_list( - errors.into_inner(), + errors.borrow().as_slice().iter().cloned(), context, )), context, @@ -1123,7 +1123,7 @@ impl Promise { .enumerable(false) .writable(true) .value(Array::create_array_from_list( - captures.errors.clone().into_inner(), + captures.errors.borrow().as_slice().iter().cloned(), context, )), context,