From 233208b640cfc524aef862b88237c78bb05cb86c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 3 Sep 2022 00:22:54 +0200 Subject: [PATCH] LibWeb: Make XMLSerializer GC-allocated --- .../LibWeb/DOMParsing/XMLSerializer.cpp | 13 +++++++++++- .../LibWeb/DOMParsing/XMLSerializer.h | 21 +++++++------------ Userland/Libraries/LibWeb/Forward.h | 1 - Userland/Libraries/LibWeb/idl_files.cmake | 2 +- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp b/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp index ed1f194493..948b6ad600 100644 --- a/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp +++ b/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -20,7 +21,17 @@ namespace Web::DOMParsing { -XMLSerializer::XMLSerializer() = default; +JS::NonnullGCPtr XMLSerializer::create_with_global_object(HTML::Window& window) +{ + return *window.heap().allocate(window.realm(), window); +} + +XMLSerializer::XMLSerializer(HTML::Window& window) + : PlatformObject(window.realm()) +{ + set_prototype(&window.ensure_web_prototype("XMLSerializer")); +} + XMLSerializer::~XMLSerializer() = default; // https://w3c.github.io/DOM-Parsing/#dom-xmlserializer-serializetostring diff --git a/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.h b/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.h index ca0d875e55..b7e57d169d 100644 --- a/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.h +++ b/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.h @@ -6,29 +6,22 @@ #pragma once -#include -#include -#include +#include namespace Web::DOMParsing { -class XMLSerializer final - : public RefCounted - , public Bindings::Wrappable { -public: - using WrapperType = Bindings::XMLSerializerWrapper; +class XMLSerializer final : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(XMLSerializer, Bindings::PlatformObject); - static NonnullRefPtr create_with_global_object(HTML::Window&) - { - return adopt_ref(*new XMLSerializer()); - } +public: + static JS::NonnullGCPtr create_with_global_object(HTML::Window&); virtual ~XMLSerializer() override; DOM::ExceptionOr serialize_to_string(JS::NonnullGCPtr root); private: - XMLSerializer(); + explicit XMLSerializer(HTML::Window&); }; enum class RequireWellFormed { @@ -39,3 +32,5 @@ enum class RequireWellFormed { DOM::ExceptionOr serialize_node_to_xml_string(JS::NonnullGCPtr root, RequireWellFormed require_well_formed); } + +WRAPPER_HACK(XMLSerializer, Web::DOMParsing) diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index e3f920d634..02a58d1187 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -479,7 +479,6 @@ class WorkerNavigatorWrapper; class Wrappable; class Wrapper; class XMLHttpRequestPrototype; -class XMLSerializerWrapper; enum class CanPlayTypeResult; enum class CanvasFillRule; enum class EndingType; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 85fe394a75..56ef04e22a 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -50,7 +50,7 @@ libweb_js_wrapper(DOM/ShadowRoot NO_INSTANCE) libweb_js_wrapper(DOM/StaticRange NO_INSTANCE) libweb_js_wrapper(DOM/Text NO_INSTANCE) libweb_js_wrapper(DOM/TreeWalker NO_INSTANCE) -libweb_js_wrapper(DOMParsing/XMLSerializer) +libweb_js_wrapper(DOMParsing/XMLSerializer NO_INSTANCE) libweb_js_wrapper(Encoding/TextDecoder) libweb_js_wrapper(Encoding/TextEncoder) libweb_js_wrapper(Fetch/Headers ITERABLE)