summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-08-08 14:49:54 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-06 00:27:09 +0200
commitae11d70b0c5cacf1b10481f3991fcaeaf11f859b (patch)
tree46ae0002f1258e343cc5f646b4b1c03332339ad1 /Userland/Libraries/LibWeb/HTML
parent72bacba97b28fe39e2c7928f5b45f1bc601523dc (diff)
downloadserenity-ae11d70b0c5cacf1b10481f3991fcaeaf11f859b.zip
LibWeb: Make DOMStringMap GC-allocated
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML')
-rw-r--r--Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp14
-rw-r--r--Userland/Libraries/LibWeb/HTML/DOMStringMap.h29
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLElement.cpp2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLElement.h5
4 files changed, 30 insertions, 20 deletions
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 };