mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02:00
LibWeb: Move ExceptionOr from DOM/ to WebIDL/
This is a concept fully defined in the Web IDL spec and doesn't belong in the DOM directory/namespace - not even DOMException, despite the name :^)
This commit is contained in:
Notes:
sideshowbarker
2024-07-17 06:38:13 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/ad04d7ac9b Pull-request: https://github.com/SerenityOS/serenity/pull/15357 Reviewed-by: https://github.com/awesomekling ✅
@@ -311,7 +311,7 @@ Element const* Node::parent_element() const
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity
|
||||
ExceptionOr<void> Node::ensure_pre_insertion_validity(JS::NonnullGCPtr<Node> node, JS::GCPtr<Node> child) const
|
||||
WebIDL::ExceptionOr<void> Node::ensure_pre_insertion_validity(JS::NonnullGCPtr<Node> node, JS::GCPtr<Node> child) const
|
||||
{
|
||||
// 1. If parent is not a Document, DocumentFragment, or Element node, then throw a "HierarchyRequestError" DOMException.
|
||||
if (!is<Document>(this) && !is<DocumentFragment>(this) && !is<Element>(this))
|
||||
@@ -456,7 +456,7 @@ void Node::insert_before(JS::NonnullGCPtr<Node> node, JS::GCPtr<Node> child, boo
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-node-pre-insert
|
||||
ExceptionOr<JS::NonnullGCPtr<Node>> Node::pre_insert(JS::NonnullGCPtr<Node> node, JS::GCPtr<Node> child)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::pre_insert(JS::NonnullGCPtr<Node> node, JS::GCPtr<Node> child)
|
||||
{
|
||||
// 1. Ensure pre-insertion validity of node into parent before child.
|
||||
TRY(ensure_pre_insertion_validity(node, child));
|
||||
@@ -476,14 +476,14 @@ ExceptionOr<JS::NonnullGCPtr<Node>> Node::pre_insert(JS::NonnullGCPtr<Node> node
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-node-removechild
|
||||
ExceptionOr<JS::NonnullGCPtr<Node>> Node::remove_child(JS::NonnullGCPtr<Node> child)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::remove_child(JS::NonnullGCPtr<Node> child)
|
||||
{
|
||||
// The removeChild(child) method steps are to return the result of pre-removing child from this.
|
||||
return pre_remove(child);
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-node-pre-remove
|
||||
ExceptionOr<JS::NonnullGCPtr<Node>> Node::pre_remove(JS::NonnullGCPtr<Node> child)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::pre_remove(JS::NonnullGCPtr<Node> child)
|
||||
{
|
||||
// 1. If child’s parent is not parent, then throw a "NotFoundError" DOMException.
|
||||
if (child->parent() != this)
|
||||
@@ -497,7 +497,7 @@ ExceptionOr<JS::NonnullGCPtr<Node>> Node::pre_remove(JS::NonnullGCPtr<Node> chil
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-node-append
|
||||
ExceptionOr<JS::NonnullGCPtr<Node>> Node::append_child(JS::NonnullGCPtr<Node> node)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::append_child(JS::NonnullGCPtr<Node> node)
|
||||
{
|
||||
// To append a node to a parent, pre-insert node into parent before null.
|
||||
return pre_insert(node, nullptr);
|
||||
@@ -608,7 +608,7 @@ void Node::remove(bool suppress_observers)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-node-replace
|
||||
ExceptionOr<JS::NonnullGCPtr<Node>> Node::replace_child(JS::NonnullGCPtr<Node> node, JS::NonnullGCPtr<Node> child)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::replace_child(JS::NonnullGCPtr<Node> node, JS::NonnullGCPtr<Node> child)
|
||||
{
|
||||
// If parent is not a Document, DocumentFragment, or Element node, then throw a "HierarchyRequestError" DOMException.
|
||||
if (!is<Document>(this) && !is<DocumentFragment>(this) && !is<Element>(this))
|
||||
@@ -792,7 +792,7 @@ JS::NonnullGCPtr<Node> Node::clone_node(Document* document, bool clone_children)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-node-clonenode
|
||||
ExceptionOr<JS::NonnullGCPtr<Node>> Node::clone_node_binding(bool deep)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::clone_node_binding(bool deep)
|
||||
{
|
||||
// 1. If this is a shadow root, then throw a "NotSupportedError" DOMException.
|
||||
if (is<ShadowRoot>(*this))
|
||||
|
||||
Reference in New Issue
Block a user