소스 검색

LibWeb: Support assigning to document.body when it is null

Andreas Kling 4 년 전
부모
커밋
b126ead34e
2개의 변경된 파일10개의 추가작업 그리고 5개의 파일을 삭제
  1. 8 5
      Userland/Libraries/LibWeb/DOM/Document.cpp
  2. 2 0
      Userland/Libraries/LibWeb/DOM/Document.h

+ 8 - 5
Userland/Libraries/LibWeb/DOM/Document.cpp

@@ -183,6 +183,11 @@ bool Document::is_child_allowed(const Node& node) const
     }
     }
 }
 }
 
 
+Element* Document::document_element()
+{
+    return first_child_of_type<Element>();
+}
+
 const Element* Document::document_element() const
 const Element* Document::document_element() const
 {
 {
     return first_child_of_type<Element>();
     return first_child_of_type<Element>();
@@ -230,13 +235,11 @@ ExceptionOr<void> Document::set_body(HTML::HTMLElement& new_body)
         return {};
         return {};
     }
     }
 
 
-    auto* html = document_element();
-    if (!html)
+    auto* document_element = this->document_element();
+    if (!document_element)
         return DOM::HierarchyRequestError::create("Missing document element");
         return DOM::HierarchyRequestError::create("Missing document element");
 
 
-    // FIXME: Implement this once there's a non-const first_child_of_type:
-    //        "Otherwise, the body element is null, but there's a document element. Append the new value to the document element."
-    TODO();
+    document_element->append_child(new_body);
     return {};
     return {};
 }
 }
 
 

+ 2 - 0
Userland/Libraries/LibWeb/DOM/Document.h

@@ -102,7 +102,9 @@ public:
     Node* inspected_node() { return m_inspected_node; }
     Node* inspected_node() { return m_inspected_node; }
     const Node* inspected_node() const { return m_inspected_node; }
     const Node* inspected_node() const { return m_inspected_node; }
 
 
+    Element* document_element();
     const Element* document_element() const;
     const Element* document_element() const;
+
     const HTML::HTMLHtmlElement* html_element() const;
     const HTML::HTMLHtmlElement* html_element() const;
     const HTML::HTMLHeadElement* head() const;
     const HTML::HTMLHeadElement* head() const;
     const HTML::HTMLElement* body() const;
     const HTML::HTMLElement* body() const;