diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index 75bf9e8083c..4ad6dc02b87 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -50,8 +50,6 @@ void HTMLElement::initialize(JS::Realm& realm) { Base::initialize(realm); WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLElement); - - m_dataset = DOMStringMap::create(*this); } void HTMLElement::visit_edges(Cell::Visitor& visitor) @@ -60,6 +58,13 @@ void HTMLElement::visit_edges(Cell::Visitor& visitor) visitor.visit(m_dataset); } +JS::NonnullGCPtr HTMLElement::dataset() +{ + if (!m_dataset) + m_dataset = DOMStringMap::create(*this); + return *m_dataset; +} + // https://html.spec.whatwg.org/multipage/dom.html#dom-dir StringView HTMLElement::dir() const { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.h b/Userland/Libraries/LibWeb/HTML/HTMLElement.h index e56c2020700..e68bd7717ff 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.h @@ -53,8 +53,7 @@ public: bool cannot_navigate() const; - DOMStringMap* dataset() { return m_dataset.ptr(); } - DOMStringMap const* dataset() const { return m_dataset.ptr(); } + [[nodiscard]] JS::NonnullGCPtr dataset(); void focus(); diff --git a/Userland/Libraries/LibWeb/MathML/MathMLElement.cpp b/Userland/Libraries/LibWeb/MathML/MathMLElement.cpp index dcccb089ac9..c08d0e0cf08 100644 --- a/Userland/Libraries/LibWeb/MathML/MathMLElement.cpp +++ b/Userland/Libraries/LibWeb/MathML/MathMLElement.cpp @@ -23,8 +23,13 @@ void MathMLElement::initialize(JS::Realm& realm) { Base::initialize(realm); WEB_SET_PROTOTYPE_FOR_INTERFACE(MathMLElement); +} - m_dataset = HTML::DOMStringMap::create(*this); +JS::NonnullGCPtr MathMLElement::dataset() +{ + if (!m_dataset) + m_dataset = HTML::DOMStringMap::create(*this); + return *m_dataset; } Optional MathMLElement::default_role() const diff --git a/Userland/Libraries/LibWeb/MathML/MathMLElement.h b/Userland/Libraries/LibWeb/MathML/MathMLElement.h index 177cba7936b..71964f28e57 100644 --- a/Userland/Libraries/LibWeb/MathML/MathMLElement.h +++ b/Userland/Libraries/LibWeb/MathML/MathMLElement.h @@ -20,8 +20,7 @@ class MathMLElement : public DOM::Element public: virtual ~MathMLElement() override; - HTML::DOMStringMap* dataset() { return m_dataset.ptr(); } - HTML::DOMStringMap const* dataset() const { return m_dataset.ptr(); } + [[nodiscard]] JS::NonnullGCPtr dataset(); virtual Optional default_role() const override; diff --git a/Userland/Libraries/LibWeb/SVG/SVGElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGElement.cpp index dc3c56ab303..84a24333506 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGElement.cpp @@ -25,8 +25,6 @@ void SVGElement::initialize(JS::Realm& realm) { Base::initialize(realm); WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGElement); - - m_dataset = HTML::DOMStringMap::create(*this); } void SVGElement::visit_edges(Cell::Visitor& visitor) @@ -35,6 +33,13 @@ void SVGElement::visit_edges(Cell::Visitor& visitor) visitor.visit(m_dataset); } +JS::NonnullGCPtr SVGElement::dataset() +{ + if (!m_dataset) + m_dataset = HTML::DOMStringMap::create(*this); + return *m_dataset; +} + void SVGElement::attribute_changed(FlyString const& name, Optional const& value) { Base::attribute_changed(name, value); diff --git a/Userland/Libraries/LibWeb/SVG/SVGElement.h b/Userland/Libraries/LibWeb/SVG/SVGElement.h index 3a9eb2744a3..8ae313fe2cb 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGElement.h +++ b/Userland/Libraries/LibWeb/SVG/SVGElement.h @@ -23,8 +23,7 @@ public: virtual void inserted() override; virtual void removed_from(Node*) override; - HTML::DOMStringMap* dataset() { return m_dataset.ptr(); } - HTML::DOMStringMap const* dataset() const { return m_dataset.ptr(); } + [[nodiscard]] JS::NonnullGCPtr dataset(); void focus(); void blur();