summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-01 20:50:16 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-06 00:27:09 +0200
commit2bba97964b1daa30877ba715f6e058de5a5100c5 (patch)
tree159db452da35dd1c6789a425e1eddc3682258080
parent4c887bf6c3ca3fc89618fc2ec9dfb7c3c7fdeffd (diff)
downloadserenity-2bba97964b1daa30877ba715f6e058de5a5100c5.zip
LibWeb: Make HTMLCollection and subclasses GC-allocated
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp20
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.h22
-rw-r--r--Userland/Libraries/LibWeb/DOM/Element.cpp2
-rw-r--r--Userland/Libraries/LibWeb/DOM/Element.h2
-rw-r--r--Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp33
-rw-r--r--Userland/Libraries/LibWeb/DOM/HTMLCollection.h37
-rw-r--r--Userland/Libraries/LibWeb/DOM/ParentNode.cpp6
-rw-r--r--Userland/Libraries/LibWeb/DOM/ParentNode.h6
-rw-r--r--Userland/Libraries/LibWeb/Forward.h2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLFormElement.h2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp10
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.h18
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp10
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h6
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp4
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableElement.h4
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp6
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h2
-rw-r--r--Userland/Libraries/LibWeb/idl_files.cmake4
22 files changed, 116 insertions, 86 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index 5b42f2e31b..78add97ac4 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -925,14 +925,14 @@ void Document::set_hovered_node(Node* node)
invalidate_style();
}
-NonnullRefPtr<HTMLCollection> Document::get_elements_by_name(String const& name)
+JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_name(String const& name)
{
return HTMLCollection::create(*this, [name](Element const& element) {
return element.name() == name;
});
}
-NonnullRefPtr<HTMLCollection> Document::get_elements_by_class_name(FlyString const& class_name)
+JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_class_name(FlyString const& class_name)
{
return HTMLCollection::create(*this, [class_name, quirks_mode = document().in_quirks_mode()](Element const& element) {
return element.has_class(class_name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive);
@@ -940,7 +940,7 @@ NonnullRefPtr<HTMLCollection> Document::get_elements_by_class_name(FlyString con
}
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-applets
-NonnullRefPtr<HTMLCollection> Document::applets()
+JS::NonnullGCPtr<HTMLCollection> Document::applets()
{
// FIXME: This should return the same HTMLCollection object every time,
// but that would cause a reference cycle since HTMLCollection refs the root.
@@ -948,7 +948,7 @@ NonnullRefPtr<HTMLCollection> Document::applets()
}
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-anchors
-NonnullRefPtr<HTMLCollection> Document::anchors()
+JS::NonnullGCPtr<HTMLCollection> Document::anchors()
{
// FIXME: This should return the same HTMLCollection object every time,
// but that would cause a reference cycle since HTMLCollection refs the root.
@@ -958,7 +958,7 @@ NonnullRefPtr<HTMLCollection> Document::anchors()
}
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-images
-NonnullRefPtr<HTMLCollection> Document::images()
+JS::NonnullGCPtr<HTMLCollection> Document::images()
{
// FIXME: This should return the same HTMLCollection object every time,
// but that would cause a reference cycle since HTMLCollection refs the root.
@@ -968,7 +968,7 @@ NonnullRefPtr<HTMLCollection> Document::images()
}
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-embeds
-NonnullRefPtr<HTMLCollection> Document::embeds()
+JS::NonnullGCPtr<HTMLCollection> Document::embeds()
{
// FIXME: This should return the same HTMLCollection object every time,
// but that would cause a reference cycle since HTMLCollection refs the root.
@@ -978,13 +978,13 @@ NonnullRefPtr<HTMLCollection> Document::embeds()
}
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-plugins
-NonnullRefPtr<HTMLCollection> Document::plugins()
+JS::NonnullGCPtr<HTMLCollection> Document::plugins()
{
return embeds();
}
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-links
-NonnullRefPtr<HTMLCollection> Document::links()
+JS::NonnullGCPtr<HTMLCollection> Document::links()
{
// FIXME: This should return the same HTMLCollection object every time,
// but that would cause a reference cycle since HTMLCollection refs the root.
@@ -994,7 +994,7 @@ NonnullRefPtr<HTMLCollection> Document::links()
}
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-forms
-NonnullRefPtr<HTMLCollection> Document::forms()
+JS::NonnullGCPtr<HTMLCollection> Document::forms()
{
// FIXME: This should return the same HTMLCollection object every time,
// but that would cause a reference cycle since HTMLCollection refs the root.
@@ -1004,7 +1004,7 @@ NonnullRefPtr<HTMLCollection> Document::forms()
}
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-scripts
-NonnullRefPtr<HTMLCollection> Document::scripts()
+JS::NonnullGCPtr<HTMLCollection> Document::scripts()
{
// FIXME: This should return the same HTMLCollection object every time,
// but that would cause a reference cycle since HTMLCollection refs the root.
diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h
index f4d6e62525..36efd422ca 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.h
+++ b/Userland/Libraries/LibWeb/DOM/Document.h
@@ -172,17 +172,17 @@ public:
void schedule_style_update();
void schedule_layout_update();
- NonnullRefPtr<HTMLCollection> get_elements_by_name(String const&);
- NonnullRefPtr<HTMLCollection> get_elements_by_class_name(FlyString const&);
-
- NonnullRefPtr<HTMLCollection> applets();
- NonnullRefPtr<HTMLCollection> anchors();
- NonnullRefPtr<HTMLCollection> images();
- NonnullRefPtr<HTMLCollection> embeds();
- NonnullRefPtr<HTMLCollection> plugins();
- NonnullRefPtr<HTMLCollection> links();
- NonnullRefPtr<HTMLCollection> forms();
- NonnullRefPtr<HTMLCollection> scripts();
+ JS::NonnullGCPtr<HTMLCollection> get_elements_by_name(String const&);
+ JS::NonnullGCPtr<HTMLCollection> get_elements_by_class_name(FlyString const&);
+
+ JS::NonnullGCPtr<HTMLCollection> applets();
+ JS::NonnullGCPtr<HTMLCollection> anchors();
+ JS::NonnullGCPtr<HTMLCollection> images();
+ JS::NonnullGCPtr<HTMLCollection> embeds();
+ JS::NonnullGCPtr<HTMLCollection> plugins();
+ JS::NonnullGCPtr<HTMLCollection> links();
+ JS::NonnullGCPtr<HTMLCollection> forms();
+ JS::NonnullGCPtr<HTMLCollection> scripts();
String const& source() const { return m_source; }
void set_source(String const& source) { m_source = source; }
diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp
index 665bf4b40e..4826fc8d21 100644
--- a/Userland/Libraries/LibWeb/DOM/Element.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Element.cpp
@@ -500,7 +500,7 @@ bool Element::is_active() const
return document().active_element() == this;
}
-NonnullRefPtr<HTMLCollection> Element::get_elements_by_class_name(FlyString const& class_name)
+JS::NonnullGCPtr<HTMLCollection> Element::get_elements_by_class_name(FlyString const& class_name)
{
return HTMLCollection::create(*this, [class_name, quirks_mode = document().in_quirks_mode()](Element const& element) {
return element.has_class(class_name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive);
diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h
index 45aa9411e1..0c64a6ceff 100644
--- a/Userland/Libraries/LibWeb/DOM/Element.h
+++ b/Userland/Libraries/LibWeb/DOM/Element.h
@@ -112,7 +112,7 @@ public:
bool is_focused() const;
bool is_active() const;
- NonnullRefPtr<HTMLCollection> get_elements_by_class_name(FlyString const&);
+ JS::NonnullGCPtr<HTMLCollection> get_elements_by_class_name(FlyString const&);
ShadowRoot* shadow_root() { return m_shadow_root.ptr(); }
ShadowRoot const* shadow_root() const { return m_shadow_root.ptr(); }
diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp
index 9f95e30094..d4977dab8c 100644
--- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp
+++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp
@@ -1,25 +1,39 @@
/*
- * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibWeb/Bindings/HTMLCollectionPrototype.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/HTMLCollection.h>
#include <LibWeb/DOM/ParentNode.h>
+#include <LibWeb/HTML/Window.h>
#include <LibWeb/Namespace.h>
namespace Web::DOM {
+JS::NonnullGCPtr<HTMLCollection> HTMLCollection::create(ParentNode& root, Function<bool(Element const&)> filter)
+{
+ return *root.heap().allocate<HTMLCollection>(root.realm(), root, move(filter));
+}
+
HTMLCollection::HTMLCollection(ParentNode& root, Function<bool(Element const&)> filter)
- : m_root(JS::make_handle(root))
+ : LegacyPlatformObject(root.window().ensure_web_prototype<Bindings::HTMLCollectionPrototype>("HTMLCollection"))
+ , m_root(root)
, m_filter(move(filter))
{
}
HTMLCollection::~HTMLCollection() = default;
+void HTMLCollection::visit_edges(Cell::Visitor& visitor)
+{
+ Base::visit_edges(visitor);
+ visitor.visit(m_root.ptr());
+}
+
JS::MarkedVector<Element*> HTMLCollection::collect_matching_elements() const
{
JS::MarkedVector<Element*> elements(m_root->heap());
@@ -109,4 +123,19 @@ bool HTMLCollection::is_supported_property_index(u32 index) const
return index < elements.size();
}
+JS::Value HTMLCollection::item_value(size_t index) const
+{
+ auto* element = item(index);
+ if (!element)
+ return JS::js_undefined();
+ return const_cast<Element*>(element);
+}
+
+JS::Value HTMLCollection::named_item_value(FlyString const& index) const
+{
+ auto* element = named_item(index);
+ if (!element)
+ return JS::js_undefined();
+ return const_cast<Element*>(element);
+}
}
diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.h b/Userland/Libraries/LibWeb/DOM/HTMLCollection.h
index eae346bf07..b9f5a7eca2 100644
--- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.h
+++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -8,9 +8,8 @@
#include <AK/FlyString.h>
#include <AK/Function.h>
-#include <AK/Noncopyable.h>
#include <LibJS/Heap/GCPtr.h>
-#include <LibWeb/Bindings/Wrappable.h>
+#include <LibWeb/Bindings/LegacyPlatformObject.h>
#include <LibWeb/Forward.h>
namespace Web::DOM {
@@ -26,21 +25,13 @@ namespace Web::DOM {
// We should teach it how to cache results. The main challenge is invalidating
// these caches, since this needs to happen on various kinds of DOM mutation.
-class HTMLCollection
- : public RefCounted<HTMLCollection>
- , public Bindings::Wrappable {
- AK_MAKE_NONCOPYABLE(HTMLCollection);
- AK_MAKE_NONMOVABLE(HTMLCollection);
+class HTMLCollection : public Bindings::LegacyPlatformObject {
+ WEB_PLATFORM_OBJECT(HTMLCollection, Bindings::LegacyPlatformObject);
public:
- using WrapperType = Bindings::HTMLCollectionWrapper;
+ static JS::NonnullGCPtr<HTMLCollection> create(ParentNode& root, Function<bool(Element const&)> filter);
- static NonnullRefPtr<HTMLCollection> create(ParentNode& root, Function<bool(Element const&)> filter)
- {
- return adopt_ref(*new HTMLCollection(root, move(filter)));
- }
-
- ~HTMLCollection();
+ virtual ~HTMLCollection() override;
size_t length();
Element* item(size_t index) const;
@@ -48,8 +39,10 @@ public:
JS::MarkedVector<Element*> collect_matching_elements() const;
- Vector<String> supported_property_names() const;
- bool is_supported_property_index(u32) const;
+ virtual JS::Value item_value(size_t index) const override;
+ virtual JS::Value named_item_value(FlyString const& name) const override;
+ virtual Vector<String> supported_property_names() const override;
+ virtual bool is_supported_property_index(u32) const override;
protected:
HTMLCollection(ParentNode& root, Function<bool(Element const&)> filter);
@@ -57,14 +50,12 @@ protected:
JS::NonnullGCPtr<ParentNode> root() { return *m_root; }
private:
- JS::Handle<ParentNode> m_root;
+ virtual void visit_edges(Cell::Visitor&) override;
+
+ JS::NonnullGCPtr<ParentNode> m_root;
Function<bool(Element const&)> m_filter;
};
}
-namespace Web::Bindings {
-
-HTMLCollectionWrapper* wrap(JS::Realm&, DOM::HTMLCollection&);
-
-}
+WRAPPER_HACK(HTMLCollection, Web::DOM)
diff --git a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp
index 42bbc2428a..efbcfbffe9 100644
--- a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp
+++ b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp
@@ -82,7 +82,7 @@ u32 ParentNode::child_element_count() const
}
// https://dom.spec.whatwg.org/#dom-parentnode-children
-NonnullRefPtr<HTMLCollection> ParentNode::children()
+JS::NonnullGCPtr<HTMLCollection> ParentNode::children()
{
// The children getter steps are to return an HTMLCollection collection rooted at this matching only element children.
// FIXME: This should return the same HTMLCollection object every time,
@@ -94,7 +94,7 @@ NonnullRefPtr<HTMLCollection> ParentNode::children()
// https://dom.spec.whatwg.org/#concept-getelementsbytagname
// NOTE: This method is only exposed on Document and Element, but is in ParentNode to prevent code duplication.
-NonnullRefPtr<HTMLCollection> ParentNode::get_elements_by_tag_name(FlyString const& qualified_name)
+JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_tag_name(FlyString const& qualified_name)
{
// 1. If qualifiedName is "*" (U+002A), return a HTMLCollection rooted at root, whose filter matches only descendant elements.
if (qualified_name == "*") {
@@ -122,7 +122,7 @@ NonnullRefPtr<HTMLCollection> ParentNode::get_elements_by_tag_name(FlyString con
// https://dom.spec.whatwg.org/#concept-getelementsbytagnamens
// NOTE: This method is only exposed on Document and Element, but is in ParentNode to prevent code duplication.
-NonnullRefPtr<HTMLCollection> ParentNode::get_elements_by_tag_name_ns(FlyString const& nullable_namespace, FlyString const& local_name)
+JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_tag_name_ns(FlyString const& nullable_namespace, FlyString const& local_name)
{
// 1. If namespace is the empty string, set it to null.
String namespace_ = nullable_namespace;
diff --git a/Userland/Libraries/LibWeb/DOM/ParentNode.h b/Userland/Libraries/LibWeb/DOM/ParentNode.h
index a2667892dd..0d2482140c 100644
--- a/Userland/Libraries/LibWeb/DOM/ParentNode.h
+++ b/Userland/Libraries/LibWeb/DOM/ParentNode.h
@@ -26,10 +26,10 @@ public:
ExceptionOr<JS::GCPtr<Element>> query_selector(StringView);
ExceptionOr<JS::NonnullGCPtr<NodeList>> query_selector_all(StringView);
- NonnullRefPtr<HTMLCollection> children();
+ JS::NonnullGCPtr<HTMLCollection> children();
- NonnullRefPtr<HTMLCollection> get_elements_by_tag_name(FlyString const&);
- NonnullRefPtr<HTMLCollection> get_elements_by_tag_name_ns(FlyString const&, FlyString const&);
+ JS::NonnullGCPtr<HTMLCollection> get_elements_by_tag_name(FlyString const&);
+ JS::NonnullGCPtr<HTMLCollection> get_elements_by_tag_name_ns(FlyString const&, FlyString const&);
ExceptionOr<void> prepend(Vector<Variant<JS::Handle<Node>, String>> const& nodes);
ExceptionOr<void> append(Vector<Variant<JS::Handle<Node>, String>> const& nodes);
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index 954c385367..dd28924a24 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -463,8 +463,6 @@ class FileWrapper;
class HeadersWrapper;
class HeadersIteratorWrapper;
class HistoryWrapper;
-class HTMLCollectionWrapper;
-class HTMLOptionsCollectionWrapper;
class IdleDeadlineWrapper;
class ImageDataWrapper;
class IntersectionObserverWrapper;
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
index b9ea743329..acce37c42d 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
@@ -184,7 +184,7 @@ static bool is_form_control(DOM::Element const& element)
}
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-elements
-NonnullRefPtr<DOM::HTMLCollection> HTMLFormElement::elements() const
+JS::NonnullGCPtr<DOM::HTMLCollection> HTMLFormElement::elements() const
{
// FIXME: This should return the same HTMLFormControlsCollection object every time,
// but that would cause a reference cycle since HTMLCollection refs the root.
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h
index d548bf41e9..d7850506e7 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h
@@ -28,7 +28,7 @@ public:
void add_associated_element(Badge<FormAssociatedElement>, HTMLElement&);
void remove_associated_element(Badge<FormAssociatedElement>, HTMLElement&);
- NonnullRefPtr<DOM::HTMLCollection> elements() const;
+ JS::NonnullGCPtr<DOM::HTMLCollection> elements() const;
unsigned length() const;
private:
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp b/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp
index b3d7589223..1763ad2c58 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp
@@ -4,19 +4,29 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibWeb/Bindings/HTMLOptionsCollectionPrototype.h>
#include <LibWeb/DOM/DOMException.h>
#include <LibWeb/HTML/HTMLOptGroupElement.h>
#include <LibWeb/HTML/HTMLOptionElement.h>
#include <LibWeb/HTML/HTMLOptionsCollection.h>
#include <LibWeb/HTML/HTMLSelectElement.h>
+#include <LibWeb/HTML/Window.h>
namespace Web::HTML {
+JS::NonnullGCPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter)
+{
+ return *root.heap().allocate<HTMLOptionsCollection>(root.realm(), root, move(filter));
+}
+
HTMLOptionsCollection::HTMLOptionsCollection(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter)
: DOM::HTMLCollection(root, move(filter))
{
+ set_prototype(&root.window().ensure_web_prototype<Bindings::HTMLOptionsCollectionPrototype>("HTMLOptionsCollection"));
}
+HTMLOptionsCollection::~HTMLOptionsCollection() = default;
+
// https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#dom-htmloptionscollection-add
DOM::ExceptionOr<void> HTMLOptionsCollection::add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before)
{
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.h b/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.h
index e27b2491e3..780401e580 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.h
@@ -16,24 +16,18 @@ using HTMLOptionOrOptGroupElement = Variant<JS::Handle<HTMLOptionElement>, JS::H
using HTMLElementOrElementIndex = Variant<JS::Handle<HTMLElement>, i32>;
class HTMLOptionsCollection final : public DOM::HTMLCollection {
-public:
- using WrapperType = Bindings::HTMLOptionsCollectionWrapper;
+ WEB_PLATFORM_OBJECT(HTMLOptionsCollection, DOM::HTMLCollection);
- static NonnullRefPtr<HTMLOptionsCollection> create(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter)
- {
- return adopt_ref(*new HTMLOptionsCollection(root, move(filter)));
- }
+public:
+ static JS::NonnullGCPtr<HTMLOptionsCollection> create(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter);
+ virtual ~HTMLOptionsCollection() override;
DOM::ExceptionOr<void> add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before = {});
-protected:
+private:
HTMLOptionsCollection(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter);
};
}
-namespace Web::Bindings {
-
-HTMLOptionsCollectionWrapper* wrap(JS::Realm&, HTML::HTMLOptionsCollection&);
-
-}
+WRAPPER_HACK(HTMLOptionsCollection, Web::HTML)
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp
index 25027acd4d..3aacee7155 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp
@@ -22,8 +22,14 @@ HTMLSelectElement::HTMLSelectElement(DOM::Document& document, DOM::QualifiedName
HTMLSelectElement::~HTMLSelectElement() = default;
+void HTMLSelectElement::visit_edges(Cell::Visitor& visitor)
+{
+ Base::visit_edges(visitor);
+ visitor.visit(m_options.ptr());
+}
+
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-options
-RefPtr<HTMLOptionsCollection> const& HTMLSelectElement::options()
+JS::GCPtr<HTMLOptionsCollection> const& HTMLSelectElement::options()
{
if (!m_options) {
m_options = HTMLOptionsCollection::create(*this, [](DOM::Element const& element) {
@@ -41,7 +47,7 @@ RefPtr<HTMLOptionsCollection> const& HTMLSelectElement::options()
DOM::ExceptionOr<void> HTMLSelectElement::add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before)
{
// Similarly, the add(element, before) method must act like its namesake method on that same options collection.
- return const_cast<RefPtr<HTMLOptionsCollection>&>(options())->add(move(element), move(before));
+ return const_cast<HTMLOptionsCollection&>(*options()).add(move(element), move(before));
}
// https://html.spec.whatwg.org/multipage/form-elements.html#concept-select-option-list
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h
index 86b42eb07e..76024d0362 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h
@@ -23,7 +23,7 @@ class HTMLSelectElement final
public:
virtual ~HTMLSelectElement() override;
- RefPtr<HTMLOptionsCollection> const& options();
+ JS::GCPtr<HTMLOptionsCollection> const& options();
DOM::ExceptionOr<void> add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before = {});
@@ -56,7 +56,9 @@ public:
private:
HTMLSelectElement(DOM::Document&, DOM::QualifiedName);
- RefPtr<HTMLOptionsCollection> m_options;
+ virtual void visit_edges(Cell::Visitor&) override;
+
+ JS::GCPtr<HTMLOptionsCollection> m_options;
};
}
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp
index e3da69c0d3..6bc0ee1fae 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp
@@ -222,7 +222,7 @@ void HTMLTableElement::delete_t_foot()
}
}
-NonnullRefPtr<DOM::HTMLCollection> HTMLTableElement::t_bodies()
+JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableElement::t_bodies()
{
return DOM::HTMLCollection::create(*this, [](DOM::Element const& element) {
return element.local_name() == TagNames::tbody;
@@ -253,7 +253,7 @@ JS::NonnullGCPtr<HTMLTableSectionElement> HTMLTableElement::create_t_body()
return static_cast<HTMLTableSectionElement&>(*tbody);
}
-NonnullRefPtr<DOM::HTMLCollection> HTMLTableElement::rows()
+JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableElement::rows()
{
HTMLTableElement* table_node = this;
// FIXME: The elements in the collection must be ordered such that those elements whose parent is a thead are
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h
index 1b6840d88e..601ae62a68 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h
@@ -35,10 +35,10 @@ public:
JS::NonnullGCPtr<HTMLTableSectionElement> create_t_foot();
void delete_t_foot();
- NonnullRefPtr<DOM::HTMLCollection> t_bodies();
+ JS::NonnullGCPtr<DOM::HTMLCollection> t_bodies();
JS::NonnullGCPtr<HTMLTableSectionElement> create_t_body();
- NonnullRefPtr<DOM::HTMLCollection> rows();
+ JS::NonnullGCPtr<DOM::HTMLCollection> rows();
DOM::ExceptionOr<JS::NonnullGCPtr<HTMLTableRowElement>> insert_row(long index);
DOM::ExceptionOr<void> delete_row(long index);
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
index 307cc5cc8c..0a2012de0c 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
@@ -23,7 +23,7 @@ HTMLTableRowElement::HTMLTableRowElement(DOM::Document& document, DOM::Qualified
HTMLTableRowElement::~HTMLTableRowElement() = default;
// https://html.spec.whatwg.org/multipage/tables.html#dom-tr-cells
-NonnullRefPtr<DOM::HTMLCollection> HTMLTableRowElement::cells() const
+JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableRowElement::cells() const
{
// The cells attribute must return an HTMLCollection rooted at this tr element,
// whose filter matches only td and th elements that are children of the tr element.
@@ -42,7 +42,7 @@ int HTMLTableRowElement::row_index() const
// or a parent tbody, thead, or tfoot element and a grandparent table element,
// return the index of this tr element in that table element's rows collection.
// If there is no such table element, then the attribute must return −1.
- auto rows_collection = [&]() -> RefPtr<DOM::HTMLCollection> {
+ auto rows_collection = [&]() -> JS::GCPtr<DOM::HTMLCollection> {
if (!parent())
return nullptr;
if (is<HTMLTableElement>(*parent()))
@@ -67,7 +67,7 @@ int HTMLTableRowElement::section_row_index() const
// return the index of the tr element in the parent element's rows collection
// (for tables, that's HTMLTableElement's rows collection; for table sections, that's HTMLTableSectionElement's rows collection).
// If there is no such parent element, then the attribute must return −1.
- auto rows_collection = [&]() -> RefPtr<DOM::HTMLCollection> {
+ auto rows_collection = [&]() -> JS::GCPtr<DOM::HTMLCollection> {
if (!parent())
return nullptr;
if (is<HTMLTableElement>(*parent()))
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h
index 03b6cb1eb2..9a31461347 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h
@@ -16,7 +16,7 @@ class HTMLTableRowElement final : public HTMLElement {
public:
virtual ~HTMLTableRowElement() override;
- NonnullRefPtr<DOM::HTMLCollection> cells() const;
+ JS::NonnullGCPtr<DOM::HTMLCollection> cells() const;
int row_index() const;
int section_row_index() const;
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp
index 6e66c9d33c..cc227cae63 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp
@@ -24,7 +24,7 @@ HTMLTableSectionElement::HTMLTableSectionElement(DOM::Document& document, DOM::Q
HTMLTableSectionElement::~HTMLTableSectionElement() = default;
// https://html.spec.whatwg.org/multipage/tables.html#dom-tbody-rows
-NonnullRefPtr<DOM::HTMLCollection> HTMLTableSectionElement::rows() const
+JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableSectionElement::rows() const
{
// The rows attribute must return an HTMLCollection rooted at this element,
// whose filter matches only tr elements that are children of this element.
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h
index 112a92a9ff..69974cb09e 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h
@@ -17,7 +17,7 @@ class HTMLTableSectionElement final : public HTMLElement {
public:
virtual ~HTMLTableSectionElement() override;
- NonnullRefPtr<DOM::HTMLCollection> rows() const;
+ JS::NonnullGCPtr<DOM::HTMLCollection> rows() const;
DOM::ExceptionOr<JS::NonnullGCPtr<HTMLTableRowElement>> insert_row(long index);
DOM::ExceptionOr<void> delete_row(long index);
diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake
index 6574bade9f..ff76850e89 100644
--- a/Userland/Libraries/LibWeb/idl_files.cmake
+++ b/Userland/Libraries/LibWeb/idl_files.cmake
@@ -37,7 +37,7 @@ libweb_js_wrapper(DOM/DOMTokenList NO_INSTANCE)
libweb_js_wrapper(DOM/Element NO_INSTANCE)
libweb_js_wrapper(DOM/Event NO_INSTANCE)
libweb_js_wrapper(DOM/EventTarget NO_INSTANCE)
-libweb_js_wrapper(DOM/HTMLCollection)
+libweb_js_wrapper(DOM/HTMLCollection NO_INSTANCE)
libweb_js_wrapper(DOM/MutationRecord NO_INSTANCE)
libweb_js_wrapper(DOM/MutationObserver NO_INSTANCE)
libweb_js_wrapper(DOM/NamedNodeMap NO_INSTANCE)
@@ -112,7 +112,7 @@ libweb_js_wrapper(HTML/HTMLObjectElement NO_INSTANCE)
libweb_js_wrapper(HTML/HTMLOListElement NO_INSTANCE)
libweb_js_wrapper(HTML/HTMLOptGroupElement NO_INSTANCE)
libweb_js_wrapper(HTML/HTMLOptionElement NO_INSTANCE)
-libweb_js_wrapper(HTML/HTMLOptionsCollection)
+libweb_js_wrapper(HTML/HTMLOptionsCollection NO_INSTANCE)
libweb_js_wrapper(HTML/HTMLOutputElement NO_INSTANCE)
libweb_js_wrapper(HTML/HTMLParagraphElement NO_INSTANCE)
libweb_js_wrapper(HTML/HTMLParamElement NO_INSTANCE)