diff --git a/Libraries/LibJS/Runtime/IndexedProperties.h b/Libraries/LibJS/Runtime/IndexedProperties.h index cba20878d5..3509e81689 100644 --- a/Libraries/LibJS/Runtime/IndexedProperties.h +++ b/Libraries/LibJS/Runtime/IndexedProperties.h @@ -169,6 +169,20 @@ public: Vector values_unordered() const; + template + void for_each_value(Callback callback) + { + if (m_storage->is_simple_storage()) { + for (auto& value : static_cast(*m_storage).elements()) + callback(value); + } else { + for (auto& element : static_cast(*m_storage).packed_elements()) + callback(element.value); + for (auto& element : static_cast(*m_storage).sparse_elements()) + callback(element.value.value); + } + } + private: void switch_to_generic_storage(); diff --git a/Libraries/LibJS/Runtime/Object.cpp b/Libraries/LibJS/Runtime/Object.cpp index 012ea4a0c2..d5e9976fb0 100644 --- a/Libraries/LibJS/Runtime/Object.cpp +++ b/Libraries/LibJS/Runtime/Object.cpp @@ -818,8 +818,9 @@ void Object::visit_edges(Cell::Visitor& visitor) for (auto& value : m_storage) visitor.visit(value); - for (auto& value : m_indexed_properties.values_unordered()) - visitor.visit(value.value); + m_indexed_properties.for_each_value([&visitor](auto& value) { + visitor.visit(value); + }); } bool Object::has_property(const PropertyName& property_name) const