mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibWeb: Make DOMStringMap GC-allocated
This commit is contained in:
parent
72bacba97b
commit
ae11d70b0c
Notes:
sideshowbarker
2024-07-17 07:28:55 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/ae11d70b0c Pull-request: https://github.com/SerenityOS/serenity/pull/14816 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/linusg ✅
8 changed files with 35 additions and 25 deletions
|
@ -471,7 +471,6 @@ class DOMPointReadOnlyWrapper;
|
|||
class DOMRectListWrapper;
|
||||
class DOMRectReadOnlyWrapper;
|
||||
class DOMRectWrapper;
|
||||
class DOMStringMapWrapper;
|
||||
class DOMTokenListWrapper;
|
||||
class ElementWrapper;
|
||||
class ErrorEventWrapper;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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)))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue