summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-08-31 18:39:32 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-06 00:27:09 +0200
commitd5e831988e169b917f27440e1cc74eb15c7af521 (patch)
treee9e0b3cec60a631904eb8166527fd8fbe663d693 /Userland/Libraries/LibWeb
parent8341f142ea31c92170f1edce7a1e3f4146547b7b (diff)
downloadserenity-d5e831988e169b917f27440e1cc74eb15c7af521.zip
LibWeb: Make DOMParser GC-allocated
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/Forward.h1
-rw-r--r--Userland/Libraries/LibWeb/HTML/DOMParser.cpp11
-rw-r--r--Userland/Libraries/LibWeb/HTML/DOMParser.h22
-rw-r--r--Userland/Libraries/LibWeb/idl_files.cmake2
4 files changed, 17 insertions, 19 deletions
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 <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/HTML/DOMParser.h>
#include <LibWeb/HTML/Parser/HTMLParser.h>
+#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/XML/XMLDocumentBuilder.h>
namespace Web::HTML {
+DOM::ExceptionOr<JS::NonnullGCPtr<DOMParser>> DOMParser::create_with_global_object(HTML::Window& window)
+{
+ return JS::NonnullGCPtr(*window.heap().allocate<DOMParser>(window.realm(), window));
+}
+
DOMParser::DOMParser(HTML::Window& window)
- : m_window(JS::make_handle(window))
+ : PlatformObject(window.realm())
{
+ set_prototype(&window.ensure_web_prototype<Bindings::DOMParserPrototype>("DOMParser"));
}
DOMParser::~DOMParser() = default;
@@ -23,7 +30,7 @@ DOMParser::~DOMParser() = default;
JS::NonnullGCPtr<DOM::Document> 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<HTML::Window>(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 <AK/RefCounted.h>
-#include <AK/Weakable.h>
-#include <LibWeb/Bindings/Wrappable.h>
+#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/Forward.h>
@@ -16,17 +14,11 @@
namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#domparser
-class DOMParser final
- : public RefCounted<DOMParser>
- , public Weakable<DOMParser>
- , public Bindings::Wrappable {
-public:
- using WrapperType = Bindings::DOMParserWrapper;
+class DOMParser final : public Bindings::PlatformObject {
+ WEB_PLATFORM_OBJECT(DOMParser, Bindings::PlatformObject);
- static DOM::ExceptionOr<NonnullRefPtr<DOMParser>> create_with_global_object(HTML::Window& window)
- {
- return adopt_ref(*new DOMParser(window));
- }
+public:
+ static DOM::ExceptionOr<JS::NonnullGCPtr<DOMParser>> create_with_global_object(HTML::Window&);
virtual ~DOMParser() override;
@@ -34,8 +26,8 @@ public:
private:
explicit DOMParser(HTML::Window&);
-
- JS::Handle<HTML::Window> 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)