1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:07:47 +00:00

LibWeb: Add spec comments to a couple of Document element getters

The implementations are correct as-is. The spec comments are mostly to
help point out that an upcoming getter (the title element) is currently
accessed incorrectly. It is currently implemented like the head element
and searches the "expected" parent head element for its first title
element; instead it should search the document itself. This incorrect
behavior becomes clearer if all of these elements have spec comments.
This commit is contained in:
Timothy Flynn 2023-06-07 14:20:57 -04:00 committed by Andreas Kling
parent efd8176ce3
commit e8fde316f6

View file

@ -610,16 +610,21 @@ Element const* Document::document_element() const
return first_child_of_type<Element>();
}
// https://html.spec.whatwg.org/multipage/dom.html#the-html-element-2
HTML::HTMLHtmlElement* Document::html_element()
{
// The html element of a document is its document element, if it's an html element, and null otherwise.
auto* html = document_element();
if (is<HTML::HTMLHtmlElement>(html))
return verify_cast<HTML::HTMLHtmlElement>(html);
return nullptr;
}
// https://html.spec.whatwg.org/multipage/dom.html#the-head-element-2
HTML::HTMLHeadElement* Document::head()
{
// The head element of a document is the first head element that is a child of the html element, if there is one,
// or null otherwise.
auto* html = html_element();
if (!html)
return nullptr;