mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
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.
This commit is contained in:
parent
285bca1633
commit
fa1ef30985
Notes:
sideshowbarker
2024-07-17 23:00:03 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/fa1ef30985 Pull-request: https://github.com/SerenityOS/serenity/pull/22539
3 changed files with 8 additions and 8 deletions
|
@ -224,13 +224,13 @@ WebIDL::ExceptionOr<QualifiedName> validate_and_extract(JS::Realm& realm, Option
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-setattributens
|
||||
WebIDL::ExceptionOr<void> Element::set_attribute_ns(Optional<FlyString> const& namespace_, FlyString const& qualified_name, FlyString const& value)
|
||||
WebIDL::ExceptionOr<void> Element::set_attribute_ns(Optional<FlyString> 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<FlyString> const& prefix, Optional<FlyString> const& namespace_)
|
||||
void Element::set_attribute_value(FlyString const& local_name, String const& value, Optional<FlyString> const& prefix, Optional<FlyString> 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
|
||||
|
|
|
@ -104,8 +104,8 @@ public:
|
|||
|
||||
WebIDL::ExceptionOr<void> set_attribute(FlyString const& name, String const& value);
|
||||
|
||||
WebIDL::ExceptionOr<void> set_attribute_ns(Optional<FlyString> const& namespace_, FlyString const& qualified_name, FlyString const& value);
|
||||
void set_attribute_value(FlyString const& local_name, ByteString const& value, Optional<FlyString> const& prefix = {}, Optional<FlyString> const& namespace_ = {});
|
||||
WebIDL::ExceptionOr<void> set_attribute_ns(Optional<FlyString> const& namespace_, FlyString const& qualified_name, String const& value);
|
||||
void set_attribute_value(FlyString const& local_name, String const& value, Optional<FlyString> const& prefix = {}, Optional<FlyString> const& namespace_ = {});
|
||||
WebIDL::ExceptionOr<JS::GCPtr<Attr>> set_attribute_node(Attr&);
|
||||
WebIDL::ExceptionOr<JS::GCPtr<Attr>> set_attribute_node_ns(Attr&);
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Reference in a new issue