diff options
author | Alexander Narsudinov <a.narsudinov@gmail.com> | 2022-12-17 17:08:51 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-12-17 18:27:57 +0100 |
commit | 530d5adc62d9383a53d7e888c826affeec270c14 (patch) | |
tree | a05b5310b95e663a3ba30f0498f7a4e8d80a4197 /Userland/Libraries/LibWeb/DOM | |
parent | 7679d38c5f9540cf6e8c5b06c8ed0875f227c41d (diff) | |
download | serenity-530d5adc62d9383a53d7e888c826affeec270c14.zip |
LibWeb: Add NamedNodeMap::removeNamedItemNS() method
This patch adds implementation of the missing `removeNamedItemNS()`
method.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp | 30 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/NamedNodeMap.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/NamedNodeMap.idl | 2 |
3 files changed, 33 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp index 2c64ace03d..f0a4d41a06 100644 --- a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp +++ b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp @@ -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); diff --git a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h index 9e6d25c60c..566a584ebd 100644 --- a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h +++ b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h @@ -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&); diff --git a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.idl b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.idl index 8fa192a842..af50fb2511 100644 --- a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.idl +++ b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.idl @@ -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); }; |