LibWeb: Implement Element.removeAttributeNode()

This commit is contained in:
Andreas Kling
2024-04-14 15:49:48 +02:00
parent f13bda60ba
commit 20bdda7f02
7 changed files with 43 additions and 1 deletions

View File

@@ -342,4 +342,19 @@ WebIDL::ExceptionOr<JS::Value> NamedNodeMap::named_item_value(FlyString const& n
return node;
}
// https://dom.spec.whatwg.org/#dom-element-removeattributenode
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> NamedNodeMap::remove_attribute_node(JS::NonnullGCPtr<Attr> attr)
{
// 1. If thiss attribute list does not contain attr, then throw a "NotFoundError" DOMException.
auto index = m_attributes.find_first_index(attr);
if (!index.has_value())
return WebIDL::NotFoundError::create(realm(), "Attribute not found"_fly_string);
// 2. Remove attr.
remove_attribute_at_index(index.value());
// 3. Return attr.
return attr;
}
}