mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:48:11 +00:00
LibJS: Don't use MarkedValueList in PromiseValueList
Instead, override visit_edges() and mark the values like any other Cell subclass would. This makes PromiseValueList play nice with zombification.
This commit is contained in:
parent
2253235a0f
commit
971dc44ed3
3 changed files with 19 additions and 15 deletions
|
@ -111,7 +111,7 @@ static Value perform_promise_common(GlobalObject& global_object, Object& iterato
|
|||
return {};
|
||||
}
|
||||
|
||||
values->values.append(js_undefined());
|
||||
values->values().append(js_undefined());
|
||||
|
||||
auto next_promise = vm.call(promise_resolve.as_function(), constructor, next_value);
|
||||
if (vm.exception())
|
||||
|
@ -135,7 +135,7 @@ static Value perform_promise_all(GlobalObject& global_object, Object& iterator_r
|
|||
return perform_promise_common(
|
||||
global_object, iterator_record, constructor, result_capability, promise_resolve,
|
||||
[&](PromiseValueList& values) -> Value {
|
||||
auto values_array = Array::create_from(global_object, values.values);
|
||||
auto values_array = Array::create_from(global_object, values.values());
|
||||
|
||||
(void)vm.call(*result_capability.resolve, js_undefined(), values_array);
|
||||
if (vm.exception())
|
||||
|
@ -159,7 +159,7 @@ static Value perform_promise_all_settled(GlobalObject& global_object, Object& it
|
|||
return perform_promise_common(
|
||||
global_object, iterator_record, constructor, result_capability, promise_resolve,
|
||||
[&](PromiseValueList& values) -> Value {
|
||||
auto values_array = Array::create_from(global_object, values.values);
|
||||
auto values_array = Array::create_from(global_object, values.values());
|
||||
|
||||
(void)vm.call(*result_capability.resolve, js_undefined(), values_array);
|
||||
if (vm.exception())
|
||||
|
@ -186,7 +186,7 @@ static Value perform_promise_any(GlobalObject& global_object, Object& iterator_r
|
|||
return perform_promise_common(
|
||||
global_object, iterator_record, constructor, result_capability, promise_resolve,
|
||||
[&](PromiseValueList& errors) -> Value {
|
||||
auto errors_array = Array::create_from(global_object, errors.values);
|
||||
auto errors_array = Array::create_from(global_object, errors.values());
|
||||
|
||||
auto* error = AggregateError::create(global_object);
|
||||
error->define_property_or_throw(vm.names.errors, { .value = errors_array, .writable = true, .enumerable = false, .configurable = true });
|
||||
|
|
|
@ -63,10 +63,10 @@ Value PromiseAllResolveElementFunction::resolve_element()
|
|||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
|
||||
m_values.values[m_index] = vm.argument(0);
|
||||
m_values.values()[m_index] = vm.argument(0);
|
||||
|
||||
if (--m_remaining_elements.value == 0) {
|
||||
auto values_array = Array::create_from(global_object, m_values.values);
|
||||
auto values_array = Array::create_from(global_object, m_values.values());
|
||||
return vm.call(*m_capability.resolve, js_undefined(), values_array);
|
||||
}
|
||||
|
||||
|
@ -92,10 +92,10 @@ Value PromiseAllSettledResolveElementFunction::resolve_element()
|
|||
object->create_data_property_or_throw(vm.names.status, js_string(vm, "fulfilled"sv));
|
||||
object->create_data_property_or_throw(vm.names.value, vm.argument(0));
|
||||
|
||||
m_values.values[m_index] = object;
|
||||
m_values.values()[m_index] = object;
|
||||
|
||||
if (--m_remaining_elements.value == 0) {
|
||||
auto values_array = Array::create_from(global_object, m_values.values);
|
||||
auto values_array = Array::create_from(global_object, m_values.values());
|
||||
return vm.call(*m_capability.resolve, js_undefined(), values_array);
|
||||
}
|
||||
|
||||
|
@ -121,10 +121,10 @@ Value PromiseAllSettledRejectElementFunction::resolve_element()
|
|||
object->create_data_property_or_throw(vm.names.status, js_string(vm, "rejected"sv));
|
||||
object->create_data_property_or_throw(vm.names.reason, vm.argument(0));
|
||||
|
||||
m_values.values[m_index] = object;
|
||||
m_values.values()[m_index] = object;
|
||||
|
||||
if (--m_remaining_elements.value == 0) {
|
||||
auto values_array = Array::create_from(global_object, m_values.values);
|
||||
auto values_array = Array::create_from(global_object, m_values.values());
|
||||
return vm.call(*m_capability.resolve, js_undefined(), values_array);
|
||||
}
|
||||
|
||||
|
@ -146,10 +146,10 @@ Value PromiseAnyRejectElementFunction::resolve_element()
|
|||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
|
||||
m_values.values[m_index] = vm.argument(0);
|
||||
m_values.values()[m_index] = vm.argument(0);
|
||||
|
||||
if (--m_remaining_elements.value == 0) {
|
||||
auto errors_array = Array::create_from(global_object, m_values.values);
|
||||
auto errors_array = Array::create_from(global_object, m_values.values());
|
||||
|
||||
auto* error = AggregateError::create(global_object);
|
||||
error->define_property_or_throw(vm.names.errors, { .value = errors_array, .writable = true, .enumerable = false, .configurable = true });
|
||||
|
|
|
@ -24,15 +24,19 @@ struct RemainingElements final : public Cell {
|
|||
u64 value { 0 };
|
||||
};
|
||||
|
||||
struct PromiseValueList final : public Cell {
|
||||
class PromiseValueList final : public Cell {
|
||||
public:
|
||||
PromiseValueList()
|
||||
: values(heap())
|
||||
{
|
||||
}
|
||||
|
||||
Vector<Value>& values() { return m_values; }
|
||||
Vector<Value> const& values() const { return m_values; }
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "PromiseValueList"; }
|
||||
|
||||
MarkedValueList values;
|
||||
Vector<Value> m_values;
|
||||
};
|
||||
|
||||
class PromiseResolvingElementFunction : public NativeFunction {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue