diff --git a/Libraries/LibWeb/CSS/CSSRuleList.cpp b/Libraries/LibWeb/CSS/CSSRuleList.cpp index 60add66bcfb..4b46b589f19 100644 --- a/Libraries/LibWeb/CSS/CSSRuleList.cpp +++ b/Libraries/LibWeb/CSS/CSSRuleList.cpp @@ -116,7 +116,13 @@ WebIDL::ExceptionOr CSSRuleList::remove_a_css_rule(u32 index) // 3. Set old rule to the indexth item in list. CSSRule& old_rule = m_rules[index]; - // FIXME: 4. If old rule is an @namespace at-rule, and list contains anything other than @import at-rules, and @namespace at-rules, throw an InvalidStateError exception. + // 4. If old rule is an @namespace at-rule, and list contains anything other than @import at-rules, and @namespace at-rules, throw an InvalidStateError exception. + if (old_rule.type() == CSSRule::Type::Namespace) { + for (auto& rule : m_rules) { + if (rule->type() != CSSRule::Type::Import && rule->type() != CSSRule::Type::Namespace) + return WebIDL::InvalidStateError::create(realm(), "Cannot remove @namespace rule from a stylesheet with non-namespace/import rules."_string); + } + } // 5. Remove rule old rule from list at the zero-indexed position index. m_rules.remove(index); diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/cssom/delete-namespace-rule-when-child-rule-exists.txt b/Tests/LibWeb/Text/expected/wpt-import/css/cssom/delete-namespace-rule-when-child-rule-exists.txt new file mode 100644 index 00000000000..eb9347ac152 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/cssom/delete-namespace-rule-when-child-rule-exists.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass Deleting a @namespace rule when list contains anything other than @import or @namespace rules should throw InvalidStateError. \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/css/cssom/delete-namespace-rule-when-child-rule-exists.html b/Tests/LibWeb/Text/input/wpt-import/css/cssom/delete-namespace-rule-when-child-rule-exists.html new file mode 100644 index 00000000000..5e6023d4581 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/cssom/delete-namespace-rule-when-child-rule-exists.html @@ -0,0 +1,16 @@ + +Deleting a @namespace rule when list contains anything other than @import or @namespace rules should throw InvalidStateError. + + + + +