From dd621cc6503d97e8759dab24ed22606e23314b27 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 20 Feb 2021 00:42:25 +0100 Subject: [PATCH] LibWeb: Use DOMException in Document::set_body() --- Userland/Libraries/LibWeb/DOM/Document.cpp | 20 ++++++++++---------- Userland/Libraries/LibWeb/DOM/Document.h | 3 ++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 2dc6736c3c..81564d29df 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -34,12 +34,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -215,28 +217,26 @@ const HTML::HTMLElement* Document::body() const return nullptr; } -void Document::set_body(HTML::HTMLElement& new_body) +// https://html.spec.whatwg.org/multipage/dom.html#dom-document-body +ExceptionOr Document::set_body(HTML::HTMLElement& new_body) { - if (!is(new_body) && !is(new_body)) { - // FIXME: throw a "HierarchyRequestError" DOMException. - return; - } + if (!is(new_body) && !is(new_body)) + return DOM::HierarchyRequestError::create("Invalid document body element, must be 'body' or 'frameset'"); auto* existing_body = body(); if (existing_body) { TODO(); - return; + return {}; } auto* html = document_element(); - if (!html) { - // FIXME: throw a "HierarchyRequestError" DOMException. - return; - } + if (!html) + 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(); + return {}; } String Document::title() const diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 00a3d00892..f39588dd2d 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -105,7 +106,7 @@ public: const HTML::HTMLHtmlElement* html_element() const; const HTML::HTMLHeadElement* head() const; const HTML::HTMLElement* body() const; - void set_body(HTML::HTMLElement& new_body); + ExceptionOr set_body(HTML::HTMLElement& new_body); String title() const; void set_title(const String&);