1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 20:07:36 +00:00

LibWeb: Use DOMException in Document::set_body()

This commit is contained in:
Linus Groh 2021-02-20 00:42:25 +01:00 committed by Andreas Kling
parent 0d196d14d2
commit dd621cc650
2 changed files with 12 additions and 11 deletions

View file

@ -34,12 +34,14 @@
#include <LibWeb/Bindings/WindowObject.h> #include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/CSS/StyleResolver.h> #include <LibWeb/CSS/StyleResolver.h>
#include <LibWeb/DOM/Comment.h> #include <LibWeb/DOM/Comment.h>
#include <LibWeb/DOM/DOMException.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/DocumentFragment.h> #include <LibWeb/DOM/DocumentFragment.h>
#include <LibWeb/DOM/DocumentType.h> #include <LibWeb/DOM/DocumentType.h>
#include <LibWeb/DOM/Element.h> #include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/ElementFactory.h> #include <LibWeb/DOM/ElementFactory.h>
#include <LibWeb/DOM/Event.h> #include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/Text.h> #include <LibWeb/DOM/Text.h>
#include <LibWeb/DOM/Window.h> #include <LibWeb/DOM/Window.h>
#include <LibWeb/Dump.h> #include <LibWeb/Dump.h>
@ -215,28 +217,26 @@ const HTML::HTMLElement* Document::body() const
return nullptr; return nullptr;
} }
void Document::set_body(HTML::HTMLElement& new_body) // https://html.spec.whatwg.org/multipage/dom.html#dom-document-body
ExceptionOr<void> Document::set_body(HTML::HTMLElement& new_body)
{ {
if (!is<HTML::HTMLBodyElement>(new_body) && !is<HTML::HTMLFrameSetElement>(new_body)) { if (!is<HTML::HTMLBodyElement>(new_body) && !is<HTML::HTMLFrameSetElement>(new_body))
// FIXME: throw a "HierarchyRequestError" DOMException. return DOM::HierarchyRequestError::create("Invalid document body element, must be 'body' or 'frameset'");
return;
}
auto* existing_body = body(); auto* existing_body = body();
if (existing_body) { if (existing_body) {
TODO(); TODO();
return; return {};
} }
auto* html = document_element(); auto* html = document_element();
if (!html) { if (!html)
// FIXME: throw a "HierarchyRequestError" DOMException. return DOM::HierarchyRequestError::create("Missing document element");
return;
}
// FIXME: Implement this once there's a non-const first_child_of_type: // 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." // "Otherwise, the body element is null, but there's a document element. Append the new value to the document element."
TODO(); TODO();
return {};
} }
String Document::title() const String Document::title() const

View file

@ -41,6 +41,7 @@
#include <LibWeb/CSS/StyleSheet.h> #include <LibWeb/CSS/StyleSheet.h>
#include <LibWeb/CSS/StyleSheetList.h> #include <LibWeb/CSS/StyleSheetList.h>
#include <LibWeb/DOM/DOMImplementation.h> #include <LibWeb/DOM/DOMImplementation.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/NonElementParentNode.h> #include <LibWeb/DOM/NonElementParentNode.h>
#include <LibWeb/DOM/ParentNode.h> #include <LibWeb/DOM/ParentNode.h>
#include <LibWeb/HTML/HTMLScriptElement.h> #include <LibWeb/HTML/HTMLScriptElement.h>
@ -105,7 +106,7 @@ public:
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;
void set_body(HTML::HTMLElement& new_body); ExceptionOr<void> set_body(HTML::HTMLElement& new_body);
String title() const; String title() const;
void set_title(const String&); void set_title(const String&);