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.
This commit is contained in:
Shannon Booth 2023-09-06 19:17:17 +12:00 committed by Andrew Kaster
parent f5efe9bb63
commit 75133cf733
Notes: sideshowbarker 2024-07-17 03:35:24 +09:00
3 changed files with 17 additions and 7 deletions

View File

@ -87,9 +87,14 @@ Attr const* NamedNodeMap::get_named_item(StringView qualified_name) const
} }
// https://dom.spec.whatwg.org/#dom-namednodemap-getnameditemns // 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<String> 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 // https://dom.spec.whatwg.org/#dom-namednodemap-setnameditem
@ -119,10 +124,15 @@ WebIDL::ExceptionOr<Attr const*> NamedNodeMap::remove_named_item(StringView qual
} }
// https://dom.spec.whatwg.org/#dom-namednodemap-removenameditemns // https://dom.spec.whatwg.org/#dom-namednodemap-removenameditemns
WebIDL::ExceptionOr<Attr const*> NamedNodeMap::remove_named_item_ns(StringView namespace_, StringView local_name) WebIDL::ExceptionOr<Attr const*> NamedNodeMap::remove_named_item_ns(Optional<String> 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. // 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. // 2. If attr is null, then throw a "NotFoundError" DOMException.
if (!attribute) if (!attribute)

View File

@ -36,11 +36,11 @@ public:
// Methods defined by the spec for JavaScript: // Methods defined by the spec for JavaScript:
Attr const* item(u32 index) const; Attr const* item(u32 index) const;
Attr const* get_named_item(StringView qualified_name) 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<String> const& namespace_, StringView local_name) const;
WebIDL::ExceptionOr<JS::GCPtr<Attr>> set_named_item(Attr& attribute); WebIDL::ExceptionOr<JS::GCPtr<Attr>> set_named_item(Attr& attribute);
WebIDL::ExceptionOr<JS::GCPtr<Attr>> set_named_item_ns(Attr& attribute); WebIDL::ExceptionOr<JS::GCPtr<Attr>> set_named_item_ns(Attr& attribute);
WebIDL::ExceptionOr<Attr const*> remove_named_item(StringView qualified_name); WebIDL::ExceptionOr<Attr const*> remove_named_item(StringView qualified_name);
WebIDL::ExceptionOr<Attr const*> remove_named_item_ns(StringView namespace_, StringView local_name); WebIDL::ExceptionOr<Attr const*> remove_named_item_ns(Optional<String> const& namespace_, StringView local_name);
// Methods defined by the spec for internal use: // Methods defined by the spec for internal use:
Attr* get_attribute(StringView qualified_name, size_t* item_index = nullptr); Attr* get_attribute(StringView qualified_name, size_t* item_index = nullptr);

View File

@ -1,6 +1,6 @@
#import <DOM/Attr.idl> #import <DOM/Attr.idl>
[Exposed=Window, LegacyUnenumerableNamedProperties, UseDeprecatedAKString] [Exposed=Window, LegacyUnenumerableNamedProperties]
interface NamedNodeMap { interface NamedNodeMap {
readonly attribute unsigned long length; readonly attribute unsigned long length;