mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:17:44 +00:00
LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr
This commit is contained in:
parent
1df3652e27
commit
7c0c1c8f49
214 changed files with 825 additions and 827 deletions
|
@ -18,8 +18,8 @@ CSSGroupingRule::CSSGroupingRule(JS::Realm& realm, CSSRuleList& rules)
|
|||
: CSSRule(realm)
|
||||
, m_rules(rules)
|
||||
{
|
||||
for (auto& rule : m_rules)
|
||||
rule.set_parent_rule(this);
|
||||
for (auto& rule : *m_rules)
|
||||
rule->set_parent_rule(this);
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<void> CSSGroupingRule::initialize(JS::Realm& realm)
|
||||
|
@ -33,32 +33,32 @@ JS::ThrowCompletionOr<void> CSSGroupingRule::initialize(JS::Realm& realm)
|
|||
void CSSGroupingRule::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(&m_rules);
|
||||
visitor.visit(m_rules);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<u32> CSSGroupingRule::insert_rule(StringView rule, u32 index)
|
||||
{
|
||||
TRY(m_rules.insert_a_css_rule(rule, index));
|
||||
TRY(m_rules->insert_a_css_rule(rule, index));
|
||||
// NOTE: The spec doesn't say where to set the parent rule, so we'll do it here.
|
||||
m_rules.item(index)->set_parent_rule(this);
|
||||
m_rules->item(index)->set_parent_rule(this);
|
||||
return index;
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSGroupingRule::delete_rule(u32 index)
|
||||
{
|
||||
return m_rules.remove_a_css_rule(index);
|
||||
return m_rules->remove_a_css_rule(index);
|
||||
}
|
||||
|
||||
void CSSGroupingRule::for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const
|
||||
{
|
||||
m_rules.for_each_effective_style_rule(callback);
|
||||
m_rules->for_each_effective_style_rule(callback);
|
||||
}
|
||||
|
||||
void CSSGroupingRule::set_parent_style_sheet(CSSStyleSheet* parent_style_sheet)
|
||||
{
|
||||
CSSRule::set_parent_style_sheet(parent_style_sheet);
|
||||
for (auto& rule : m_rules)
|
||||
rule.set_parent_style_sheet(parent_style_sheet);
|
||||
for (auto& rule : *m_rules)
|
||||
rule->set_parent_style_sheet(parent_style_sheet);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
|
||||
CSSRuleList const& css_rules() const { return m_rules; }
|
||||
CSSRuleList& css_rules() { return m_rules; }
|
||||
CSSRuleList* css_rules_for_bindings() { return &m_rules; }
|
||||
CSSRuleList* css_rules_for_bindings() { return m_rules; }
|
||||
WebIDL::ExceptionOr<u32> insert_rule(StringView rule, u32 index = 0);
|
||||
WebIDL::ExceptionOr<void> delete_rule(u32 index);
|
||||
|
||||
|
@ -37,7 +37,7 @@ protected:
|
|||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
private:
|
||||
CSSRuleList& m_rules;
|
||||
JS::NonnullGCPtr<CSSRuleList> m_rules;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -34,17 +34,17 @@ JS::ThrowCompletionOr<void> CSSMediaRule::initialize(JS::Realm& realm)
|
|||
void CSSMediaRule::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(&m_media);
|
||||
visitor.visit(m_media);
|
||||
}
|
||||
|
||||
DeprecatedString CSSMediaRule::condition_text() const
|
||||
{
|
||||
return m_media.media_text();
|
||||
return m_media->media_text();
|
||||
}
|
||||
|
||||
void CSSMediaRule::set_condition_text(DeprecatedString text)
|
||||
{
|
||||
m_media.set_media_text(text);
|
||||
m_media->set_media_text(text);
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom-1/#serialize-a-css-rule
|
||||
|
|
|
@ -26,11 +26,11 @@ public:
|
|||
|
||||
virtual DeprecatedString condition_text() const override;
|
||||
virtual void set_condition_text(DeprecatedString) override;
|
||||
virtual bool condition_matches() const override { return m_media.matches(); }
|
||||
virtual bool condition_matches() const override { return m_media->matches(); }
|
||||
|
||||
MediaList* media() const { return &m_media; }
|
||||
MediaList* media() const { return m_media; }
|
||||
|
||||
bool evaluate(HTML::Window const& window) { return m_media.evaluate(window); }
|
||||
bool evaluate(HTML::Window const& window) { return m_media->evaluate(window); }
|
||||
|
||||
private:
|
||||
CSSMediaRule(JS::Realm&, MediaList&, CSSRuleList&);
|
||||
|
@ -39,7 +39,7 @@ private:
|
|||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
virtual DeprecatedString serialized() const override;
|
||||
|
||||
MediaList& m_media;
|
||||
JS::NonnullGCPtr<MediaList> m_media;
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
|
@ -47,7 +47,7 @@ void CSSRuleList::visit_edges(Cell::Visitor& visitor)
|
|||
{
|
||||
Base::visit_edges(visitor);
|
||||
for (auto& rule : m_rules)
|
||||
visitor.visit(&rule);
|
||||
visitor.visit(rule);
|
||||
}
|
||||
|
||||
bool CSSRuleList::is_supported_property_index(u32 index) const
|
||||
|
@ -123,23 +123,23 @@ WebIDL::ExceptionOr<void> CSSRuleList::remove_a_css_rule(u32 index)
|
|||
void CSSRuleList::for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const
|
||||
{
|
||||
for (auto const& rule : m_rules) {
|
||||
switch (rule.type()) {
|
||||
switch (rule->type()) {
|
||||
case CSSRule::Type::FontFace:
|
||||
break;
|
||||
case CSSRule::Type::Import: {
|
||||
auto const& import_rule = static_cast<CSSImportRule const&>(rule);
|
||||
auto const& import_rule = static_cast<CSSImportRule const&>(*rule);
|
||||
if (import_rule.has_import_result() && import_rule.loaded_style_sheet())
|
||||
import_rule.loaded_style_sheet()->for_each_effective_style_rule(callback);
|
||||
break;
|
||||
}
|
||||
case CSSRule::Type::Media:
|
||||
static_cast<CSSMediaRule const&>(rule).for_each_effective_style_rule(callback);
|
||||
static_cast<CSSMediaRule const&>(*rule).for_each_effective_style_rule(callback);
|
||||
break;
|
||||
case CSSRule::Type::Style:
|
||||
callback(static_cast<CSSStyleRule const&>(rule));
|
||||
callback(static_cast<CSSStyleRule const&>(*rule));
|
||||
break;
|
||||
case CSSRule::Type::Supports:
|
||||
static_cast<CSSSupportsRule const&>(rule).for_each_effective_style_rule(callback);
|
||||
static_cast<CSSSupportsRule const&>(*rule).for_each_effective_style_rule(callback);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -150,17 +150,17 @@ bool CSSRuleList::evaluate_media_queries(HTML::Window const& window)
|
|||
bool any_media_queries_changed_match_state = false;
|
||||
|
||||
for (auto& rule : m_rules) {
|
||||
switch (rule.type()) {
|
||||
switch (rule->type()) {
|
||||
case CSSRule::Type::FontFace:
|
||||
break;
|
||||
case CSSRule::Type::Import: {
|
||||
auto& import_rule = verify_cast<CSSImportRule>(rule);
|
||||
auto& import_rule = verify_cast<CSSImportRule>(*rule);
|
||||
if (import_rule.has_import_result() && import_rule.loaded_style_sheet() && import_rule.loaded_style_sheet()->evaluate_media_queries(window))
|
||||
any_media_queries_changed_match_state = true;
|
||||
break;
|
||||
}
|
||||
case CSSRule::Type::Media: {
|
||||
auto& media_rule = verify_cast<CSSMediaRule>(rule);
|
||||
auto& media_rule = verify_cast<CSSMediaRule>(*rule);
|
||||
bool did_match = media_rule.condition_matches();
|
||||
bool now_matches = media_rule.evaluate(window);
|
||||
if (did_match != now_matches)
|
||||
|
@ -172,7 +172,7 @@ bool CSSRuleList::evaluate_media_queries(HTML::Window const& window)
|
|||
case CSSRule::Type::Style:
|
||||
break;
|
||||
case CSSRule::Type::Supports: {
|
||||
auto& supports_rule = verify_cast<CSSSupportsRule>(rule);
|
||||
auto& supports_rule = verify_cast<CSSSupportsRule>(*rule);
|
||||
if (supports_rule.condition_matches() && supports_rule.css_rules().evaluate_media_queries(window))
|
||||
any_media_queries_changed_match_state = true;
|
||||
break;
|
||||
|
|
|
@ -32,26 +32,23 @@ public:
|
|||
{
|
||||
if (index >= length())
|
||||
return nullptr;
|
||||
return &m_rules[index];
|
||||
return m_rules[index];
|
||||
}
|
||||
|
||||
CSSRule* item(size_t index)
|
||||
{
|
||||
if (index >= length())
|
||||
return nullptr;
|
||||
return &m_rules[index];
|
||||
return m_rules[index];
|
||||
}
|
||||
|
||||
size_t length() const { return m_rules.size(); }
|
||||
|
||||
using ConstIterator = AK::SimpleIterator<Vector<CSSRule&> const, CSSRule const>;
|
||||
using Iterator = AK::SimpleIterator<Vector<CSSRule&>, CSSRule>;
|
||||
auto begin() const { return m_rules.begin(); }
|
||||
auto begin() { return m_rules.begin(); }
|
||||
|
||||
ConstIterator const begin() const { return m_rules.begin(); }
|
||||
Iterator begin() { return m_rules.begin(); }
|
||||
|
||||
ConstIterator const end() const { return m_rules.end(); }
|
||||
Iterator end() { return m_rules.end(); }
|
||||
auto end() const { return m_rules.end(); }
|
||||
auto end() { return m_rules.end(); }
|
||||
|
||||
virtual bool is_supported_property_index(u32 index) const override;
|
||||
virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
|
||||
|
@ -82,7 +79,7 @@ private:
|
|||
virtual bool named_property_setter_has_identifier() const override { return false; }
|
||||
virtual bool named_property_deleter_has_identifier() const override { return false; }
|
||||
|
||||
Vector<CSSRule&> m_rules;
|
||||
Vector<JS::NonnullGCPtr<CSSRule>> m_rules;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -35,13 +35,13 @@ JS::ThrowCompletionOr<void> CSSStyleRule::initialize(JS::Realm& realm)
|
|||
void CSSStyleRule::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(&m_declaration);
|
||||
visitor.visit(m_declaration);
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom/#dom-cssstylerule-style
|
||||
CSSStyleDeclaration* CSSStyleRule::style()
|
||||
{
|
||||
return &m_declaration;
|
||||
return m_declaration;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom/#serialize-a-css-rule
|
||||
|
|
|
@ -40,7 +40,7 @@ private:
|
|||
virtual DeprecatedString serialized() const override;
|
||||
|
||||
Vector<NonnullRefPtr<Selector>> m_selectors;
|
||||
CSSStyleDeclaration& m_declaration;
|
||||
JS::NonnullGCPtr<CSSStyleDeclaration> m_declaration;
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
|
@ -27,7 +27,7 @@ CSSStyleSheet::CSSStyleSheet(JS::Realm& realm, CSSRuleList& rules, MediaList& me
|
|||
set_location(location->to_deprecated_string());
|
||||
|
||||
for (auto& rule : *m_rules)
|
||||
rule.set_parent_style_sheet(this);
|
||||
rule->set_parent_style_sheet(this);
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<void> CSSStyleSheet::initialize(JS::Realm& realm)
|
||||
|
@ -106,7 +106,7 @@ WebIDL::ExceptionOr<void> CSSStyleSheet::remove_rule(unsigned index)
|
|||
|
||||
void CSSStyleSheet::for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const
|
||||
{
|
||||
if (m_media.matches()) {
|
||||
if (m_media->matches()) {
|
||||
m_rules->for_each_effective_style_rule(callback);
|
||||
}
|
||||
}
|
||||
|
@ -115,8 +115,8 @@ bool CSSStyleSheet::evaluate_media_queries(HTML::Window const& window)
|
|||
{
|
||||
bool any_media_queries_changed_match_state = false;
|
||||
|
||||
bool did_match = m_media.matches();
|
||||
bool now_matches = m_media.evaluate(window);
|
||||
bool did_match = m_media->matches();
|
||||
bool now_matches = m_media->evaluate(window);
|
||||
if (did_match != now_matches)
|
||||
any_media_queries_changed_match_state = true;
|
||||
if (now_matches && m_rules->evaluate_media_queries(window))
|
||||
|
|
|
@ -54,10 +54,10 @@ private:
|
|||
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
CSSRuleList* m_rules { nullptr };
|
||||
JS::GCPtr<CSSRuleList> m_rules;
|
||||
|
||||
JS::GCPtr<StyleSheetList> m_style_sheet_list;
|
||||
CSSRule* m_owner_css_rule { nullptr };
|
||||
JS::GCPtr<CSSRule> m_owner_css_rule;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ public:
|
|||
JS::Realm& realm() const { return m_realm; }
|
||||
|
||||
private:
|
||||
JS::Realm& m_realm;
|
||||
DOM::Document const* m_document { nullptr };
|
||||
JS::NonnullGCPtr<JS::Realm> m_realm;
|
||||
JS::GCPtr<DOM::Document const> m_document;
|
||||
PropertyID m_current_property_id { PropertyID::Invalid };
|
||||
AK::URL m_url;
|
||||
};
|
||||
|
|
|
@ -136,8 +136,8 @@ static void collect_style_sheets(CSSStyleSheet const& sheet, Vector<JS::NonnullG
|
|||
{
|
||||
sheets.append(sheet);
|
||||
for (auto const& rule : sheet.rules()) {
|
||||
if (rule.type() == CSSRule::Type::Import) {
|
||||
auto const& import_rule = static_cast<CSSImportRule const&>(rule);
|
||||
if (rule->type() == CSSRule::Type::Import) {
|
||||
auto const& import_rule = static_cast<CSSImportRule const&>(*rule);
|
||||
if (auto const* imported_sheet = import_rule.loaded_style_sheet()) {
|
||||
collect_style_sheets(*imported_sheet, sheets);
|
||||
}
|
||||
|
@ -991,7 +991,7 @@ CSSPixels StyleComputer::root_element_font_size() const
|
|||
{
|
||||
constexpr float default_root_element_font_size = 16;
|
||||
|
||||
auto const* root_element = m_document.first_child_of_type<HTML::HTMLHtmlElement>();
|
||||
auto const* root_element = m_document->first_child_of_type<HTML::HTMLHtmlElement>();
|
||||
if (!root_element)
|
||||
return default_root_element_font_size;
|
||||
|
||||
|
@ -1588,9 +1588,9 @@ void StyleComputer::did_load_font([[maybe_unused]] FlyString const& family_name)
|
|||
void StyleComputer::load_fonts_from_sheet(CSSStyleSheet const& sheet)
|
||||
{
|
||||
for (auto const& rule : static_cast<CSSStyleSheet const&>(sheet).rules()) {
|
||||
if (!is<CSSFontFaceRule>(rule))
|
||||
if (!is<CSSFontFaceRule>(*rule))
|
||||
continue;
|
||||
auto const& font_face = static_cast<CSSFontFaceRule const&>(rule).font_face();
|
||||
auto const& font_face = static_cast<CSSFontFaceRule const&>(*rule).font_face();
|
||||
if (font_face.sources().is_empty())
|
||||
continue;
|
||||
if (m_loaded_fonts.contains(font_face.font_family()))
|
||||
|
@ -1620,7 +1620,7 @@ void StyleComputer::load_fonts_from_sheet(CSSStyleSheet const& sheet)
|
|||
continue;
|
||||
|
||||
LoadRequest request;
|
||||
auto url = m_document.parse_url(candidate_url.value().to_deprecated_string());
|
||||
auto url = m_document->parse_url(candidate_url.value().to_deprecated_string());
|
||||
auto loader = make<FontLoader>(const_cast<StyleComputer&>(*this), font_face.font_family(), move(url));
|
||||
const_cast<StyleComputer&>(*this).m_loaded_fonts.set(font_face.font_family().to_string(), move(loader));
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
namespace Web::CSS {
|
||||
|
||||
struct MatchingRule {
|
||||
CSSStyleRule const* rule { nullptr };
|
||||
JS::GCPtr<CSSStyleRule const> rule;
|
||||
size_t style_sheet_index { 0 };
|
||||
size_t rule_index { 0 };
|
||||
size_t selector_index { 0 };
|
||||
|
@ -114,7 +114,7 @@ private:
|
|||
void build_rule_cache();
|
||||
void build_rule_cache_if_needed() const;
|
||||
|
||||
DOM::Document& m_document;
|
||||
JS::NonnullGCPtr<DOM::Document> m_document;
|
||||
|
||||
struct RuleCache {
|
||||
HashMap<FlyString, Vector<MatchingRule>> rules_by_id;
|
||||
|
|
|
@ -36,12 +36,12 @@ public:
|
|||
|
||||
MediaList* media() const
|
||||
{
|
||||
return &m_media;
|
||||
return m_media;
|
||||
}
|
||||
|
||||
void set_media(DeprecatedString media)
|
||||
{
|
||||
m_media.set_media_text(media);
|
||||
m_media->set_media_text(media);
|
||||
}
|
||||
|
||||
bool is_alternate() const { return m_alternate; }
|
||||
|
@ -59,7 +59,7 @@ protected:
|
|||
explicit StyleSheet(JS::Realm&, MediaList& media);
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
MediaList& m_media;
|
||||
JS::NonnullGCPtr<MediaList> m_media;
|
||||
|
||||
private:
|
||||
JS::GCPtr<DOM::Element> m_owner_node;
|
||||
|
|
|
@ -24,9 +24,9 @@ void StyleSheetList::add_sheet(CSSStyleSheet& sheet)
|
|||
return;
|
||||
}
|
||||
|
||||
m_document.style_computer().invalidate_rule_cache();
|
||||
m_document.style_computer().load_fonts_from_sheet(sheet);
|
||||
m_document.invalidate_style();
|
||||
m_document->style_computer().invalidate_rule_cache();
|
||||
m_document->style_computer().load_fonts_from_sheet(sheet);
|
||||
m_document->invalidate_style();
|
||||
}
|
||||
|
||||
void StyleSheetList::remove_sheet(CSSStyleSheet& sheet)
|
||||
|
@ -41,8 +41,8 @@ void StyleSheetList::remove_sheet(CSSStyleSheet& sheet)
|
|||
|
||||
sort_sheets();
|
||||
|
||||
m_document.style_computer().invalidate_rule_cache();
|
||||
m_document.invalidate_style();
|
||||
m_document->style_computer().invalidate_rule_cache();
|
||||
m_document->invalidate_style();
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<StyleSheetList>> StyleSheetList::create(DOM::Document& document)
|
||||
|
|
|
@ -60,7 +60,7 @@ private:
|
|||
|
||||
void sort_sheets();
|
||||
|
||||
DOM::Document& m_document;
|
||||
JS::NonnullGCPtr<DOM::Document> m_document;
|
||||
Vector<JS::NonnullGCPtr<CSSStyleSheet>> m_sheets;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue