mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +00:00
LibWeb: Make Document vend the same HTMLCollections every time
This commit is contained in:
parent
1903dff365
commit
fa2dd4cbe3
2 changed files with 55 additions and 33 deletions
|
@ -316,6 +316,14 @@ void Document::visit_edges(Cell::Visitor& visitor)
|
||||||
visitor.visit(m_pending_parsing_blocking_script.ptr());
|
visitor.visit(m_pending_parsing_blocking_script.ptr());
|
||||||
visitor.visit(m_history.ptr());
|
visitor.visit(m_history.ptr());
|
||||||
|
|
||||||
|
visitor.visit(m_applets);
|
||||||
|
visitor.visit(m_anchors);
|
||||||
|
visitor.visit(m_images);
|
||||||
|
visitor.visit(m_embeds);
|
||||||
|
visitor.visit(m_links);
|
||||||
|
visitor.visit(m_forms);
|
||||||
|
visitor.visit(m_scripts);
|
||||||
|
|
||||||
for (auto& script : m_scripts_to_execute_when_parsing_has_finished)
|
for (auto& script : m_scripts_to_execute_when_parsing_has_finished)
|
||||||
visitor.visit(script.ptr());
|
visitor.visit(script.ptr());
|
||||||
for (auto& script : m_scripts_to_execute_as_soon_as_possible)
|
for (auto& script : m_scripts_to_execute_as_soon_as_possible)
|
||||||
|
@ -956,40 +964,43 @@ JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_class_name(FlyString
|
||||||
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-applets
|
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-applets
|
||||||
JS::NonnullGCPtr<HTMLCollection> Document::applets()
|
JS::NonnullGCPtr<HTMLCollection> Document::applets()
|
||||||
{
|
{
|
||||||
// FIXME: This should return the same HTMLCollection object every time,
|
if (!m_applets)
|
||||||
// but that would cause a reference cycle since HTMLCollection refs the root.
|
m_applets = HTMLCollection::create(*this, [](auto&) { return false; });
|
||||||
return HTMLCollection::create(*this, [](auto&) { return false; });
|
return *m_applets;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-anchors
|
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-anchors
|
||||||
JS::NonnullGCPtr<HTMLCollection> Document::anchors()
|
JS::NonnullGCPtr<HTMLCollection> Document::anchors()
|
||||||
{
|
{
|
||||||
// FIXME: This should return the same HTMLCollection object every time,
|
if (!m_anchors) {
|
||||||
// but that would cause a reference cycle since HTMLCollection refs the root.
|
m_anchors = HTMLCollection::create(*this, [](Element const& element) {
|
||||||
return HTMLCollection::create(*this, [](Element const& element) {
|
|
||||||
return is<HTML::HTMLAnchorElement>(element) && element.has_attribute(HTML::AttributeNames::name);
|
return is<HTML::HTMLAnchorElement>(element) && element.has_attribute(HTML::AttributeNames::name);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return *m_anchors;
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-images
|
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-images
|
||||||
JS::NonnullGCPtr<HTMLCollection> Document::images()
|
JS::NonnullGCPtr<HTMLCollection> Document::images()
|
||||||
{
|
{
|
||||||
// FIXME: This should return the same HTMLCollection object every time,
|
if (!m_images) {
|
||||||
// but that would cause a reference cycle since HTMLCollection refs the root.
|
m_images = HTMLCollection::create(*this, [](Element const& element) {
|
||||||
return HTMLCollection::create(*this, [](Element const& element) {
|
|
||||||
return is<HTML::HTMLImageElement>(element);
|
return is<HTML::HTMLImageElement>(element);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return *m_images;
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-embeds
|
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-embeds
|
||||||
JS::NonnullGCPtr<HTMLCollection> Document::embeds()
|
JS::NonnullGCPtr<HTMLCollection> Document::embeds()
|
||||||
{
|
{
|
||||||
// FIXME: This should return the same HTMLCollection object every time,
|
if (!m_embeds) {
|
||||||
// but that would cause a reference cycle since HTMLCollection refs the root.
|
m_embeds = HTMLCollection::create(*this, [](Element const& element) {
|
||||||
return HTMLCollection::create(*this, [](Element const& element) {
|
|
||||||
return is<HTML::HTMLEmbedElement>(element);
|
return is<HTML::HTMLEmbedElement>(element);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return *m_embeds;
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-plugins
|
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-plugins
|
||||||
JS::NonnullGCPtr<HTMLCollection> Document::plugins()
|
JS::NonnullGCPtr<HTMLCollection> Document::plugins()
|
||||||
|
@ -1000,32 +1011,35 @@ JS::NonnullGCPtr<HTMLCollection> Document::plugins()
|
||||||
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-links
|
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-links
|
||||||
JS::NonnullGCPtr<HTMLCollection> Document::links()
|
JS::NonnullGCPtr<HTMLCollection> Document::links()
|
||||||
{
|
{
|
||||||
// FIXME: This should return the same HTMLCollection object every time,
|
if (!m_links) {
|
||||||
// but that would cause a reference cycle since HTMLCollection refs the root.
|
m_links = HTMLCollection::create(*this, [](Element const& element) {
|
||||||
return HTMLCollection::create(*this, [](Element const& element) {
|
|
||||||
return (is<HTML::HTMLAnchorElement>(element) || is<HTML::HTMLAreaElement>(element)) && element.has_attribute(HTML::AttributeNames::href);
|
return (is<HTML::HTMLAnchorElement>(element) || is<HTML::HTMLAreaElement>(element)) && element.has_attribute(HTML::AttributeNames::href);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return *m_links;
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-forms
|
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-forms
|
||||||
JS::NonnullGCPtr<HTMLCollection> Document::forms()
|
JS::NonnullGCPtr<HTMLCollection> Document::forms()
|
||||||
{
|
{
|
||||||
// FIXME: This should return the same HTMLCollection object every time,
|
if (!m_forms) {
|
||||||
// but that would cause a reference cycle since HTMLCollection refs the root.
|
m_forms = HTMLCollection::create(*this, [](Element const& element) {
|
||||||
return HTMLCollection::create(*this, [](Element const& element) {
|
|
||||||
return is<HTML::HTMLFormElement>(element);
|
return is<HTML::HTMLFormElement>(element);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return *m_forms;
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-scripts
|
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-scripts
|
||||||
JS::NonnullGCPtr<HTMLCollection> Document::scripts()
|
JS::NonnullGCPtr<HTMLCollection> Document::scripts()
|
||||||
{
|
{
|
||||||
// FIXME: This should return the same HTMLCollection object every time,
|
if (!m_scripts) {
|
||||||
// but that would cause a reference cycle since HTMLCollection refs the root.
|
m_scripts = HTMLCollection::create(*this, [](Element const& element) {
|
||||||
return HTMLCollection::create(*this, [](Element const& element) {
|
|
||||||
return is<HTML::HTMLScriptElement>(element);
|
return is<HTML::HTMLScriptElement>(element);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return *m_scripts;
|
||||||
|
}
|
||||||
|
|
||||||
Color Document::link_color() const
|
Color Document::link_color() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -486,6 +486,14 @@ private:
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#concept-document-origin
|
// https://dom.spec.whatwg.org/#concept-document-origin
|
||||||
HTML::Origin m_origin;
|
HTML::Origin m_origin;
|
||||||
|
|
||||||
|
JS::GCPtr<HTMLCollection> m_applets;
|
||||||
|
JS::GCPtr<HTMLCollection> m_anchors;
|
||||||
|
JS::GCPtr<HTMLCollection> m_images;
|
||||||
|
JS::GCPtr<HTMLCollection> m_embeds;
|
||||||
|
JS::GCPtr<HTMLCollection> m_links;
|
||||||
|
JS::GCPtr<HTMLCollection> m_forms;
|
||||||
|
JS::GCPtr<HTMLCollection> m_scripts;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue