1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:17:46 +00:00

LibWeb: Port supported property names from DeprecatedString to String

This commit is contained in:
Shannon Booth 2023-11-21 07:39:58 +13:00 committed by Tim Flynn
parent 66ac0d88a3
commit 629f661e3b
19 changed files with 59 additions and 59 deletions

View file

@ -99,29 +99,28 @@ Element* HTMLCollection::named_item(FlyString const& name_) const
}
// https://dom.spec.whatwg.org/#ref-for-dfn-supported-property-names
Vector<DeprecatedString> HTMLCollection::supported_property_names() const
Vector<String> HTMLCollection::supported_property_names() const
{
// 1. Let result be an empty list.
Vector<DeprecatedString> result;
Vector<String> result;
// 2. For each element represented by the collection, in tree order:
auto elements = collect_matching_elements();
for (auto& element : elements) {
// 1. If element has an ID which is not in result, append elements ID to result.
if (element->has_attribute(HTML::AttributeNames::id)) {
auto id = element->deprecated_attribute(HTML::AttributeNames::id);
if (!result.contains_slow(id))
result.append(id);
if (auto maybe_id = element->attribute(HTML::AttributeNames::id); maybe_id.has_value()) {
if (!result.contains_slow(maybe_id.value()))
result.append(maybe_id.release_value());
}
// 2. If element is in the HTML namespace and has a name attribute whose value is neither the empty string nor is in result, append elements name attribute value to result.
if (element->namespace_uri() == Namespace::HTML && element->has_attribute(HTML::AttributeNames::name)) {
auto name = element->deprecated_attribute(HTML::AttributeNames::name);
if (!name.is_empty() && !result.contains_slow(name))
result.append(name);
if (element->namespace_uri() == Namespace::HTML) {
if (auto maybe_name = element->attribute(HTML::AttributeNames::name); maybe_name.has_value()) {
auto name = maybe_name.release_value();
if (!name.is_empty() && !result.contains_slow(name))
result.append(move(name));
}
}
}

View file

@ -46,7 +46,7 @@ public:
virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
virtual WebIDL::ExceptionOr<JS::Value> named_item_value(FlyString const& name) const override;
virtual Vector<DeprecatedString> supported_property_names() const override;
virtual Vector<String> supported_property_names() const override;
virtual bool is_supported_property_index(u32) const override;
protected:

View file

@ -9,6 +9,7 @@
#include <LibWeb/DOM/Attr.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/NamedNodeMap.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/Namespace.h>
namespace Web::DOM {
@ -48,16 +49,16 @@ bool NamedNodeMap::is_supported_property_index(u32 index) const
}
// https://dom.spec.whatwg.org/#ref-for-dfn-supported-property-names%E2%91%A0
Vector<DeprecatedString> NamedNodeMap::supported_property_names() const
Vector<String> NamedNodeMap::supported_property_names() const
{
// 1. Let names be the qualified names of the attributes in this NamedNodeMap objects attribute list, with duplicates omitted, in order.
Vector<DeprecatedString> names;
Vector<String> names;
names.ensure_capacity(m_attributes.size());
for (auto const& attribute : m_attributes) {
auto const attribute_name = attribute->name().to_deprecated_fly_string();
auto const attribute_name = attribute->name();
if (!names.contains_slow(attribute_name))
names.append(attribute_name);
names.append(attribute_name.to_string());
}
// 2. If this NamedNodeMap objects element is in the HTML namespace and its node document is an HTML document, then for each name in names:
@ -65,7 +66,7 @@ Vector<DeprecatedString> NamedNodeMap::supported_property_names() const
if (associated_element().namespace_uri() == Namespace::HTML) {
// 1. Let lowercaseName be name, in ASCII lowercase.
// 2. If lowercaseName is not equal to name, remove name from names.
names.remove_all_matching([](auto const& name) { return name != name.to_lowercase(); });
names.remove_all_matching([](auto const& name) { return name != MUST(Infra::to_ascii_lowercase(name)); });
}
// 3. Return names.

View file

@ -27,7 +27,7 @@ public:
~NamedNodeMap() = default;
virtual bool is_supported_property_index(u32 index) const override;
virtual Vector<DeprecatedString> supported_property_names() const override;
virtual Vector<String> supported_property_names() const override;
virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
virtual WebIDL::ExceptionOr<JS::Value> named_item_value(FlyString const& name) const override;