LibWeb/CSS: Return GC::Ref from Parser::convert_to_style_declaration()

This commit is contained in:
Sam Atkins 2025-03-18 13:41:46 +00:00
parent a28197669a
commit 9b06f66571
Notes: github-actions[bot] 2025-03-19 13:54:06 +00:00
4 changed files with 7 additions and 31 deletions

View file

@ -505,12 +505,7 @@ GC::Ptr<CSSMediaRule> Parser::convert_to_media_rule(AtRule const& rule, Nested n
child_rules.append(child_rule);
},
[&](Vector<Declaration> const& declarations) {
auto* declaration = convert_to_style_declaration(declarations);
if (!declaration) {
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding.");
return;
}
child_rules.append(CSSNestedDeclarations::create(realm(), *declaration));
child_rules.append(CSSNestedDeclarations::create(realm(), *convert_to_style_declaration(declarations)));
});
}
auto rule_list = CSSRuleList::create(realm(), child_rules);

View file

@ -1493,7 +1493,7 @@ void Parser::extract_property(Declaration const& declaration, PropertiesAndCusto
}
}
CSSStyleProperties* Parser::convert_to_style_declaration(Vector<Declaration> const& declarations)
GC::Ref<CSSStyleProperties> Parser::convert_to_style_declaration(Vector<Declaration> const& declarations)
{
PropertiesAndCustomProperties properties;
PropertiesAndCustomProperties& dest = properties;

View file

@ -245,7 +245,7 @@ private:
GC::Ptr<CSSSupportsRule> convert_to_supports_rule(AtRule const&, Nested);
GC::Ptr<CSSPropertyRule> convert_to_property_rule(AtRule const& rule);
CSSStyleProperties* convert_to_style_declaration(Vector<Declaration> const&);
GC::Ref<CSSStyleProperties> convert_to_style_declaration(Vector<Declaration> const&);
Optional<StyleProperty> convert_to_style_property(Declaration const&);
Optional<Dimension> parse_dimension(ComponentValue const&);

View file

@ -103,11 +103,7 @@ GC::Ptr<CSSStyleRule> Parser::convert_to_style_rule(QualifiedRule const& qualifi
if (nested == Nested::Yes)
selectors = adapt_nested_relative_selector_list(selectors);
auto* declaration = convert_to_style_declaration(qualified_rule.declarations);
if (!declaration) {
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: style rule declaration invalid; discarding.");
return {};
}
auto declaration = convert_to_style_declaration(qualified_rule.declarations);
GC::RootVector<CSSRule*> child_rules { realm().heap() };
for (auto& child : qualified_rule.child_rules) {
@ -125,12 +121,7 @@ GC::Ptr<CSSStyleRule> Parser::convert_to_style_rule(QualifiedRule const& qualifi
}
},
[&](Vector<Declaration> const& declarations) {
auto* declaration = convert_to_style_declaration(declarations);
if (!declaration) {
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding.");
return;
}
child_rules.append(CSSNestedDeclarations::create(realm(), *declaration));
child_rules.append(CSSNestedDeclarations::create(realm(), *convert_to_style_declaration(declarations)));
});
}
auto nested_rules = CSSRuleList::create(realm(), move(child_rules));
@ -256,12 +247,7 @@ GC::Ptr<CSSRule> Parser::convert_to_layer_rule(AtRule const& rule, Nested nested
child_rules.append(child_rule);
},
[&](Vector<Declaration> const& declarations) {
auto* declaration = convert_to_style_declaration(declarations);
if (!declaration) {
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding.");
return;
}
child_rules.append(CSSNestedDeclarations::create(realm(), *declaration));
child_rules.append(CSSNestedDeclarations::create(realm(), *convert_to_style_declaration(declarations)));
});
}
auto rule_list = CSSRuleList::create(realm(), child_rules);
@ -478,12 +464,7 @@ GC::Ptr<CSSSupportsRule> Parser::convert_to_supports_rule(AtRule const& rule, Ne
child_rules.append(child_rule);
},
[&](Vector<Declaration> const& declarations) {
auto* declaration = convert_to_style_declaration(declarations);
if (!declaration) {
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding.");
return;
}
child_rules.append(CSSNestedDeclarations::create(realm(), *declaration));
child_rules.append(CSSNestedDeclarations::create(realm(), *convert_to_style_declaration(declarations)));
});
}