From 8f2a711132292238ffd1cd4a2d15556914e0d6dd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 4 Sep 2022 13:20:53 +0200 Subject: [PATCH] LibWeb: Make Selection GC-allocated --- Userland/Libraries/LibWeb/Forward.h | 1 - Userland/Libraries/LibWeb/HTML/Window.cpp | 1 - .../Libraries/LibWeb/Selection/Selection.cpp | 13 ++++++++++-- .../Libraries/LibWeb/Selection/Selection.h | 21 +++++++++++-------- Userland/Libraries/LibWeb/idl_files.cmake | 2 +- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index e18837077b..992bd9e15f 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -455,7 +455,6 @@ class LocationObject; class OptionConstructor; class RangePrototype; class ResizeObserverWrapper; -class SelectionWrapper; class URLSearchParamsIteratorWrapper; class URLSearchParamsWrapper; class URLWrapper; diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index db10fb6816..e01ec222a1 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include diff --git a/Userland/Libraries/LibWeb/Selection/Selection.cpp b/Userland/Libraries/LibWeb/Selection/Selection.cpp index 4860da5e82..d90894e6d4 100644 --- a/Userland/Libraries/LibWeb/Selection/Selection.cpp +++ b/Userland/Libraries/LibWeb/Selection/Selection.cpp @@ -4,15 +4,24 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include namespace Web::Selection { -NonnullRefPtr Selection::create() +JS::NonnullGCPtr Selection::create(HTML::Window& window) { - return adopt_ref(*new Selection); + return *window.heap().allocate(window.realm(), window); } +Selection::Selection(HTML::Window& window) + : PlatformObject(window.realm()) +{ + set_prototype(&window.cached_web_prototype("Selection")); +} + +Selection::~Selection() = default; + DOM::Node* Selection::anchor_node() { TODO(); diff --git a/Userland/Libraries/LibWeb/Selection/Selection.h b/Userland/Libraries/LibWeb/Selection/Selection.h index 65fff1443b..15108587b1 100644 --- a/Userland/Libraries/LibWeb/Selection/Selection.h +++ b/Userland/Libraries/LibWeb/Selection/Selection.h @@ -6,19 +6,17 @@ #pragma once -#include -#include -#include +#include namespace Web::Selection { -class Selection - : public RefCounted - , public Bindings::Wrappable { -public: - using WrapperType = Bindings::SelectionWrapper; +class Selection final : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(Selection, Bindings::PlatformObject); - static NonnullRefPtr create(); +public: + static JS::NonnullGCPtr create(HTML::Window&); + + virtual ~Selection() override; DOM::Node* anchor_node(); unsigned anchor_offset(); @@ -43,6 +41,11 @@ public: bool contains_node(DOM::Node&, bool allow_partial_containment) const; String to_string() const; + +private: + explicit Selection(HTML::Window&); }; } + +WRAPPER_HACK(Selection, Web::Selection) diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index a216c9a56d..a9875eddde 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -175,7 +175,7 @@ libweb_js_wrapper(SVG/SVGPolylineElement NO_INSTANCE) libweb_js_wrapper(SVG/SVGRectElement NO_INSTANCE) libweb_js_wrapper(SVG/SVGSVGElement NO_INSTANCE) libweb_js_wrapper(SVG/SVGTextContentElement NO_INSTANCE) -libweb_js_wrapper(Selection/Selection) +libweb_js_wrapper(Selection/Selection NO_INSTANCE) libweb_js_wrapper(UIEvents/FocusEvent NO_INSTANCE) libweb_js_wrapper(UIEvents/KeyboardEvent NO_INSTANCE) libweb_js_wrapper(UIEvents/MouseEvent NO_INSTANCE)