diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index dac3d92321..65c5468e59 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -453,7 +453,6 @@ class CanvasGradientWrapper; class CanvasRenderingContext2DWrapper; class CryptoWrapper; class DOMExceptionWrapper; -class DOMParserWrapper; class DOMPointWrapper; class DOMPointReadOnlyWrapper; class DOMRectListWrapper; diff --git a/Userland/Libraries/LibWeb/HTML/DOMParser.cpp b/Userland/Libraries/LibWeb/HTML/DOMParser.cpp index 1f661a4ffd..f7846e0fb4 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/DOMParser.cpp @@ -8,13 +8,20 @@ #include #include #include +#include #include namespace Web::HTML { -DOMParser::DOMParser(HTML::Window& window) - : m_window(JS::make_handle(window)) +DOM::ExceptionOr> DOMParser::create_with_global_object(HTML::Window& window) { + return JS::NonnullGCPtr(*window.heap().allocate(window.realm(), window)); +} + +DOMParser::DOMParser(HTML::Window& window) + : PlatformObject(window.realm()) +{ + set_prototype(&window.ensure_web_prototype("DOMParser")); } DOMParser::~DOMParser() = default; @@ -23,7 +30,7 @@ DOMParser::~DOMParser() = default; JS::NonnullGCPtr DOMParser::parse_from_string(String const& string, Bindings::DOMParserSupportedType type) { // 1. Let document be a new Document, whose content type is type and url is this's relevant global object's associated Document's URL. - auto document = DOM::Document::create(Bindings::main_thread_internal_window_object(), m_window->associated_document().url()); + auto document = DOM::Document::create(Bindings::main_thread_internal_window_object(), verify_cast(relevant_global_object(*this)).associated_document().url()); document->set_content_type(Bindings::idl_enum_to_string(type)); // 2. Switch on type: diff --git a/Userland/Libraries/LibWeb/HTML/DOMParser.h b/Userland/Libraries/LibWeb/HTML/DOMParser.h index 4c1c50f708..943cbcc0c8 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMParser.h +++ b/Userland/Libraries/LibWeb/HTML/DOMParser.h @@ -6,9 +6,7 @@ #pragma once -#include -#include -#include +#include #include #include #include @@ -16,17 +14,11 @@ namespace Web::HTML { // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#domparser -class DOMParser final - : public RefCounted - , public Weakable - , public Bindings::Wrappable { -public: - using WrapperType = Bindings::DOMParserWrapper; +class DOMParser final : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(DOMParser, Bindings::PlatformObject); - static DOM::ExceptionOr> create_with_global_object(HTML::Window& window) - { - return adopt_ref(*new DOMParser(window)); - } +public: + static DOM::ExceptionOr> create_with_global_object(HTML::Window&); virtual ~DOMParser() override; @@ -34,8 +26,8 @@ public: private: explicit DOMParser(HTML::Window&); - - JS::Handle m_window; }; } + +WRAPPER_HACK(DOMParser, Web::HTML) diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 4a9626be54..5a69d6a356 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -64,7 +64,7 @@ libweb_js_wrapper(Geometry/DOMRectReadOnly) libweb_js_wrapper(HTML/CanvasGradient) libweb_js_wrapper(HTML/CanvasRenderingContext2D) libweb_js_wrapper(HTML/CloseEvent NO_INSTANCE) -libweb_js_wrapper(HTML/DOMParser) +libweb_js_wrapper(HTML/DOMParser NO_INSTANCE) libweb_js_wrapper(HTML/DOMStringMap NO_INSTANCE) libweb_js_wrapper(HTML/ErrorEvent NO_INSTANCE) libweb_js_wrapper(HTML/History)