From fa1ef30985fe6b8bd19504ec7af8fdafd582ee51 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Wed, 3 Jan 2024 12:47:38 +1300 Subject: [PATCH] LibWeb: Port Element::set_attribute_value from ByteString Also making set_attribute_ns take a String instead of a FlyString as this is only used as an Attr value and no FlyString properties are used. --- Userland/Libraries/LibWeb/DOM/Element.cpp | 10 +++++----- Userland/Libraries/LibWeb/DOM/Element.h | 4 ++-- Userland/Services/WebContent/ConnectionFromClient.cpp | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 230a93616ae..cdb7e4c6b5a 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -224,13 +224,13 @@ WebIDL::ExceptionOr validate_and_extract(JS::Realm& realm, Option } // https://dom.spec.whatwg.org/#dom-element-setattributens -WebIDL::ExceptionOr Element::set_attribute_ns(Optional const& namespace_, FlyString const& qualified_name, FlyString const& value) +WebIDL::ExceptionOr Element::set_attribute_ns(Optional const& namespace_, FlyString const& qualified_name, String const& value) { // 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract. auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_, qualified_name)); // 2. Set an attribute value for this using localName, value, and also prefix and namespace. - set_attribute_value(extracted_qualified_name.local_name(), value.to_deprecated_fly_string(), extracted_qualified_name.prefix(), extracted_qualified_name.namespace_()); + set_attribute_value(extracted_qualified_name.local_name(), value, extracted_qualified_name.prefix(), extracted_qualified_name.namespace_()); return {}; } @@ -242,7 +242,7 @@ void Element::append_attribute(Attr& attribute) } // https://dom.spec.whatwg.org/#concept-element-attributes-set-value -void Element::set_attribute_value(FlyString const& local_name, ByteString const& value, Optional const& prefix, Optional const& namespace_) +void Element::set_attribute_value(FlyString const& local_name, String const& value, Optional const& prefix, Optional const& namespace_) { // 1. Let attribute be the result of getting an attribute given namespace, localName, and element. auto* attribute = m_attributes->get_attribute_ns(namespace_, local_name); @@ -253,14 +253,14 @@ void Element::set_attribute_value(FlyString const& local_name, ByteString const& if (!attribute) { QualifiedName name { local_name, prefix, namespace_ }; - auto new_attribute = Attr::create(document(), move(name), MUST(String::from_byte_string(value))); + auto new_attribute = Attr::create(document(), move(name), value); m_attributes->append_attribute(new_attribute); return; } // 3. Change attribute to value. - attribute->change_attribute(MUST(String::from_byte_string(value))); + attribute->change_attribute(value); } // https://dom.spec.whatwg.org/#dom-element-setattributenode diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 3292054fe1d..7c3a0d963e7 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -104,8 +104,8 @@ public: WebIDL::ExceptionOr set_attribute(FlyString const& name, String const& value); - WebIDL::ExceptionOr set_attribute_ns(Optional const& namespace_, FlyString const& qualified_name, FlyString const& value); - void set_attribute_value(FlyString const& local_name, ByteString const& value, Optional const& prefix = {}, Optional const& namespace_ = {}); + WebIDL::ExceptionOr set_attribute_ns(Optional const& namespace_, FlyString const& qualified_name, String const& value); + void set_attribute_value(FlyString const& local_name, String const& value, Optional const& prefix = {}, Optional const& namespace_ = {}); WebIDL::ExceptionOr> set_attribute_node(Attr&); WebIDL::ExceptionOr> set_attribute_node_ns(Attr&); diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index deb3b2e533d..37fe41a195f 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -659,7 +659,7 @@ void ConnectionFromClient::set_dom_node_tag(i32 node_id, String const& name) auto new_element = Web::DOM::create_element(element.document(), name, element.namespace_uri(), element.prefix(), element.is_value()).release_value_but_fixme_should_propagate_errors(); element.for_each_attribute([&](auto const& attribute) { - new_element->set_attribute_value(attribute.local_name(), attribute.value().to_byte_string(), attribute.prefix(), attribute.namespace_uri()); + new_element->set_attribute_value(attribute.local_name(), attribute.value(), attribute.prefix(), attribute.namespace_uri()); }); while (auto* child_node = element.first_child()) {