diff --git a/Libraries/LibWeb/CSS/CSSRuleList.cpp b/Libraries/LibWeb/CSS/CSSRuleList.cpp index db4ea6c8a06..54cf230ea05 100644 --- a/Libraries/LibWeb/CSS/CSSRuleList.cpp +++ b/Libraries/LibWeb/CSS/CSSRuleList.cpp @@ -22,11 +22,11 @@ namespace Web::CSS { GC_DEFINE_ALLOCATOR(CSSRuleList); -GC::Ref CSSRuleList::create(JS::Realm& realm, GC::RootVector const& rules) +GC::Ref CSSRuleList::create(JS::Realm& realm, ReadonlySpan> rules) { auto rule_list = realm.create(realm); - for (auto* rule : rules) - rule_list->m_rules.append(*rule); + for (auto rule : rules) + rule_list->m_rules.append(rule); return rule_list; } @@ -36,11 +36,6 @@ CSSRuleList::CSSRuleList(JS::Realm& realm) m_legacy_platform_object_flags = LegacyPlatformObjectFlags { .supports_indexed_properties = 1 }; } -GC::Ref CSSRuleList::create_empty(JS::Realm& realm) -{ - return realm.create(realm); -} - void CSSRuleList::initialize(JS::Realm& realm) { WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSRuleList); diff --git a/Libraries/LibWeb/CSS/CSSRuleList.h b/Libraries/LibWeb/CSS/CSSRuleList.h index b591116b94e..2be543a1294 100644 --- a/Libraries/LibWeb/CSS/CSSRuleList.h +++ b/Libraries/LibWeb/CSS/CSSRuleList.h @@ -23,8 +23,7 @@ class CSSRuleList : public Bindings::PlatformObject { GC_DECLARE_ALLOCATOR(CSSRuleList); public: - [[nodiscard]] static GC::Ref create(JS::Realm&, GC::RootVector const&); - [[nodiscard]] static GC::Ref create_empty(JS::Realm&); + [[nodiscard]] static GC::Ref create(JS::Realm&, ReadonlySpan> = {}); ~CSSRuleList() = default; diff --git a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Libraries/LibWeb/CSS/CSSStyleSheet.cpp index 6e2b61d9e66..eb33f279cfc 100644 --- a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleSheet.cpp @@ -33,7 +33,7 @@ GC::Ref CSSStyleSheet::create(JS::Realm& realm, CSSRuleList& rule WebIDL::ExceptionOr> CSSStyleSheet::construct_impl(JS::Realm& realm, Optional const& options) { // 1. Construct a new CSSStyleSheet object sheet. - auto sheet = create(realm, CSSRuleList::create_empty(realm), CSS::MediaList::create(realm, {}), {}); + auto sheet = create(realm, CSSRuleList::create(realm), CSS::MediaList::create(realm, {}), {}); // 2. Set sheet’s location to the base URL of the associated Document for the current principal global object. auto associated_document = as(HTML::current_principal_global_object()).document(); diff --git a/Libraries/LibWeb/CSS/Parser/Helpers.cpp b/Libraries/LibWeb/CSS/Parser/Helpers.cpp index 79f2fba2924..a407a36e9f3 100644 --- a/Libraries/LibWeb/CSS/Parser/Helpers.cpp +++ b/Libraries/LibWeb/CSS/Parser/Helpers.cpp @@ -45,7 +45,7 @@ GC::Ref internal_css_realm() GC::Ref parse_css_stylesheet(CSS::Parser::ParsingParams const& context, StringView css, Optional<::URL::URL> location, Vector> media_query_list) { if (css.is_empty()) { - auto rule_list = CSS::CSSRuleList::create_empty(*context.realm); + auto rule_list = CSS::CSSRuleList::create(*context.realm); auto media_list = CSS::MediaList::create(*context.realm, {}); auto style_sheet = CSS::CSSStyleSheet::create(*context.realm, rule_list, media_list, location); style_sheet->set_source_text({}); diff --git a/Libraries/LibWeb/CSS/Parser/MediaParsing.cpp b/Libraries/LibWeb/CSS/Parser/MediaParsing.cpp index fcadb1a4864..e446d37693d 100644 --- a/Libraries/LibWeb/CSS/Parser/MediaParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/MediaParsing.cpp @@ -497,12 +497,12 @@ GC::Ptr Parser::convert_to_media_rule(AtRule const& rule, Nested n auto media_query_list = parse_a_media_query_list(media_query_tokens); auto media_list = MediaList::create(realm(), move(media_query_list)); - GC::RootVector child_rules { realm().heap() }; + GC::RootVector> child_rules { realm().heap() }; for (auto const& child : rule.child_rules_and_lists_of_declarations) { child.visit( [&](Rule const& rule) { if (auto child_rule = convert_to_rule(rule, nested)) - child_rules.append(child_rule); + child_rules.append(*child_rule); }, [&](Vector const& declarations) { child_rules.append(CSSNestedDeclarations::create(realm(), *convert_to_style_declaration(declarations))); diff --git a/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Libraries/LibWeb/CSS/Parser/Parser.cpp index 5bad45a46b6..b7d0f0c3077 100644 --- a/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -141,7 +141,7 @@ GC::Ref Parser::parse_as_css_stylesheet(Optional<::URL::URL> auto const& style_sheet = parse_a_stylesheet(m_token_stream, location); // Interpret all of the resulting top-level qualified rules as style rules, defined below. - GC::RootVector rules(realm().heap()); + GC::RootVector> rules(realm().heap()); for (auto const& raw_rule : style_sheet.rules) { auto rule = convert_to_rule(raw_rule, Nested::No); // If any style rule is invalid, or any at-rule is not recognized or is invalid according to its grammar or context, it’s a parse error. @@ -150,7 +150,7 @@ GC::Ref Parser::parse_as_css_stylesheet(Optional<::URL::URL> log_parse_error(); continue; } - rules.append(rule); + rules.append(*rule); } auto rule_list = CSSRuleList::create(realm(), rules); diff --git a/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp b/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp index 060523104be..50c4b8253ae 100644 --- a/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp @@ -107,7 +107,7 @@ GC::Ptr Parser::convert_to_style_rule(QualifiedRule const& qualifi auto declaration = convert_to_style_declaration(qualified_rule.declarations); - GC::RootVector child_rules { realm().heap() }; + GC::RootVector> child_rules { realm().heap() }; for (auto& child : qualified_rule.child_rules) { child.visit( [&](Rule const& rule) { @@ -116,7 +116,7 @@ GC::Ptr Parser::convert_to_style_rule(QualifiedRule const& qualifi // https://drafts.csswg.org/css-nesting-1/#nested-group-rules if (auto converted_rule = convert_to_rule(rule, Nested::Yes)) { if (is(*converted_rule)) { - child_rules.append(converted_rule); + child_rules.append(*converted_rule); } else { dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested {} is not allowed inside style rule; discarding.", converted_rule->class_name()); } @@ -126,7 +126,7 @@ GC::Ptr Parser::convert_to_style_rule(QualifiedRule const& qualifi child_rules.append(CSSNestedDeclarations::create(realm(), *convert_to_style_declaration(declarations))); }); } - auto nested_rules = CSSRuleList::create(realm(), move(child_rules)); + auto nested_rules = CSSRuleList::create(realm(), child_rules); return CSSStyleRule::create(realm(), move(selectors), *declaration, *nested_rules); } @@ -260,12 +260,12 @@ GC::Ptr Parser::convert_to_layer_rule(AtRule const& rule, Nested nested } // Then the rules - GC::RootVector child_rules { realm().heap() }; + GC::RootVector> child_rules { realm().heap() }; for (auto const& child : rule.child_rules_and_lists_of_declarations) { child.visit( [&](Rule const& rule) { if (auto child_rule = convert_to_rule(rule, nested)) - child_rules.append(child_rule); + child_rules.append(*child_rule); }, [&](Vector const& declarations) { child_rules.append(CSSNestedDeclarations::create(realm(), *convert_to_style_declaration(declarations))); @@ -350,7 +350,7 @@ GC::Ptr Parser::convert_to_keyframes_rule(AtRule const& rule) auto name = name_token.to_string(); - GC::RootVector keyframes(realm().heap()); + GC::RootVector> keyframes(realm().heap()); rule.for_each_as_qualified_rule_list([&](auto& qualified_rule) { if (!qualified_rule.child_rules.is_empty()) { dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @keyframes keyframe rule contains at-rules; discarding them."); @@ -405,7 +405,7 @@ GC::Ptr Parser::convert_to_keyframes_rule(AtRule const& rule) } }); - return CSSKeyframesRule::create(realm(), name, CSSRuleList::create(realm(), move(keyframes))); + return CSSKeyframesRule::create(realm(), name, CSSRuleList::create(realm(), keyframes)); } GC::Ptr Parser::convert_to_namespace_rule(AtRule const& rule) @@ -480,12 +480,12 @@ GC::Ptr Parser::convert_to_supports_rule(AtRule const& rule, Ne return {}; } - GC::RootVector child_rules { realm().heap() }; + GC::RootVector> child_rules { realm().heap() }; for (auto const& child : rule.child_rules_and_lists_of_declarations) { child.visit( [&](Rule const& rule) { if (auto child_rule = convert_to_rule(rule, nested)) - child_rules.append(child_rule); + child_rules.append(*child_rule); }, [&](Vector const& declarations) { child_rules.append(CSSNestedDeclarations::create(realm(), *convert_to_style_declaration(declarations)));