1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +00:00

LibWeb: Add NamedNodeMap::removeNamedItemNS() method

This patch adds implementation of the missing `removeNamedItemNS()`
method.
This commit is contained in:
Alexander Narsudinov 2022-12-17 17:08:51 +03:00 committed by Andreas Kling
parent 7679d38c5f
commit 530d5adc62
3 changed files with 33 additions and 1 deletions

View file

@ -106,6 +106,20 @@ WebIDL::ExceptionOr<Attr const*> NamedNodeMap::remove_named_item(StringView qual
return attribute;
}
// https://dom.spec.whatwg.org/#dom-namednodemap-removenameditemns
WebIDL::ExceptionOr<Attr const*> NamedNodeMap::remove_named_item_ns(StringView namespace_, StringView local_name)
{
// 1. Let attr be the result of removing an attribute given namespace, localName, and element.
auto const* attribute = remove_attribute_ns(namespace_, local_name);
// 2. If attr is null, then throw a "NotFoundError" DOMException.
if (!attribute)
return WebIDL::NotFoundError::create(realm(), DeprecatedString::formatted("Attribute with namespace '{}' and local name '{}' not found", namespace_, local_name));
// 3. Return attr.
return attribute;
}
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
Attr* NamedNodeMap::get_attribute(StringView qualified_name, size_t* item_index)
{
@ -257,6 +271,22 @@ Attr const* NamedNodeMap::remove_attribute(StringView qualified_name)
return attribute;
}
// https://dom.spec.whatwg.org/#concept-element-attributes-remove-by-namespace
Attr const* NamedNodeMap::remove_attribute_ns(StringView namespace_, StringView local_name)
{
size_t item_index = 0;
// 1. Let attr be the result of getting an attribute given namespace, localName, and element.
auto const* attribute = get_attribute_ns(namespace_, local_name, &item_index);
// 2. If attr is non-null, then remove attr.
if (attribute)
remove_attribute_at_index(item_index);
// 3. Return attr.
return attribute;
}
JS::Value NamedNodeMap::item_value(size_t index) const
{
auto const* node = item(index);