diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index e3e1a1f2a6..8dab6c5d3b 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1387,7 +1387,7 @@ WebIDL::ExceptionOr> Document::create_element_ns(Optio } // 4. Return the result of creating an element given document, localName, namespace, prefix, is, and with the synchronous custom elements flag set. - return TRY(DOM::create_element(*this, extracted_qualified_name.local_name(), extracted_qualified_name.deprecated_namespace_(), extracted_qualified_name.deprecated_prefix(), move(is_value), true)); + return TRY(DOM::create_element(*this, extracted_qualified_name.local_name(), extracted_qualified_name.deprecated_namespace_(), extracted_qualified_name.prefix(), move(is_value), true)); } JS::NonnullGCPtr Document::create_document_fragment() diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 61a49ab368..e929df53a0 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -221,7 +221,7 @@ WebIDL::ExceptionOr validate_and_extract(JS::Realm& realm, Deprec TRY(Document::validate_qualified_name(realm, qualified_name)); // 3. Let prefix be null. - DeprecatedFlyString prefix = {}; + Optional prefix = {}; // 4. Let localName be qualifiedName. auto local_name = qualified_name; @@ -229,12 +229,12 @@ WebIDL::ExceptionOr validate_and_extract(JS::Realm& realm, Deprec // 5. If qualifiedName contains a U+003A (:), then strictly split the string on it and set prefix to the part before and localName to the part after. if (qualified_name.view().contains(':')) { auto parts = qualified_name.view().split_view(':'); - prefix = parts[0]; + prefix = MUST(FlyString::from_utf8(parts[0])); local_name = parts[1]; } // 6. If prefix is non-null and namespace is null, then throw a "NamespaceError" DOMException. - if (!prefix.is_null() && namespace_.is_null()) + if (prefix.has_value() && namespace_.is_null()) return WebIDL::NamespaceError::create(realm, "Prefix is non-null and namespace is null."_fly_string); // 7. If prefix is "xml" and namespace is not the XML namespace, then throw a "NamespaceError" DOMException. @@ -264,13 +264,13 @@ WebIDL::ExceptionOr Element::set_attribute_ns(Optional const& name auto extracted_qualified_name = TRY(validate_and_extract(realm(), deprecated_namespace, qualified_name.to_deprecated_fly_string())); // 2. Set an attribute value for this using localName, value, and also prefix and namespace. - set_attribute_value(extracted_qualified_name.local_name().to_deprecated_fly_string(), value.to_deprecated_fly_string(), extracted_qualified_name.deprecated_prefix(), extracted_qualified_name.deprecated_namespace_()); + set_attribute_value(extracted_qualified_name.local_name(), value.to_deprecated_fly_string(), extracted_qualified_name.prefix(), extracted_qualified_name.deprecated_namespace_()); return {}; } // https://dom.spec.whatwg.org/#concept-element-attributes-set-value -void Element::set_attribute_value(DeprecatedFlyString const& local_name, DeprecatedString const& value, DeprecatedFlyString const& prefix, DeprecatedFlyString const& namespace_) +void Element::set_attribute_value(FlyString const& local_name, DeprecatedString const& value, Optional const& prefix, DeprecatedFlyString 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); @@ -279,7 +279,7 @@ void Element::set_attribute_value(DeprecatedFlyString const& local_name, Depreca // is localName, value is value, and node document is element’s node document, then append this attribute to element, // and then return. if (!attribute) { - QualifiedName name { MUST(FlyString::from_deprecated_fly_string(local_name)), prefix, namespace_ }; + QualifiedName name { local_name, prefix, namespace_ }; auto new_attribute = Attr::create(document(), move(name), MUST(String::from_deprecated_string(value))); m_attributes->append_attribute(new_attribute); diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 014176f1cd..ca7f4d0e66 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -118,7 +118,7 @@ public: // FIXME: This should be taking an Optional WebIDL::ExceptionOr set_attribute_ns(Optional const& namespace_, FlyString const& qualified_name, FlyString const& value); - void set_attribute_value(DeprecatedFlyString const& local_name, DeprecatedString const& value, DeprecatedFlyString const& prefix = {}, DeprecatedFlyString const& namespace_ = {}); + void set_attribute_value(FlyString const& local_name, DeprecatedString const& value, Optional const& prefix = {}, DeprecatedFlyString const& namespace_ = {}); WebIDL::ExceptionOr> set_attribute_node(Attr&); WebIDL::ExceptionOr> set_attribute_node_ns(Attr&); diff --git a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp index 8019a2fc91..790bbe2837 100644 --- a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp +++ b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp @@ -490,7 +490,7 @@ static JS::GCPtr create_mathml_element(JS::Realm& realm, return nullptr; } // https://dom.spec.whatwg.org/#concept-create-element -WebIDL::ExceptionOr> create_element(Document& document, FlyString local_name, DeprecatedFlyString namespace_, DeprecatedFlyString prefix, Optional is_value, bool synchronous_custom_elements_flag) +WebIDL::ExceptionOr> create_element(Document& document, FlyString local_name, DeprecatedFlyString namespace_, Optional prefix, Optional is_value, bool synchronous_custom_elements_flag) { auto& realm = document.realm(); @@ -581,10 +581,7 @@ WebIDL::ExceptionOr> create_element(Document& document return JS::throw_completion(WebIDL::NotSupportedError::create(realm, "Synchronously created custom element must have the same local name that element creation was invoked with"_fly_string)); // 10. Set result’s namespace prefix to prefix. - if (prefix.is_null()) - element->set_prefix({}); - else - element->set_prefix(MUST(FlyString::from_deprecated_fly_string(prefix))); + element->set_prefix(prefix); // 11. Set result’s is value to null. element->set_is_value(Optional {}); diff --git a/Userland/Libraries/LibWeb/DOM/ElementFactory.h b/Userland/Libraries/LibWeb/DOM/ElementFactory.h index a40f28d7b5..0743a33cb7 100644 --- a/Userland/Libraries/LibWeb/DOM/ElementFactory.h +++ b/Userland/Libraries/LibWeb/DOM/ElementFactory.h @@ -15,6 +15,6 @@ ErrorOr> valid_local_names_for_given_html_element_interfac bool is_unknown_html_element(FlyString const& tag_name); // FIXME: The spec doesn't say what the default value of synchronous_custom_elements_flag should be. -WebIDL::ExceptionOr> create_element(Document&, FlyString local_name, DeprecatedFlyString namespace_, DeprecatedFlyString prefix = {}, Optional is = Optional {}, bool synchronous_custom_elements_flag = false); +WebIDL::ExceptionOr> create_element(Document&, FlyString local_name, DeprecatedFlyString namespace_, Optional prefix = {}, Optional is = Optional {}, bool synchronous_custom_elements_flag = false); } diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 9c18ebf226..8b1c00e477 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -809,7 +809,7 @@ JS::NonnullGCPtr Node::clone_node(Document* document, bool clone_children) if (is(this)) { // 1. Let copy be the result of creating an element, given document, node’s local name, node’s namespace, node’s namespace prefix, and node’s is value, with the synchronous custom elements flag unset. auto& element = *verify_cast(this); - auto element_copy = DOM::create_element(*document, element.local_name(), element.namespace_(), element.deprecated_prefix(), element.is_value(), false).release_value_but_fixme_should_propagate_errors(); + auto element_copy = DOM::create_element(*document, element.local_name(), element.namespace_(), element.prefix(), element.is_value(), false).release_value_but_fixme_should_propagate_errors(); // 2. For each attribute in node’s attribute list: element.for_each_attribute([&](auto& name, auto& value) { diff --git a/Userland/Libraries/LibWeb/DOM/QualifiedName.cpp b/Userland/Libraries/LibWeb/DOM/QualifiedName.cpp index c379db7a7f..564c0ecbe0 100644 --- a/Userland/Libraries/LibWeb/DOM/QualifiedName.cpp +++ b/Userland/Libraries/LibWeb/DOM/QualifiedName.cpp @@ -54,8 +54,8 @@ QualifiedName::QualifiedName(FlyString const& local_name, Optional co { } -QualifiedName::QualifiedName(FlyString const& local_name, DeprecatedFlyString const& prefix, DeprecatedFlyString const& namespace_) - : QualifiedName(local_name, prefix.is_null() ? Optional {} : MUST(FlyString::from_deprecated_fly_string(prefix)), namespace_.is_null() ? Optional {} : MUST(FlyString::from_deprecated_fly_string(namespace_))) +QualifiedName::QualifiedName(FlyString const& local_name, Optional const& prefix, DeprecatedFlyString const& namespace_) + : QualifiedName(local_name, prefix, namespace_.is_null() ? Optional {} : MUST(FlyString::from_deprecated_fly_string(namespace_))) { } diff --git a/Userland/Libraries/LibWeb/DOM/QualifiedName.h b/Userland/Libraries/LibWeb/DOM/QualifiedName.h index 87112223cc..ea00c4477c 100644 --- a/Userland/Libraries/LibWeb/DOM/QualifiedName.h +++ b/Userland/Libraries/LibWeb/DOM/QualifiedName.h @@ -16,7 +16,7 @@ namespace Web::DOM { class QualifiedName { public: QualifiedName(FlyString const& local_name, Optional const& prefix, Optional const& namespace_); - QualifiedName(FlyString const& local_name, DeprecatedFlyString const& prefix, DeprecatedFlyString const& namespace_); + QualifiedName(FlyString const& local_name, Optional const& prefix, DeprecatedFlyString const& namespace_); FlyString const& local_name() const { return m_impl->local_name; } Optional const& prefix() const { return m_impl->prefix; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index f931e078fb..30dfff9399 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -502,7 +502,7 @@ class PlaceholderElement final : public HTMLDivElement { public: PlaceholderElement(DOM::Document& document) - : HTMLDivElement(document, DOM::QualifiedName { HTML::TagNames::div, ""sv, Namespace::HTML }) + : HTMLDivElement(document, DOM::QualifiedName { HTML::TagNames::div, ""_fly_string, Namespace::HTML }) { } virtual Optional pseudo_element() const override { return CSS::Selector::PseudoElement::Placeholder; }