diff options
author | Luke <luke.wilde@live.co.uk> | 2021-05-07 00:54:20 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-07 08:53:37 +0200 |
commit | df52040ce9ae7ab49b6f1d6d50dacccdce0d0d0a (patch) | |
tree | f4b31d90054aa5c0e18e35ddd699359fec9fe9f8 /Userland | |
parent | b6004a4ce1af1b03718ce836df75e529f86de9c8 (diff) | |
download | serenity-df52040ce9ae7ab49b6f1d6d50dacccdce0d0d0a.zip |
LibWeb: Implement replacing the current body when setting document.body
Also adds an exception check to the append at the end.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 0f652e69a3..2777eed422 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -222,7 +222,9 @@ ExceptionOr<void> Document::set_body(HTML::HTMLElement& new_body) auto* existing_body = body(); if (existing_body) { - TODO(); + auto replace_result = existing_body->parent()->replace_child(new_body, *existing_body); + if (replace_result.is_exception()) + return NonnullRefPtr<DOMException>(replace_result.exception()); return {}; } @@ -230,7 +232,9 @@ ExceptionOr<void> Document::set_body(HTML::HTMLElement& new_body) if (!document_element) return DOM::HierarchyRequestError::create("Missing document element"); - document_element->append_child(new_body); + auto append_result = document_element->append_child(new_body); + if (append_result.is_exception()) + return NonnullRefPtr<DOMException>(append_result.exception()); return {}; } |