From b126ead34e706c0cc7042962fca2721e9c4d17d4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 22 Feb 2021 14:00:47 +0100 Subject: [PATCH] LibWeb: Support assigning to document.body when it is null --- Userland/Libraries/LibWeb/DOM/Document.cpp | 13 ++++++++----- Userland/Libraries/LibWeb/DOM/Document.h | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 99e71a9af7..d4f2170f1b 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/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(); +} + const Element* Document::document_element() const { return first_child_of_type(); @@ -230,13 +235,11 @@ ExceptionOr Document::set_body(HTML::HTMLElement& new_body) return {}; } - auto* html = document_element(); - if (!html) + auto* document_element = this->document_element(); + if (!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 {}; } diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index eb6e9cfeb3..e789df05a3 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -102,7 +102,9 @@ public: Node* inspected_node() { return m_inspected_node; } const Node* inspected_node() const { return m_inspected_node; } + Element* document_element(); const Element* document_element() const; + const HTML::HTMLHtmlElement* html_element() const; const HTML::HTMLHeadElement* head() const; const HTML::HTMLElement* body() const;