LibWeb: Make Element::is_document_element() slightly nicer

By following the spec more closely, we can actually make this function
a bit more efficient (by comparing the parent against the document
instead of looking for the first element child of the document).
This commit is contained in:
Andreas Kling 2024-03-13 21:27:29 +01:00
parent bbf67faa95
commit 0c76c7ee36
Notes: sideshowbarker 2024-07-17 10:05:47 +09:00

View File

@ -777,7 +777,8 @@ bool Element::is_target() const
// https://dom.spec.whatwg.org/#document-element // https://dom.spec.whatwg.org/#document-element
bool Element::is_document_element() const bool Element::is_document_element() const
{ {
return document().document_element() == this; // The document element of a document is the element whose parent is that document, if it exists; otherwise null.
return parent() == &document();
} }
JS::NonnullGCPtr<HTMLCollection> Element::get_elements_by_class_name(StringView class_names) JS::NonnullGCPtr<HTMLCollection> Element::get_elements_by_class_name(StringView class_names)