浏览代码

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).
Andreas Kling 1 年之前
父节点
当前提交
0c76c7ee36
共有 1 个文件被更改,包括 2 次插入1 次删除
  1. 2 1
      Userland/Libraries/LibWeb/DOM/Element.cpp

+ 2 - 1
Userland/Libraries/LibWeb/DOM/Element.cpp

@@ -777,7 +777,8 @@ bool Element::is_target() const
 // https://dom.spec.whatwg.org/#document-element
 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)