Forráskód Böngészése

LibWeb: Port HTMLParser::serialize_html_fragment from DeprecatedString

Shannon Booth 1 éve
szülő
commit
a8fd4fab00

+ 1 - 1
Userland/Libraries/LibWeb/DOM/Node.cpp

@@ -1333,7 +1333,7 @@ WebIDL::ExceptionOr<DeprecatedString> Node::serialize_fragment(DOMParsing::Requi
 
 
     // 2. If context document is an HTML document, return an HTML serialization of node.
     // 2. If context document is an HTML document, return an HTML serialization of node.
     if (context_document.is_html_document())
     if (context_document.is_html_document())
-        return HTML::HTMLParser::serialize_html_fragment(*this);
+        return HTML::HTMLParser::serialize_html_fragment(*this).to_deprecated_string();
 
 
     // 3. Otherwise, context document is an XML document; return an XML serialization of node passing the flag require well-formed.
     // 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);
     return DOMParsing::serialize_node_to_xml_string(*this, require_well_formed);

+ 6 - 6
Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp

@@ -3849,19 +3849,19 @@ JS::NonnullGCPtr<HTMLParser> HTMLParser::create(DOM::Document& document, StringV
 }
 }
 
 
 // https://html.spec.whatwg.org/multipage/parsing.html#html-fragment-serialisation-algorithm
 // https://html.spec.whatwg.org/multipage/parsing.html#html-fragment-serialisation-algorithm
-DeprecatedString HTMLParser::serialize_html_fragment(DOM::Node const& node)
+String HTMLParser::serialize_html_fragment(DOM::Node const& node)
 {
 {
     // The algorithm takes as input a DOM Element, Document, or DocumentFragment referred to as the node.
     // The algorithm takes as input a DOM Element, Document, or DocumentFragment referred to as the node.
     VERIFY(node.is_element() || node.is_document() || node.is_document_fragment());
     VERIFY(node.is_element() || node.is_document() || node.is_document_fragment());
     JS::NonnullGCPtr<DOM::Node const> actual_node = node;
     JS::NonnullGCPtr<DOM::Node const> actual_node = node;
 
 
     if (is<DOM::Element>(node)) {
     if (is<DOM::Element>(node)) {
-        auto& element = verify_cast<DOM::Element>(node);
+        auto const& element = verify_cast<DOM::Element>(node);
 
 
         // 1. If the node serializes as void, then return the empty string.
         // 1. If the node serializes as void, then return the empty string.
         //    (NOTE: serializes as void is defined only on elements in the spec)
         //    (NOTE: serializes as void is defined only on elements in the spec)
         if (element.serializes_as_void())
         if (element.serializes_as_void())
-            return DeprecatedString::empty();
+            return String {};
 
 
         // 3. If the node is a template element, then let the node instead be the template element's template contents (a DocumentFragment node).
         // 3. If the node is a template element, then let the node instead be the template element's template contents (a DocumentFragment node).
         //    (NOTE: This is out of order of the spec to avoid another dynamic cast. The second step just creates a string builder, so it shouldn't matter)
         //    (NOTE: This is out of order of the spec to avoid another dynamic cast. The second step just creates a string builder, so it shouldn't matter)
@@ -3874,7 +3874,7 @@ DeprecatedString HTMLParser::serialize_html_fragment(DOM::Node const& node)
         Yes,
         Yes,
     };
     };
 
 
-    auto escape_string = [](StringView string, AttributeMode attribute_mode) -> DeprecatedString {
+    auto escape_string = [](StringView string, AttributeMode attribute_mode) -> String {
         // https://html.spec.whatwg.org/multipage/parsing.html#escapingString
         // https://html.spec.whatwg.org/multipage/parsing.html#escapingString
         StringBuilder builder;
         StringBuilder builder;
         for (auto code_point : Utf8View { string }) {
         for (auto code_point : Utf8View { string }) {
@@ -3895,7 +3895,7 @@ DeprecatedString HTMLParser::serialize_html_fragment(DOM::Node const& node)
             else
             else
                 builder.append_code_point(code_point);
                 builder.append_code_point(code_point);
         }
         }
-        return builder.to_deprecated_string();
+        return MUST(builder.to_string());
     };
     };
 
 
     // 2. Let s be a string, and initialize it to the empty string.
     // 2. Let s be a string, and initialize it to the empty string.
@@ -4048,7 +4048,7 @@ DeprecatedString HTMLParser::serialize_html_fragment(DOM::Node const& node)
     });
     });
 
 
     // 5. Return s.
     // 5. Return s.
-    return builder.to_deprecated_string();
+    return MUST(builder.to_string());
 }
 }
 
 
 // https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#current-dimension-value
 // https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#current-dimension-value

+ 1 - 1
Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.h

@@ -58,7 +58,7 @@ public:
     DOM::Document& document();
     DOM::Document& document();
 
 
     static Vector<JS::Handle<DOM::Node>> parse_html_fragment(DOM::Element& context_element, StringView);
     static Vector<JS::Handle<DOM::Node>> parse_html_fragment(DOM::Element& context_element, StringView);
-    static DeprecatedString serialize_html_fragment(DOM::Node const& node);
+    static String serialize_html_fragment(DOM::Node const& node);
 
 
     enum class InsertionMode {
     enum class InsertionMode {
 #define __ENUMERATE_INSERTION_MODE(mode) mode,
 #define __ENUMERATE_INSERTION_MODE(mode) mode,