diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 8fde3fd27f..25f8c2ae14 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -721,8 +721,7 @@ WebIDL::ExceptionOr Element::set_inner_html(StringView markup) // https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml WebIDL::ExceptionOr Element::inner_html() const { - auto inner_html = TRY(serialize_fragment(DOMParsing::RequireWellFormed::Yes)); - return MUST(String::from_deprecated_string(inner_html)); + return serialize_fragment(DOMParsing::RequireWellFormed::Yes); } bool Element::is_focused() const diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index b43506c52d..c1c901a561 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -1330,14 +1330,14 @@ void Node::string_replace_all(DeprecatedString const& string) } // https://w3c.github.io/DOM-Parsing/#dfn-fragment-serializing-algorithm -WebIDL::ExceptionOr Node::serialize_fragment(DOMParsing::RequireWellFormed require_well_formed) const +WebIDL::ExceptionOr Node::serialize_fragment(DOMParsing::RequireWellFormed require_well_formed) const { // 1. Let context document be the value of node's node document. auto const& context_document = document(); // 2. If context document is an HTML document, return an HTML serialization of node. if (context_document.is_html_document()) - return HTML::HTMLParser::serialize_html_fragment(*this).to_deprecated_string(); + return HTML::HTMLParser::serialize_html_fragment(*this); // 3. Otherwise, context document is an XML document; return an XML serialization of node passing the flag require well-formed. return DOMParsing::serialize_node_to_xml_string(*this, require_well_formed); diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index 08081a6ae2..2ab966c224 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -238,7 +238,7 @@ public: i32 unique_id() const { return m_unique_id; } static Node* from_unique_id(i32); - WebIDL::ExceptionOr serialize_fragment(DOMParsing::RequireWellFormed) const; + WebIDL::ExceptionOr serialize_fragment(DOMParsing::RequireWellFormed) const; void replace_all(JS::GCPtr); void string_replace_all(DeprecatedString const&); diff --git a/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp b/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp index 26deaba174..4ee1d1d149 100644 --- a/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp +++ b/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp @@ -40,7 +40,7 @@ EventTarget* ShadowRoot::get_parent(Event const& event) } // https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml -WebIDL::ExceptionOr ShadowRoot::inner_html() const +WebIDL::ExceptionOr ShadowRoot::inner_html() const { return serialize_fragment(DOMParsing::RequireWellFormed::Yes); } diff --git a/Userland/Libraries/LibWeb/DOM/ShadowRoot.h b/Userland/Libraries/LibWeb/DOM/ShadowRoot.h index acdc8d98ac..17f3a52895 100644 --- a/Userland/Libraries/LibWeb/DOM/ShadowRoot.h +++ b/Userland/Libraries/LibWeb/DOM/ShadowRoot.h @@ -30,7 +30,7 @@ public: // ^EventTarget virtual EventTarget* get_parent(Event const&) override; - WebIDL::ExceptionOr inner_html() const; + WebIDL::ExceptionOr inner_html() const; WebIDL::ExceptionOr set_inner_html(StringView); private: diff --git a/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp b/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp index d0ad3aad6d..25559a45e1 100644 --- a/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp +++ b/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp @@ -44,7 +44,7 @@ void XMLSerializer::initialize(JS::Realm& realm) } // https://w3c.github.io/DOM-Parsing/#dom-xmlserializer-serializetostring -WebIDL::ExceptionOr XMLSerializer::serialize_to_string(JS::NonnullGCPtr root) +WebIDL::ExceptionOr XMLSerializer::serialize_to_string(JS::NonnullGCPtr root) { // The serializeToString(root) method must produce an XML serialization of root passing a value of false for the require well-formed parameter, and return the result. return serialize_node_to_xml_string(root, RequireWellFormed::No); @@ -127,10 +127,10 @@ static bool prefix_is_in_prefix_map(FlyString const& prefix, HashMapvalue.contains_slow(prefix); } -WebIDL::ExceptionOr serialize_node_to_xml_string_impl(JS::NonnullGCPtr root, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed); +WebIDL::ExceptionOr serialize_node_to_xml_string_impl(JS::NonnullGCPtr root, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed); // https://w3c.github.io/DOM-Parsing/#dfn-xml-serialization -WebIDL::ExceptionOr serialize_node_to_xml_string(JS::NonnullGCPtr root, RequireWellFormed require_well_formed) +WebIDL::ExceptionOr serialize_node_to_xml_string(JS::NonnullGCPtr root, RequireWellFormed require_well_formed) { // 1. Let namespace be a context namespace with value null. The context namespace tracks the XML serialization algorithm's current default namespace. // The context namespace is changed when either an Element Node has a default namespace declaration, or the algorithm generates a default namespace declaration @@ -154,16 +154,16 @@ WebIDL::ExceptionOr serialize_node_to_xml_string(JS::NonnullGC return serialize_node_to_xml_string_impl(root, namespace_, prefix_map, prefix_index, require_well_formed); } -static WebIDL::ExceptionOr serialize_element(DOM::Element const& element, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed); -static WebIDL::ExceptionOr serialize_document(DOM::Document const& document, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed); -static WebIDL::ExceptionOr serialize_comment(DOM::Comment const& comment, RequireWellFormed require_well_formed); -static WebIDL::ExceptionOr serialize_text(DOM::Text const& text, RequireWellFormed require_well_formed); -static WebIDL::ExceptionOr serialize_document_fragment(DOM::DocumentFragment const& document_fragment, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed); -static WebIDL::ExceptionOr serialize_document_type(DOM::DocumentType const& document_type, RequireWellFormed require_well_formed); -static WebIDL::ExceptionOr serialize_processing_instruction(DOM::ProcessingInstruction const& processing_instruction, RequireWellFormed require_well_formed); +static WebIDL::ExceptionOr serialize_element(DOM::Element const& element, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed); +static WebIDL::ExceptionOr serialize_document(DOM::Document const& document, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed); +static WebIDL::ExceptionOr serialize_comment(DOM::Comment const& comment, RequireWellFormed require_well_formed); +static WebIDL::ExceptionOr serialize_text(DOM::Text const& text, RequireWellFormed require_well_formed); +static WebIDL::ExceptionOr serialize_document_fragment(DOM::DocumentFragment const& document_fragment, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed); +static WebIDL::ExceptionOr serialize_document_type(DOM::DocumentType const& document_type, RequireWellFormed require_well_formed); +static WebIDL::ExceptionOr serialize_processing_instruction(DOM::ProcessingInstruction const& processing_instruction, RequireWellFormed require_well_formed); // https://w3c.github.io/DOM-Parsing/#dfn-xml-serialization-algorithm -WebIDL::ExceptionOr serialize_node_to_xml_string_impl(JS::NonnullGCPtr root, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed) +WebIDL::ExceptionOr serialize_node_to_xml_string_impl(JS::NonnullGCPtr root, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed) { // Each of the following algorithms for producing an XML serialization of a DOM node take as input a node to serialize and the following arguments: // - A context namespace namespace @@ -221,7 +221,7 @@ WebIDL::ExceptionOr serialize_node_to_xml_string_impl(JS::Nonn if (is(*root)) { // -> An Attr object // Return an empty string. - return DeprecatedString::empty(); + return String {}; } // -> Anything else @@ -287,14 +287,14 @@ static Optional record_namespace_information(DOM::Element const& elem } // https://w3c.github.io/DOM-Parsing/#dfn-serializing-an-attribute-value -static WebIDL::ExceptionOr serialize_an_attribute_value(Optional const& attribute_value, [[maybe_unused]] RequireWellFormed require_well_formed) +static WebIDL::ExceptionOr serialize_an_attribute_value(Optional const& attribute_value, [[maybe_unused]] RequireWellFormed require_well_formed) { // FIXME: 1. If the require well-formed flag is set (its value is true), and attribute value contains characters that are not matched by the XML Char production, // then throw an exception; the serialization of this attribute value would fail to produce a well-formed element serialization. // 2. If attribute value is null, then return the empty string. if (!attribute_value.has_value()) - return DeprecatedString::empty(); + return String {}; // 3. Otherwise, attribute value is a string. Return the value of attribute value, first replacing any occurrences of the following: auto final_attribute_value = attribute_value->to_string(); @@ -320,7 +320,7 @@ struct LocalNameSetEntry { }; // https://w3c.github.io/DOM-Parsing/#dfn-xml-serialization-of-the-attributes -static WebIDL::ExceptionOr serialize_element_attributes(DOM::Element const& element, HashMap>>& namespace_prefix_map, u64& prefix_index, HashMap> const& local_prefixes_map, bool ignore_namespace_definition_attribute, RequireWellFormed require_well_formed) +static WebIDL::ExceptionOr serialize_element_attributes(DOM::Element const& element, HashMap>>& namespace_prefix_map, u64& prefix_index, HashMap> const& local_prefixes_map, bool ignore_namespace_definition_attribute, RequireWellFormed require_well_formed) { auto& realm = element.realm(); @@ -365,10 +365,6 @@ static WebIDL::ExceptionOr serialize_element_attributes(DOM::E // 5. If attribute namespace is not null, then run these sub-steps: if (attribute_namespace.has_value()) { // 1. Let candidate prefix be the result of retrieving a preferred prefix string from map given namespace attribute namespace with preferred prefix being attr's prefix value. - DeprecatedString deprecated_prefix; - if (attribute->prefix().has_value()) - deprecated_prefix = attribute->prefix()->to_deprecated_fly_string(); - candidate_prefix = retrieve_a_preferred_prefix_string(attribute->prefix(), namespace_prefix_map, attribute->namespace_uri()); // 2. If the value of attribute namespace is the XMLNS namespace, then run these steps: @@ -473,11 +469,11 @@ static WebIDL::ExceptionOr serialize_element_attributes(DOM::E } // 4. Return the value of result. - return result.to_deprecated_string(); + return MUST(result.to_string()); } // https://w3c.github.io/DOM-Parsing/#xml-serializing-an-element-node -static WebIDL::ExceptionOr serialize_element(DOM::Element const& element, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed) +static WebIDL::ExceptionOr serialize_element(DOM::Element const& element, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed) { auto& realm = element.realm(); @@ -542,7 +538,7 @@ static WebIDL::ExceptionOr serialize_element(DOM::Element cons qualified_name.append(element.local_name()); // 4. Append the value of qualified name to markup. - markup.append(qualified_name.to_deprecated_string()); + markup.append(qualified_name.string_view()); } // 12. Otherwise, inherited ns is not equal to ns (the node's own namespace is different from the context namespace of its parent). Run these sub-steps: @@ -579,7 +575,7 @@ static WebIDL::ExceptionOr serialize_element(DOM::Element cons } // 3. Append the value of qualified name to markup. - markup.append(qualified_name.to_deprecated_string()); + markup.append(qualified_name.string_view()); } // 5. Otherwise, if prefix is not null, then: @@ -595,7 +591,7 @@ static WebIDL::ExceptionOr serialize_element(DOM::Element cons qualified_name.appendff("{}:{}", prefix, element.local_name()); // 4. Append the value of qualified name to markup. - markup.append(qualified_name.to_deprecated_string()); + markup.append(qualified_name.string_view()); // 5. Append the following to markup, in the order listed: // 1. " " (U+0020 SPACE); @@ -636,7 +632,7 @@ static WebIDL::ExceptionOr serialize_element(DOM::Element cons inherited_ns = ns; // 4. Append the value of qualified name to markup. - markup.append(qualified_name.to_deprecated_string()); + markup.append(qualified_name.string_view()); // 5. Append the following to markup, in the order listed: // 1. " " (U+0020 SPACE); @@ -659,7 +655,7 @@ static WebIDL::ExceptionOr serialize_element(DOM::Element cons qualified_name.append(element.local_name()); inherited_ns = ns; - markup.append(qualified_name.to_deprecated_string()); + markup.append(qualified_name.string_view()); } } @@ -689,7 +685,7 @@ static WebIDL::ExceptionOr serialize_element(DOM::Element cons // 17. If the value of skip end tag is true, then return the value of markup and skip the remaining steps. The node is a leaf-node. if (skip_end_tag) - return markup.to_deprecated_string(); + return MUST(markup.to_string()); // 18. If ns is the HTML namespace, and the node's localName matches the string "template", then this is a template element. if (ns == Namespace::HTML && element.local_name() == HTML::TagNames::template_) { @@ -709,17 +705,17 @@ static WebIDL::ExceptionOr serialize_element(DOM::Element cons markup.append("" (U+003E GREATER-THAN SIGN). markup.append('>'); // 21. Return the value of markup. - return markup.to_deprecated_string(); + return MUST(markup.to_string()); } // https://w3c.github.io/DOM-Parsing/#xml-serializing-a-document-node -static WebIDL::ExceptionOr serialize_document(DOM::Document const& document, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed) +static WebIDL::ExceptionOr serialize_document(DOM::Document const& document, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed) { // If the require well-formed flag is set (its value is true), and this node has no documentElement (the documentElement attribute's value is null), // then throw an exception; the serialization of this node would not be a well-formed document. @@ -735,11 +731,11 @@ static WebIDL::ExceptionOr serialize_document(DOM::Document co serialized_document.append(TRY(serialize_node_to_xml_string_impl(*child, namespace_, namespace_prefix_map, prefix_index, require_well_formed))); // 3. Return the value of serialized document. - return serialized_document.to_deprecated_string(); + return MUST(serialized_document.to_string()); } // https://w3c.github.io/DOM-Parsing/#xml-serializing-a-comment-node -static WebIDL::ExceptionOr serialize_comment(DOM::Comment const& comment, RequireWellFormed require_well_formed) +static WebIDL::ExceptionOr serialize_comment(DOM::Comment const& comment, RequireWellFormed require_well_formed) { // If the require well-formed flag is set (its value is true), and node's data contains characters that are not matched by the XML Char production // or contains "--" (two adjacent U+002D HYPHEN-MINUS characters) or that ends with a "-" (U+002D HYPHEN-MINUS) character, then throw an exception; @@ -755,11 +751,11 @@ static WebIDL::ExceptionOr serialize_comment(DOM::Comment cons } // Otherwise, return the concatenation of "". - return DeprecatedString::formatted("", comment.data()); + return MUST(String::formatted("", comment.data())); } // https://w3c.github.io/DOM-Parsing/#xml-serializing-a-text-node -static WebIDL::ExceptionOr serialize_text(DOM::Text const& text, [[maybe_unused]] RequireWellFormed require_well_formed) +static WebIDL::ExceptionOr serialize_text(DOM::Text const& text, [[maybe_unused]] RequireWellFormed require_well_formed) { // FIXME: 1. If the require well-formed flag is set (its value is true), and node's data contains characters that are not matched by the XML Char production, // then throw an exception; the serialization of this node's data would not be well-formed. @@ -781,7 +777,7 @@ static WebIDL::ExceptionOr serialize_text(DOM::Text const& tex } // https://w3c.github.io/DOM-Parsing/#xml-serializing-a-documentfragment-node -static WebIDL::ExceptionOr serialize_document_fragment(DOM::DocumentFragment const& document_fragment, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed) +static WebIDL::ExceptionOr serialize_document_fragment(DOM::DocumentFragment const& document_fragment, Optional& namespace_, HashMap>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed) { // 1. Let markup the empty string. StringBuilder markup; @@ -792,11 +788,11 @@ static WebIDL::ExceptionOr serialize_document_fragment(DOM::Do markup.append(TRY(serialize_node_to_xml_string_impl(*child, namespace_, namespace_prefix_map, prefix_index, require_well_formed))); // 3. Return the value of markup. - return markup.to_deprecated_string(); + return MUST(markup.to_string()); } // https://w3c.github.io/DOM-Parsing/#xml-serializing-a-documenttype-node -static WebIDL::ExceptionOr serialize_document_type(DOM::DocumentType const& document_type, RequireWellFormed require_well_formed) +static WebIDL::ExceptionOr serialize_document_type(DOM::DocumentType const& document_type, RequireWellFormed require_well_formed) { if (require_well_formed == RequireWellFormed::Yes) { // FIXME: 1. If the require well-formed flag is true and the node's publicId attribute contains characters that are not matched by the XML PubidChar production, @@ -858,11 +854,11 @@ static WebIDL::ExceptionOr serialize_document_type(DOM::Docume markup.append('>'); // 11. Return the value of markup. - return markup.to_deprecated_string(); + return MUST(markup.to_string()); } // https://w3c.github.io/DOM-Parsing/#dfn-xml-serializing-a-processinginstruction-node -static WebIDL::ExceptionOr serialize_processing_instruction(DOM::ProcessingInstruction const& processing_instruction, RequireWellFormed require_well_formed) +static WebIDL::ExceptionOr serialize_processing_instruction(DOM::ProcessingInstruction const& processing_instruction, RequireWellFormed require_well_formed) { if (require_well_formed == RequireWellFormed::Yes) { // 1. If the require well-formed flag is set (its value is true), and node's target contains a ":" (U+003A COLON) character @@ -899,7 +895,7 @@ static WebIDL::ExceptionOr serialize_processing_instruction(DO markup.append("?>"sv); // 4. Return the value of markup. - return markup.to_deprecated_string(); + return MUST(markup.to_string()); } } diff --git a/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.h b/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.h index 7527b39b87..85ac29daab 100644 --- a/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.h +++ b/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.h @@ -19,7 +19,7 @@ public: virtual ~XMLSerializer() override; - WebIDL::ExceptionOr serialize_to_string(JS::NonnullGCPtr root); + WebIDL::ExceptionOr serialize_to_string(JS::NonnullGCPtr root); private: explicit XMLSerializer(JS::Realm&); @@ -32,5 +32,5 @@ enum class RequireWellFormed { Yes, }; -WebIDL::ExceptionOr serialize_node_to_xml_string(JS::NonnullGCPtr root, RequireWellFormed require_well_formed); +WebIDL::ExceptionOr serialize_node_to_xml_string(JS::NonnullGCPtr root, RequireWellFormed require_well_formed); } diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index fd6a7bed41..2d644223bb 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -566,7 +566,6 @@ WebIDL::ExceptionOr XMLHttpRequest::send(Optionalhas>()) { - // FIXME: Perform USVString conversion and UTF-8 encoding. auto string_serialized_document = TRY(body->get>().cell()->serialize_fragment(DOMParsing::RequireWellFormed::No)); m_request_body = TRY(Fetch::Infrastructure::byte_sequence_as_body(realm, string_serialized_document.bytes())); } diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index 1f1655b937..19c27b0f5e 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -1422,11 +1422,11 @@ Messages::WebDriverClient::GetSourceResponse WebDriverConnection::get_source() // 3. Let source be the result of invoking the fragment serializing algorithm on a fictional node whose only child is the document element providing true for the require well-formed flag. If this causes an exception to be thrown, let source be null. if (auto result = document->serialize_fragment(Web::DOMParsing::RequireWellFormed::Yes); !result.is_error()) - source = result.release_value(); + source = result.release_value().to_deprecated_string(); // 4. Let source be the result of serializing to string the current browsing context active document, if source is null. if (!source.has_value()) - source = MUST(document->serialize_fragment(Web::DOMParsing::RequireWellFormed::No)); + source = MUST(document->serialize_fragment(Web::DOMParsing::RequireWellFormed::No)).to_deprecated_string(); // 5. Return success with data source. return source.release_value();