diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 68cf4fed8d..3cf3a18aa1 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -743,17 +743,13 @@ void Document::adopt_node(Node& node) } // https://dom.spec.whatwg.org/#dom-document-adoptnode -NonnullRefPtr Document::adopt_node_binding(NonnullRefPtr node) +ExceptionOr> Document::adopt_node_binding(NonnullRefPtr node) { - if (is(*node)) { - dbgln("Document::adopt_node_binding: Cannot adopt a document into a document (FIXME: throw as NotSupportedError exception, see issue #6075"); - return node; - } + if (is(*node)) + return DOM ::NotSupportedError::create("Cannot adopt a document into a document"); - if (is(*node)) { - dbgln("Document::adopt_node_binding: Cannot adopt a shadow root into a document (FIXME: throw as HierarchyRequestError exception, see issue #6075"); - return node; - } + if (is(*node)) + return DOM::HierarchyRequestError::create("Cannot adopt a shadow root into a document"); if (is(*node) && downcast(*node).host()) return node; diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index f3fa83b674..27d350b256 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -189,7 +189,7 @@ public: void set_quirks_mode(QuirksMode mode) { m_quirks_mode = mode; } void adopt_node(Node&); - NonnullRefPtr adopt_node_binding(NonnullRefPtr); + ExceptionOr> adopt_node_binding(NonnullRefPtr); const DocumentType* doctype() const; const String& compat_mode() const; diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index a784afd242..90ccf5ef2d 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -280,13 +280,11 @@ void Node::insert_before(NonnullRefPtr node, RefPtr child, bool supp } // https://dom.spec.whatwg.org/#concept-node-pre-insert -NonnullRefPtr Node::pre_insert(NonnullRefPtr node, RefPtr child) +ExceptionOr> Node::pre_insert(NonnullRefPtr node, RefPtr child) { auto validity_result = ensure_pre_insertion_validity(node, child); - if (validity_result.is_exception()) { - dbgln("Node::pre_insert: ensure_pre_insertion_validity failed: {}. (FIXME: throw as exception, see issue #6075)", validity_result.exception().message()); - return node; - } + if (validity_result.is_exception()) + return NonnullRefPtr(validity_result.exception()); auto reference_child = child; if (reference_child == node) @@ -297,12 +295,10 @@ NonnullRefPtr Node::pre_insert(NonnullRefPtr node, RefPtr chil } // https://dom.spec.whatwg.org/#concept-node-pre-remove -NonnullRefPtr Node::pre_remove(NonnullRefPtr child) +ExceptionOr> Node::pre_remove(NonnullRefPtr child) { - if (child->parent() != this) { - dbgln("Node::pre_remove: Child doesn't belong to this node. (FIXME: throw NotFoundError DOMException, see issue #6075)"); - return child; - } + if (child->parent() != this) + return DOM::NotFoundError::create("Child does not belong to this node"); child->remove(); @@ -310,7 +306,7 @@ NonnullRefPtr Node::pre_remove(NonnullRefPtr child) } // https://dom.spec.whatwg.org/#concept-node-append -NonnullRefPtr Node::append_child(NonnullRefPtr node) +ExceptionOr> Node::append_child(NonnullRefPtr node) { return pre_insert(node, nullptr); } diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index f399f88d7f..e4a2927c51 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -93,10 +93,10 @@ public: virtual bool is_editable() const; - NonnullRefPtr pre_insert(NonnullRefPtr, RefPtr); - NonnullRefPtr pre_remove(NonnullRefPtr); + ExceptionOr> pre_insert(NonnullRefPtr, RefPtr); + ExceptionOr> pre_remove(NonnullRefPtr); - NonnullRefPtr append_child(NonnullRefPtr); + ExceptionOr> append_child(NonnullRefPtr); void insert_before(NonnullRefPtr node, RefPtr child, bool suppress_observers = false); void remove(bool suppress_observers = false); void remove_all_children(bool suppress_observers = false);