summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-11 22:16:30 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-11 22:16:30 +0200
commit971dc44ed3e4a324a9cd94dbabb807cce2cd1cc7 (patch)
treea8b58690fbe1c7079401e4f87d81112b23028886 /Userland/Libraries/LibJS/Runtime
parent2253235a0ffffd4d4f5699e7360e027c68084647 (diff)
downloadserenity-971dc44ed3e4a324a9cd94dbabb807cce2cd1cc7.zip
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.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp16
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.h10
3 files changed, 19 insertions, 15 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
index 0905f034e8..e605e8f9da 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
@@ -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 });
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp
index 94f9b4d348..22019a1eb2 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp
@@ -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 });
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.h b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.h
index cd0d339f74..40579c0b02 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.h
+++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.h
@@ -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 {