From 75133cf733c047b930348d82b72040fa9d4a4833 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Wed, 6 Sep 2023 19:17:17 +1200 Subject: [PATCH] LibWeb: Port NamedNodeMap from DeprecatedString to String The conversion which is required here is unfortunately quite ugly, but in the spirit of making forwards progress, just leave a FIXME for our future selves to deal with. --- Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp | 18 ++++++++++++++---- Userland/Libraries/LibWeb/DOM/NamedNodeMap.h | 4 ++-- Userland/Libraries/LibWeb/DOM/NamedNodeMap.idl | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp index cb15e840dc..6c0a2a798d 100644 --- a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp +++ b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp @@ -87,9 +87,14 @@ Attr const* NamedNodeMap::get_named_item(StringView qualified_name) const } // https://dom.spec.whatwg.org/#dom-namednodemap-getnameditemns -Attr const* NamedNodeMap::get_named_item_ns(StringView namespace_, StringView local_name) const +Attr const* NamedNodeMap::get_named_item_ns(Optional const& namespace_, StringView local_name) const { - return get_attribute_ns(namespace_, local_name); + // FIXME: This conversion is quite ugly. + StringView namespace_view; + if (namespace_.has_value()) + namespace_view = namespace_->bytes_as_string_view(); + + return get_attribute_ns(namespace_view, local_name); } // https://dom.spec.whatwg.org/#dom-namednodemap-setnameditem @@ -119,10 +124,15 @@ WebIDL::ExceptionOr NamedNodeMap::remove_named_item(StringView qual } // https://dom.spec.whatwg.org/#dom-namednodemap-removenameditemns -WebIDL::ExceptionOr NamedNodeMap::remove_named_item_ns(StringView namespace_, StringView local_name) +WebIDL::ExceptionOr NamedNodeMap::remove_named_item_ns(Optional const& namespace_, StringView local_name) { + // FIXME: This conversion is quite ugly. + StringView namespace_view; + if (namespace_.has_value()) + namespace_view = namespace_->bytes_as_string_view(); + // 1. Let attr be the result of removing an attribute given namespace, localName, and element. - auto const* attribute = remove_attribute_ns(namespace_, local_name); + auto const* attribute = remove_attribute_ns(namespace_view, local_name); // 2. If attr is null, then throw a "NotFoundError" DOMException. if (!attribute) diff --git a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h index 7a7e46d21e..cd26b10425 100644 --- a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h +++ b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h @@ -36,11 +36,11 @@ public: // Methods defined by the spec for JavaScript: Attr const* item(u32 index) const; Attr const* get_named_item(StringView qualified_name) const; - Attr const* get_named_item_ns(StringView namespace_, StringView local_name) const; + Attr const* get_named_item_ns(Optional const& namespace_, StringView local_name) const; WebIDL::ExceptionOr> set_named_item(Attr& attribute); WebIDL::ExceptionOr> set_named_item_ns(Attr& attribute); WebIDL::ExceptionOr remove_named_item(StringView qualified_name); - WebIDL::ExceptionOr remove_named_item_ns(StringView namespace_, StringView local_name); + WebIDL::ExceptionOr remove_named_item_ns(Optional const& namespace_, StringView local_name); // Methods defined by the spec for internal use: Attr* get_attribute(StringView qualified_name, size_t* item_index = nullptr); diff --git a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.idl b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.idl index 2bfdadcf5d..cf52b16552 100644 --- a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.idl +++ b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.idl @@ -1,6 +1,6 @@ #import -[Exposed=Window, LegacyUnenumerableNamedProperties, UseDeprecatedAKString] +[Exposed=Window, LegacyUnenumerableNamedProperties] interface NamedNodeMap { readonly attribute unsigned long length;