mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-01 14:42:05 +00:00
LibWeb/CSS: Give all style values a visit_edges() method
Having this hidden away in ImageStyleValue meant that CSSStyleProperties (and anyone else who holds style values) had to know exactly which types need visiting. This is a footgun waiting to happen, so make this a virtual method on CSSStyleValue instead.
This commit is contained in:
parent
c4bb74f40b
commit
a2c89f585f
Notes:
github-actions[bot]
2025-03-27 11:54:20 +00:00
Author: https://github.com/AtkinsSJ
Commit: a2c89f585f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4106
4 changed files with 9 additions and 3 deletions
|
@ -85,8 +85,7 @@ void CSSStyleProperties::visit_edges(Visitor& visitor)
|
||||||
{
|
{
|
||||||
Base::visit_edges(visitor);
|
Base::visit_edges(visitor);
|
||||||
for (auto& property : m_properties) {
|
for (auto& property : m_properties) {
|
||||||
if (property.value->is_image())
|
property.value->visit_edges(visitor);
|
||||||
property.value->as_image().visit_edges(visitor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <AK/WeakPtr.h>
|
#include <AK/WeakPtr.h>
|
||||||
#include <LibGfx/Color.h>
|
#include <LibGfx/Color.h>
|
||||||
|
#include <LibJS/Heap/Cell.h>
|
||||||
#include <LibURL/URL.h>
|
#include <LibURL/URL.h>
|
||||||
#include <LibWeb/CSS/Keyword.h>
|
#include <LibWeb/CSS/Keyword.h>
|
||||||
#include <LibWeb/CSS/Length.h>
|
#include <LibWeb/CSS/Length.h>
|
||||||
|
@ -369,6 +370,8 @@ public:
|
||||||
[[nodiscard]] int to_font_slope() const;
|
[[nodiscard]] int to_font_slope() const;
|
||||||
[[nodiscard]] int to_font_width() const;
|
[[nodiscard]] int to_font_width() const;
|
||||||
|
|
||||||
|
virtual void visit_edges(JS::Cell::Visitor&) const { }
|
||||||
|
|
||||||
virtual bool equals(CSSStyleValue const& other) const = 0;
|
virtual bool equals(CSSStyleValue const& other) const = 0;
|
||||||
|
|
||||||
bool operator==(CSSStyleValue const& other) const
|
bool operator==(CSSStyleValue const& other) const
|
||||||
|
|
|
@ -30,6 +30,7 @@ ImageStyleValue::~ImageStyleValue() = default;
|
||||||
|
|
||||||
void ImageStyleValue::visit_edges(JS::Cell::Visitor& visitor) const
|
void ImageStyleValue::visit_edges(JS::Cell::Visitor& visitor) const
|
||||||
{
|
{
|
||||||
|
Base::visit_edges(visitor);
|
||||||
// FIXME: visit_edges in non-GC allocated classes is confusing pattern.
|
// FIXME: visit_edges in non-GC allocated classes is confusing pattern.
|
||||||
// Consider making CSSStyleValue to be GC allocated instead.
|
// Consider making CSSStyleValue to be GC allocated instead.
|
||||||
visitor.visit(m_resource_request);
|
visitor.visit(m_resource_request);
|
||||||
|
|
|
@ -21,6 +21,9 @@ namespace Web::CSS {
|
||||||
class ImageStyleValue final
|
class ImageStyleValue final
|
||||||
: public AbstractImageStyleValue
|
: public AbstractImageStyleValue
|
||||||
, public Weakable<ImageStyleValue> {
|
, public Weakable<ImageStyleValue> {
|
||||||
|
|
||||||
|
using Base = AbstractImageStyleValue;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static ValueComparingNonnullRefPtr<ImageStyleValue> create(URL::URL const& url)
|
static ValueComparingNonnullRefPtr<ImageStyleValue> create(URL::URL const& url)
|
||||||
{
|
{
|
||||||
|
@ -28,7 +31,7 @@ public:
|
||||||
}
|
}
|
||||||
virtual ~ImageStyleValue() override;
|
virtual ~ImageStyleValue() override;
|
||||||
|
|
||||||
void visit_edges(JS::Cell::Visitor& visitor) const;
|
virtual void visit_edges(JS::Cell::Visitor& visitor) const override;
|
||||||
|
|
||||||
virtual String to_string(SerializationMode) const override;
|
virtual String to_string(SerializationMode) const override;
|
||||||
virtual bool equals(CSSStyleValue const& other) const override;
|
virtual bool equals(CSSStyleValue const& other) const override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue