LibWeb: Move XMLSerializer into HTML directory

The DOMParsing spec is in the process of being merged into the HTML one,
gradually. The linked spec change moves XMLSerializer, but many of the
algorithms are still in the DOMParsing spec so I've left the links to
those alone.

I've done my best to update the GN build but since I'm not actually
using it, I might have done that wrong.

Corresponds to 2edb8cc7ee
This commit is contained in:
Sam Atkins 2025-03-03 13:04:14 +00:00 committed by Tim Ledbetter
parent a11848f163
commit f148af0a93
Notes: github-actions[bot] 2025-03-04 16:45:51 +00:00
18 changed files with 25 additions and 32 deletions

View file

@ -240,7 +240,6 @@ set(SOURCES
DOM/TreeWalker.cpp
DOM/Utils.cpp
DOM/XMLDocument.cpp
DOMParsing/XMLSerializer.cpp
DOMURL/DOMURL.cpp
DOMURL/URLSearchParams.cpp
DOMURL/URLSearchParamsIterator.cpp
@ -536,6 +535,7 @@ set(SOURCES
HTML/WorkerNavigator.cpp
HTML/WorkletGlobalScope.cpp
HTML/ValidityState.cpp
HTML/XMLSerializer.cpp
HighResolutionTime/Performance.cpp
HighResolutionTime/TimeOrigin.cpp
Infra/ByteSequences.cpp

View file

@ -865,7 +865,7 @@ WebIDL::ExceptionOr<void> Element::set_inner_html(StringView value)
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-innerhtml
WebIDL::ExceptionOr<String> Element::inner_html() const
{
return serialize_fragment(DOMParsing::RequireWellFormed::Yes);
return serialize_fragment(HTML::RequireWellFormed::Yes);
}
bool Element::is_focused() const
@ -1768,7 +1768,7 @@ WebIDL::ExceptionOr<GC::Ref<DOM::DocumentFragment>> Element::parse_fragment(Stri
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-outerhtml
WebIDL::ExceptionOr<String> Element::outer_html() const
{
return serialize_fragment(DOMParsing::RequireWellFormed::Yes, FragmentSerializationMode::Outer);
return serialize_fragment(HTML::RequireWellFormed::Yes, FragmentSerializationMode::Outer);
}
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-element-outerhtml

View file

@ -1815,7 +1815,7 @@ void Node::string_replace_all(String const& string)
}
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#fragment-serializing-algorithm-steps
WebIDL::ExceptionOr<String> Node::serialize_fragment(DOMParsing::RequireWellFormed require_well_formed, FragmentSerializationMode fragment_serialization_mode) const
WebIDL::ExceptionOr<String> Node::serialize_fragment(HTML::RequireWellFormed require_well_formed, FragmentSerializationMode fragment_serialization_mode) const
{
// 1. Let context document be the value of node's node document.
auto const& context_document = document();
@ -1830,12 +1830,12 @@ WebIDL::ExceptionOr<String> Node::serialize_fragment(DOMParsing::RequireWellForm
if (fragment_serialization_mode == FragmentSerializationMode::Inner) {
StringBuilder markup;
for (auto* child = first_child(); child; child = child->next_sibling()) {
auto child_markup = TRY(DOMParsing::serialize_node_to_xml_string(*child, require_well_formed));
auto child_markup = TRY(HTML::serialize_node_to_xml_string(*child, require_well_formed));
markup.append(child_markup.bytes_as_string_view());
}
return MUST(markup.to_string());
}
return DOMParsing::serialize_node_to_xml_string(*this, require_well_formed);
return HTML::serialize_node_to_xml_string(*this, require_well_formed);
}
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#unsafely-set-html

View file

@ -17,7 +17,7 @@
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/DOM/NodeType.h>
#include <LibWeb/DOM/Slottable.h>
#include <LibWeb/DOMParsing/XMLSerializer.h>
#include <LibWeb/HTML/XMLSerializer.h>
#include <LibWeb/TraversalDecision.h>
#include <LibWeb/TreeNode.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
@ -329,7 +329,7 @@ public:
[[nodiscard]] UniqueNodeID unique_id() const { return m_unique_id; }
static Node* from_unique_id(UniqueNodeID);
WebIDL::ExceptionOr<String> serialize_fragment(DOMParsing::RequireWellFormed, FragmentSerializationMode = FragmentSerializationMode::Inner) const;
WebIDL::ExceptionOr<String> serialize_fragment(HTML::RequireWellFormed, FragmentSerializationMode = FragmentSerializationMode::Inner) const;
WebIDL::ExceptionOr<void> unsafely_set_html(Element&, StringView);

View file

@ -64,7 +64,7 @@ EventTarget* ShadowRoot::get_parent(Event const& event)
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-innerhtml
WebIDL::ExceptionOr<String> ShadowRoot::inner_html() const
{
return serialize_fragment(DOMParsing::RequireWellFormed::Yes);
return serialize_fragment(HTML::RequireWellFormed::Yes);
}
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-innerhtml

View file

@ -339,10 +339,6 @@ struct AddEventListenerOptions;
struct EventListenerOptions;
}
namespace Web::DOMParsing {
class XMLSerializer;
}
namespace Web::Encoding {
class TextDecoder;
class TextEncoder;
@ -579,6 +575,7 @@ class WorkerEnvironmentSettingsObject;
class WorkerGlobalScope;
class WorkerLocation;
class WorkerNavigator;
class XMLSerializer;
enum class AllowMultipleFiles;
enum class MediaSeekMode;

View file

@ -16,13 +16,13 @@
#include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/ProcessingInstruction.h>
#include <LibWeb/DOM/Text.h>
#include <LibWeb/DOMParsing/XMLSerializer.h>
#include <LibWeb/HTML/HTMLTemplateElement.h>
#include <LibWeb/HTML/XMLSerializer.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/Namespace.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::DOMParsing {
namespace Web::HTML {
GC_DEFINE_ALLOCATOR(XMLSerializer);
@ -44,10 +44,12 @@ void XMLSerializer::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(XMLSerializer);
}
// https://w3c.github.io/DOM-Parsing/#dom-xmlserializer-serializetostring
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-xmlserializer-serializetostring
WebIDL::ExceptionOr<String> XMLSerializer::serialize_to_string(GC::Ref<DOM::Node const> 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.
// The serializeToString(root) method steps are:
// 1. Return the XML serialization of root given false.
return serialize_node_to_xml_string(root, RequireWellFormed::No);
}

View file

@ -8,8 +8,9 @@
#include <LibWeb/Bindings/PlatformObject.h>
namespace Web::DOMParsing {
namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#xmlserializer
class XMLSerializer final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(XMLSerializer, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(XMLSerializer);

View file

@ -1,6 +1,6 @@
#import <DOM/Node.idl>
// https://w3c.github.io/DOM-Parsing/#the-xmlserializer-interface
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#xmlserializer
[Exposed=Window]
interface XMLSerializer {
constructor();

View file

@ -573,7 +573,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
// 2. If body is a Document, then set thiss request body to body, serialized, converted, and UTF-8 encoded.
if (body->has<GC::Root<DOM::Document>>()) {
auto string_serialized_document = TRY(body->get<GC::Root<DOM::Document>>().cell()->serialize_fragment(DOMParsing::RequireWellFormed::No));
auto string_serialized_document = TRY(body->get<GC::Root<DOM::Document>>().cell()->serialize_fragment(HTML::RequireWellFormed::No));
m_request_body = Fetch::Infrastructure::byte_sequence_as_body(realm, string_serialized_document.bytes());
}
// 3. Otherwise:

View file

@ -83,7 +83,6 @@ libweb_js_bindings(DOM/StaticRange)
libweb_js_bindings(DOM/Text)
libweb_js_bindings(DOM/TreeWalker)
libweb_js_bindings(DOM/XMLDocument)
libweb_js_bindings(DOMParsing/XMLSerializer)
libweb_js_bindings(DOMURL/DOMURL)
libweb_js_bindings(DOMURL/URLSearchParams ITERABLE)
libweb_js_bindings(Encoding/TextDecoder)
@ -251,6 +250,7 @@ libweb_js_bindings(HTML/WorkerGlobalScope)
libweb_js_bindings(HTML/WorkerLocation)
libweb_js_bindings(HTML/WorkerNavigator)
libweb_js_bindings(HTML/WorkletGlobalScope)
libweb_js_bindings(HTML/XMLSerializer)
libweb_js_bindings(HighResolutionTime/Performance)
libweb_js_bindings(IndexedDB/IDBCursor)
libweb_js_bindings(IndexedDB/IDBDatabase)

View file

@ -4505,7 +4505,6 @@ using namespace Web::CredentialManagement;
using namespace Web::Crypto;
using namespace Web::CSS;
using namespace Web::DOM;
using namespace Web::DOMParsing;
using namespace Web::DOMURL;
using namespace Web::Encoding;
using namespace Web::EntriesAPI;

View file

@ -18,7 +18,6 @@ static constexpr Array libweb_interface_namespaces = {
"Compression"sv,
"Crypto"sv,
"DOM"sv,
"DOMParsing"sv,
"DOMURL"sv,
"Encoding"sv,
"Fetch"sv,

View file

@ -301,7 +301,6 @@ shared_library("LibWeb") {
"Cookie",
"Crypto",
"DOM",
"DOMParsing",
"DOMURL",
"Encoding",
"EntriesAPI",

View file

@ -1,5 +0,0 @@
source_set("DOMParsing") {
configs += [ "//Userland/Libraries/LibWeb:configs" ]
deps = [ "//Userland/Libraries/LibWeb:all_generated" ]
sources = [ "XMLSerializer.cpp" ]
}

View file

@ -205,5 +205,6 @@ source_set("HTML") {
"WorkerGlobalScope.cpp",
"WorkerLocation.cpp",
"WorkerNavigator.cpp",
"XMLSerializer.cpp"
]
}

View file

@ -94,7 +94,6 @@ standard_idl_files = [
"//Userland/Libraries/LibWeb/DOM/Text.idl",
"//Userland/Libraries/LibWeb/DOM/TreeWalker.idl",
"//Userland/Libraries/LibWeb/DOM/XMLDocument.idl",
"//Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.idl",
"//Userland/Libraries/LibWeb/DOMURL/DOMURL.idl",
"//Userland/Libraries/LibWeb/Encoding/TextDecoder.idl",
"//Userland/Libraries/LibWeb/Encoding/TextEncoder.idl",
@ -258,6 +257,7 @@ standard_idl_files = [
"//Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.idl",
"//Userland/Libraries/LibWeb/HTML/WorkerLocation.idl",
"//Userland/Libraries/LibWeb/HTML/WorkerNavigator.idl",
"//Userland/Libraries/LibWeb/HTML/XMLSerializer.idl",
"//Userland/Libraries/LibWeb/IndexedDB/IDBFactory.idl",
"//Userland/Libraries/LibWeb/IndexedDB/IDBOpenDBRequest.idl",
"//Userland/Libraries/LibWeb/IndexedDB/IDBRequest.idl",

View file

@ -2033,13 +2033,13 @@ 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->document_element()->serialize_fragment(Web::DOMParsing::RequireWellFormed::Yes, Web::DOM::FragmentSerializationMode::Outer); !result.is_error())
if (auto result = document->document_element()->serialize_fragment(Web::HTML::RequireWellFormed::Yes, Web::DOM::FragmentSerializationMode::Outer); !result.is_error())
source = result.release_value();
// 4. Let source be the result of serializing to string session's current browsing context's 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::HTML::RequireWellFormed::No));
// 5. Return success with data source.
async_driver_execution_complete({ source.release_value() });