diff options
author | Andreas Kling <kling@serenityos.org> | 2022-08-08 14:49:54 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-09-06 00:27:09 +0200 |
commit | ae11d70b0c5cacf1b10481f3991fcaeaf11f859b (patch) | |
tree | 46ae0002f1258e343cc5f646b4b1c03332339ad1 | |
parent | 72bacba97b28fe39e2c7928f5b45f1bc601523dc (diff) | |
download | serenity-ae11d70b0c5cacf1b10481f3991fcaeaf11f859b.zip |
LibWeb: Make DOMStringMap GC-allocated
-rw-r--r-- | Userland/Libraries/LibWeb/Forward.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp | 14 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/DOMStringMap.h | 29 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLElement.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLElement.h | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGElement.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGElement.h | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/idl_files.cmake | 2 |
8 files changed, 35 insertions, 25 deletions
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index eb06ef7f75..dd01406f82 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -471,7 +471,6 @@ class DOMPointReadOnlyWrapper; class DOMRectListWrapper; class DOMRectReadOnlyWrapper; class DOMRectWrapper; -class DOMStringMapWrapper; class DOMTokenListWrapper; class ElementWrapper; class ErrorEventWrapper; diff --git a/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp b/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp index bf9ef0b5e6..3e276996ed 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp +++ b/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp @@ -5,13 +5,23 @@ */ #include <AK/CharacterTypes.h> +#include <LibWeb/Bindings/DOMStringMapPrototype.h> +#include <LibWeb/Bindings/WindowObject.h> +#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Element.h> #include <LibWeb/HTML/DOMStringMap.h> namespace Web::HTML { -DOMStringMap::DOMStringMap(DOM::Element& associated_element) - : m_associated_element(associated_element) +DOMStringMap* DOMStringMap::create(DOM::Element& element) +{ + auto& realm = element.document().preferred_window_object().realm(); + return realm.heap().allocate<DOMStringMap>(realm, element); +} + +DOMStringMap::DOMStringMap(DOM::Element& element) + : PlatformObject(element.document().preferred_window_object().ensure_web_prototype<Bindings::DOMStringMapPrototype>("DOMStringMap")) + , m_associated_element(element) { } diff --git a/Userland/Libraries/LibWeb/HTML/DOMStringMap.h b/Userland/Libraries/LibWeb/HTML/DOMStringMap.h index a29c85faa4..902037a2db 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMStringMap.h +++ b/Userland/Libraries/LibWeb/HTML/DOMStringMap.h @@ -1,33 +1,29 @@ /* * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org> + * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include <AK/RefCounted.h> -#include <AK/Weakable.h> -#include <LibWeb/Bindings/Wrappable.h> +#include <LibWeb/Bindings/PlatformObject.h> #include <LibWeb/Forward.h> namespace Web::HTML { // https://html.spec.whatwg.org/multipage/dom.html#domstringmap -class DOMStringMap final - : public RefCounted<DOMStringMap> - , public Weakable<DOMStringMap> - , public Bindings::Wrappable { -public: - using WrapperType = Bindings::DOMStringMapWrapper; +class DOMStringMap final : public Bindings::PlatformObject { + JS_OBJECT(DOMStringMap, Bindings::PlatformObject); - static NonnullRefPtr<DOMStringMap> create(DOM::Element& associated_element) - { - return adopt_ref(*new DOMStringMap(associated_element)); - } +public: + static DOMStringMap* create(DOM::Element&); + explicit DOMStringMap(DOM::Element&); virtual ~DOMStringMap() override; + DOMStringMap& impl() { return *this; } + Vector<String> supported_property_names() const; String determine_value_of_named_property(String const&) const; @@ -38,8 +34,6 @@ public: bool delete_existing_named_property(String const&); private: - DOMStringMap(DOM::Element&); - struct NameValuePair { String name; String value; @@ -52,3 +46,8 @@ private: }; } + +namespace Web::Bindings { +inline JS::Object* wrap(JS::Realm&, Web::HTML::DOMStringMap& object) { return &object; } +using DOMStringMapWrapper = Web::HTML::DOMStringMap; +} diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index 935b45d32d..36fd97e8c6 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -30,7 +30,7 @@ namespace Web::HTML { HTMLElement::HTMLElement(DOM::Document& document, DOM::QualifiedName qualified_name) : Element(document, move(qualified_name)) - , m_dataset(DOMStringMap::create(*this)) + , m_dataset(JS::make_handle(DOMStringMap::create(*this))) { } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.h b/Userland/Libraries/LibWeb/HTML/HTMLElement.h index 9baa00569a..1c0376668e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.h @@ -38,7 +38,8 @@ public: bool cannot_navigate() const; - NonnullRefPtr<DOMStringMap> dataset() const { return m_dataset; } + DOMStringMap* dataset() { return m_dataset.cell(); } + DOMStringMap const* dataset() const { return m_dataset.cell(); } void focus(); @@ -65,7 +66,7 @@ private: }; ContentEditableState content_editable_state() const; - NonnullRefPtr<DOMStringMap> m_dataset; + JS::Handle<DOMStringMap> m_dataset; // https://html.spec.whatwg.org/multipage/interaction.html#locked-for-focus bool m_locked_for_focus { false }; diff --git a/Userland/Libraries/LibWeb/SVG/SVGElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGElement.cpp index 4119706dd5..301231367a 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGElement.cpp @@ -10,7 +10,7 @@ namespace Web::SVG { SVGElement::SVGElement(DOM::Document& document, DOM::QualifiedName qualified_name) : Element(document, move(qualified_name)) - , m_dataset(HTML::DOMStringMap::create(*this)) + , m_dataset(JS::make_handle(HTML::DOMStringMap::create(*this))) { } diff --git a/Userland/Libraries/LibWeb/SVG/SVGElement.h b/Userland/Libraries/LibWeb/SVG/SVGElement.h index 0cd75788fe..af47434fb4 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGElement.h +++ b/Userland/Libraries/LibWeb/SVG/SVGElement.h @@ -17,12 +17,13 @@ public: virtual bool requires_svg_container() const override { return true; } - NonnullRefPtr<HTML::DOMStringMap> dataset() const { return m_dataset; } + HTML::DOMStringMap* dataset() { return m_dataset.cell(); } + HTML::DOMStringMap const* dataset() const { return m_dataset.cell(); } protected: SVGElement(DOM::Document&, DOM::QualifiedName); - NonnullRefPtr<HTML::DOMStringMap> m_dataset; + JS::Handle<HTML::DOMStringMap> m_dataset; }; } diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 2cd19c0df9..62c83c4fbe 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -65,7 +65,7 @@ libweb_js_wrapper(HTML/CanvasGradient) libweb_js_wrapper(HTML/CanvasRenderingContext2D) libweb_js_wrapper(HTML/CloseEvent) libweb_js_wrapper(HTML/DOMParser) -libweb_js_wrapper(HTML/DOMStringMap) +libweb_js_wrapper(HTML/DOMStringMap NO_INSTANCE) libweb_js_wrapper(HTML/ErrorEvent) libweb_js_wrapper(HTML/History) libweb_js_wrapper(HTML/HTMLAnchorElement) |