mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +00:00
LibWeb: Make DOMException GC-allocated
This commit is contained in:
parent
0e47754ac8
commit
497ead37bc
58 changed files with 307 additions and 278 deletions
|
@ -310,24 +310,24 @@ ExceptionOr<void> Node::ensure_pre_insertion_validity(JS::NonnullGCPtr<Node> nod
|
|||
{
|
||||
// 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))
|
||||
return DOM::HierarchyRequestError::create("Can only insert into a document, document fragment or element");
|
||||
return DOM::HierarchyRequestError::create(global_object(), "Can only insert into a document, document fragment or element");
|
||||
|
||||
// 2. If node is a host-including inclusive ancestor of parent, then throw a "HierarchyRequestError" DOMException.
|
||||
if (node->is_host_including_inclusive_ancestor_of(*this))
|
||||
return DOM::HierarchyRequestError::create("New node is an ancestor of this node");
|
||||
return DOM::HierarchyRequestError::create(global_object(), "New node is an ancestor of this node");
|
||||
|
||||
// 3. If child is non-null and its parent is not parent, then throw a "NotFoundError" DOMException.
|
||||
if (child && child->parent() != this)
|
||||
return DOM::NotFoundError::create("This node is not the parent of the given child");
|
||||
return DOM::NotFoundError::create(global_object(), "This node is not the parent of the given child");
|
||||
|
||||
// FIXME: All the following "Invalid node type for insertion" messages could be more descriptive.
|
||||
// 4. If node is not a DocumentFragment, DocumentType, Element, or CharacterData node, then throw a "HierarchyRequestError" DOMException.
|
||||
if (!is<DocumentFragment>(*node) && !is<DocumentType>(*node) && !is<Element>(*node) && !is<Text>(*node) && !is<Comment>(*node) && !is<ProcessingInstruction>(*node))
|
||||
return DOM::HierarchyRequestError::create("Invalid node type for insertion");
|
||||
return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion");
|
||||
|
||||
// 5. If either node is a Text node and parent is a document, or node is a doctype and parent is not a document, then throw a "HierarchyRequestError" DOMException.
|
||||
if ((is<Text>(*node) && is<Document>(this)) || (is<DocumentType>(*node) && !is<Document>(this)))
|
||||
return DOM::HierarchyRequestError::create("Invalid node type for insertion");
|
||||
return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion");
|
||||
|
||||
// 6. If parent is a document, and any of the statements below, switched on the interface node implements, are true, then throw a "HierarchyRequestError" DOMException.
|
||||
if (is<Document>(this)) {
|
||||
|
@ -338,18 +338,18 @@ ExceptionOr<void> Node::ensure_pre_insertion_validity(JS::NonnullGCPtr<Node> nod
|
|||
auto node_element_child_count = verify_cast<DocumentFragment>(*node).child_element_count();
|
||||
if ((node_element_child_count > 1 || node->has_child_of_type<Text>())
|
||||
|| (node_element_child_count == 1 && (has_child_of_type<Element>() || is<DocumentType>(child.ptr()) || (child && child->has_following_node_of_type_in_tree_order<DocumentType>())))) {
|
||||
return DOM::HierarchyRequestError::create("Invalid node type for insertion");
|
||||
return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion");
|
||||
}
|
||||
} else if (is<Element>(*node)) {
|
||||
// Element
|
||||
// If parent has an element child, child is a doctype, or child is non-null and a doctype is following child.
|
||||
if (has_child_of_type<Element>() || is<DocumentType>(child.ptr()) || (child && child->has_following_node_of_type_in_tree_order<DocumentType>()))
|
||||
return DOM::HierarchyRequestError::create("Invalid node type for insertion");
|
||||
return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion");
|
||||
} else if (is<DocumentType>(*node)) {
|
||||
// DocumentType
|
||||
// parent has a doctype child, child is non-null and an element is preceding child, or child is null and parent has an element child.
|
||||
if (has_child_of_type<DocumentType>() || (child && child->has_preceding_node_of_type_in_tree_order<Element>()) || (!child && has_child_of_type<Element>()))
|
||||
return DOM::HierarchyRequestError::create("Invalid node type for insertion");
|
||||
return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -482,7 +482,7 @@ ExceptionOr<JS::NonnullGCPtr<Node>> Node::pre_remove(JS::NonnullGCPtr<Node> chil
|
|||
{
|
||||
// 1. If child’s parent is not parent, then throw a "NotFoundError" DOMException.
|
||||
if (child->parent() != this)
|
||||
return DOM::NotFoundError::create("Child does not belong to this node");
|
||||
return DOM::NotFoundError::create(global_object(), "Child does not belong to this node");
|
||||
|
||||
// 2. Remove child.
|
||||
child->remove();
|
||||
|
@ -607,25 +607,25 @@ ExceptionOr<JS::NonnullGCPtr<Node>> Node::replace_child(JS::NonnullGCPtr<Node> n
|
|||
{
|
||||
// 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))
|
||||
return DOM::HierarchyRequestError::create("Can only insert into a document, document fragment or element");
|
||||
return DOM::HierarchyRequestError::create(global_object(), "Can only insert into a document, document fragment or element");
|
||||
|
||||
// 2. If node is a host-including inclusive ancestor of parent, then throw a "HierarchyRequestError" DOMException.
|
||||
if (node->is_host_including_inclusive_ancestor_of(*this))
|
||||
return DOM::HierarchyRequestError::create("New node is an ancestor of this node");
|
||||
return DOM::HierarchyRequestError::create(global_object(), "New node is an ancestor of this node");
|
||||
|
||||
// 3. If child’s parent is not parent, then throw a "NotFoundError" DOMException.
|
||||
if (child->parent() != this)
|
||||
return DOM::NotFoundError::create("This node is not the parent of the given child");
|
||||
return DOM::NotFoundError::create(global_object(), "This node is not the parent of the given child");
|
||||
|
||||
// FIXME: All the following "Invalid node type for insertion" messages could be more descriptive.
|
||||
|
||||
// 4. If node is not a DocumentFragment, DocumentType, Element, or CharacterData node, then throw a "HierarchyRequestError" DOMException.
|
||||
if (!is<DocumentFragment>(*node) && !is<DocumentType>(*node) && !is<Element>(*node) && !is<Text>(*node) && !is<Comment>(*node) && !is<ProcessingInstruction>(*node))
|
||||
return DOM::HierarchyRequestError::create("Invalid node type for insertion");
|
||||
return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion");
|
||||
|
||||
// 5. If either node is a Text node and parent is a document, or node is a doctype and parent is not a document, then throw a "HierarchyRequestError" DOMException.
|
||||
if ((is<Text>(*node) && is<Document>(this)) || (is<DocumentType>(*node) && !is<Document>(this)))
|
||||
return DOM::HierarchyRequestError::create("Invalid node type for insertion");
|
||||
return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion");
|
||||
|
||||
// If parent is a document, and any of the statements below, switched on the interface node implements, are true, then throw a "HierarchyRequestError" DOMException.
|
||||
if (is<Document>(this)) {
|
||||
|
@ -636,18 +636,18 @@ ExceptionOr<JS::NonnullGCPtr<Node>> Node::replace_child(JS::NonnullGCPtr<Node> n
|
|||
auto node_element_child_count = verify_cast<DocumentFragment>(*node).child_element_count();
|
||||
if ((node_element_child_count > 1 || node->has_child_of_type<Text>())
|
||||
|| (node_element_child_count == 1 && (first_child_of_type<Element>() != child || child->has_following_node_of_type_in_tree_order<DocumentType>()))) {
|
||||
return DOM::HierarchyRequestError::create("Invalid node type for insertion");
|
||||
return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion");
|
||||
}
|
||||
} else if (is<Element>(*node)) {
|
||||
// Element
|
||||
// parent has an element child that is not child or a doctype is following child.
|
||||
if (first_child_of_type<Element>() != child || child->has_following_node_of_type_in_tree_order<DocumentType>())
|
||||
return DOM::HierarchyRequestError::create("Invalid node type for insertion");
|
||||
return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion");
|
||||
} else if (is<DocumentType>(*node)) {
|
||||
// DocumentType
|
||||
// parent has a doctype child that is not child, or an element is preceding child.
|
||||
if (first_child_of_type<DocumentType>() != node || child->has_preceding_node_of_type_in_tree_order<Element>())
|
||||
return DOM::HierarchyRequestError::create("Invalid node type for insertion");
|
||||
return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -791,7 +791,7 @@ 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))
|
||||
return NotSupportedError::create("Cannot clone shadow root");
|
||||
return NotSupportedError::create(global_object(), "Cannot clone shadow root");
|
||||
|
||||
// 2. Return a clone of this, with the clone children flag set if deep is true.
|
||||
return clone_node(nullptr, deep);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue