From e8fde316f60ba73530635676e183942a841f8093 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 7 Jun 2023 14:20:57 -0400 Subject: [PATCH] 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. --- Userland/Libraries/LibWeb/DOM/Document.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index fcb2cff399..2e5491a750 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -610,16 +610,21 @@ Element const* Document::document_element() const return first_child_of_type(); } +// 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)) return verify_cast(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;