mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
LibWeb: Add NamedNodeMap::removeNamedItemNS() method
This patch adds implementation of the missing `removeNamedItemNS()` method.
This commit is contained in:
parent
7679d38c5f
commit
530d5adc62
3 changed files with 33 additions and 1 deletions
|
@ -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);
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
Attr const* get_named_item_ns(StringView namespace_, StringView local_name) const;
|
||||
WebIDL::ExceptionOr<Attr const*> set_named_item(Attr& attribute);
|
||||
WebIDL::ExceptionOr<Attr const*> remove_named_item(StringView qualified_name);
|
||||
WebIDL::ExceptionOr<Attr const*> remove_named_item_ns(StringView namespace_, StringView local_name);
|
||||
|
||||
// Methods defined by the spec for internal use:
|
||||
Attr* get_attribute(StringView qualified_name, size_t* item_index = nullptr);
|
||||
|
@ -49,6 +50,7 @@ public:
|
|||
void replace_attribute(Attr& old_attribute, Attr& new_attribute, size_t old_attribute_index);
|
||||
void append_attribute(Attr& attribute);
|
||||
Attr const* remove_attribute(StringView qualified_name);
|
||||
Attr const* remove_attribute_ns(StringView namespace_, StringView local_name);
|
||||
|
||||
private:
|
||||
explicit NamedNodeMap(Element&);
|
||||
|
|
|
@ -12,5 +12,5 @@ interface NamedNodeMap {
|
|||
// [CEReactions] Attr? setNamedItemNS(Attr attr);
|
||||
|
||||
[CEReactions] Attr removeNamedItem(DOMString qualifiedName);
|
||||
// [CEReactions] Attr removeNamedItemNS(DOMString? namespace, DOMString localName);
|
||||
[CEReactions] Attr removeNamedItemNS(DOMString? namespace, DOMString localName);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue