1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +00:00

LibWeb: Move DOMException from DOM/ to WebIDL/

This commit is contained in:
Linus Groh 2022-09-25 17:28:46 +01:00
parent ad04d7ac9b
commit bbaa05fcf9
49 changed files with 206 additions and 203 deletions

View file

@ -137,11 +137,11 @@ WebIDL::ExceptionOr<void> Range::set_start_or_end(Node& node, u32 offset, StartO
// 1. If node is a doctype, then throw an "InvalidNodeTypeError" DOMException.
if (is<DocumentType>(node))
return InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType.");
return WebIDL::InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType.");
// 2. If offset is greater than nodes length, then throw an "IndexSizeError" DOMException.
if (offset > node.length())
return IndexSizeError::create(global_object(), String::formatted("Node does not contain a child at offset {}", offset));
return WebIDL::IndexSizeError::create(global_object(), String::formatted("Node does not contain a child at offset {}", offset));
// 3. Let bp be the boundary point (node, offset).
@ -196,7 +196,7 @@ WebIDL::ExceptionOr<void> Range::set_start_before(Node& node)
// 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException.
if (!parent)
return InvalidNodeTypeError::create(global_object(), "Given node has no parent.");
return WebIDL::InvalidNodeTypeError::create(global_object(), "Given node has no parent.");
// 3. Set the start of this to boundary point (parent, nodes index).
return set_start_or_end(*parent, node.index(), StartOrEnd::Start);
@ -210,7 +210,7 @@ WebIDL::ExceptionOr<void> Range::set_start_after(Node& node)
// 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException.
if (!parent)
return InvalidNodeTypeError::create(global_object(), "Given node has no parent.");
return WebIDL::InvalidNodeTypeError::create(global_object(), "Given node has no parent.");
// 3. Set the start of this to boundary point (parent, nodes index plus 1).
return set_start_or_end(*parent, node.index() + 1, StartOrEnd::Start);
@ -224,7 +224,7 @@ WebIDL::ExceptionOr<void> Range::set_end_before(Node& node)
// 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException.
if (!parent)
return InvalidNodeTypeError::create(global_object(), "Given node has no parent.");
return WebIDL::InvalidNodeTypeError::create(global_object(), "Given node has no parent.");
// 3. Set the end of this to boundary point (parent, nodes index).
return set_start_or_end(*parent, node.index(), StartOrEnd::End);
@ -238,7 +238,7 @@ WebIDL::ExceptionOr<void> Range::set_end_after(Node& node)
// 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException.
if (!parent)
return InvalidNodeTypeError::create(global_object(), "Given node has no parent.");
return WebIDL::InvalidNodeTypeError::create(global_object(), "Given node has no parent.");
// 3. Set the end of this to boundary point (parent, nodes index plus 1).
return set_start_or_end(*parent, node.index() + 1, StartOrEnd::End);
@ -254,11 +254,11 @@ WebIDL::ExceptionOr<i16> Range::compare_boundary_points(u16 how, Range const& so
// - END_TO_START,
// then throw a "NotSupportedError" DOMException.
if (how != HowToCompareBoundaryPoints::START_TO_START && how != HowToCompareBoundaryPoints::START_TO_END && how != HowToCompareBoundaryPoints::END_TO_END && how != HowToCompareBoundaryPoints::END_TO_START)
return NotSupportedError::create(global_object(), String::formatted("Expected 'how' to be one of START_TO_START (0), START_TO_END (1), END_TO_END (2) or END_TO_START (3), got {}", how));
return WebIDL::NotSupportedError::create(global_object(), String::formatted("Expected 'how' to be one of START_TO_START (0), START_TO_END (1), END_TO_END (2) or END_TO_START (3), got {}", how));
// 2. If thiss root is not the same as sourceRanges root, then throw a "WrongDocumentError" DOMException.
if (&root() != &source_range.root())
return WrongDocumentError::create(global_object(), "This range is not in the same tree as the source range.");
return WebIDL::WrongDocumentError::create(global_object(), "This range is not in the same tree as the source range.");
JS::GCPtr<Node> this_point_node;
u32 this_point_offset = 0;
@ -339,7 +339,7 @@ WebIDL::ExceptionOr<void> Range::select(Node& node)
// 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException.
if (!parent)
return InvalidNodeTypeError::create(global_object(), "Given node has no parent.");
return WebIDL::InvalidNodeTypeError::create(global_object(), "Given node has no parent.");
// 3. Let index be nodes index.
auto index = node.index();
@ -381,7 +381,7 @@ WebIDL::ExceptionOr<void> Range::select_node_contents(Node const& node)
{
// 1. If node is a doctype, throw an "InvalidNodeTypeError" DOMException.
if (is<DocumentType>(node))
return InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType.");
return WebIDL::InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType.");
// 2. Let length be the length of node.
auto length = node.length();
@ -474,11 +474,11 @@ WebIDL::ExceptionOr<bool> Range::is_point_in_range(Node const& node, u32 offset)
// 2. If node is a doctype, then throw an "InvalidNodeTypeError" DOMException.
if (is<DocumentType>(node))
return InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType.");
return WebIDL::InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType.");
// 3. If offset is greater than nodes length, then throw an "IndexSizeError" DOMException.
if (offset > node.length())
return IndexSizeError::create(global_object(), String::formatted("Node does not contain a child at offset {}", offset));
return WebIDL::IndexSizeError::create(global_object(), String::formatted("Node does not contain a child at offset {}", offset));
// 4. If (node, offset) is before start or after end, return false.
auto relative_position_to_start = position_of_boundary_point_relative_to_other_boundary_point(node, offset, m_start_container, m_start_offset);
@ -495,15 +495,15 @@ WebIDL::ExceptionOr<i16> Range::compare_point(Node const& node, u32 offset) cons
{
// 1. If nodes root is different from thiss root, then throw a "WrongDocumentError" DOMException.
if (&node.root() != &root())
return WrongDocumentError::create(global_object(), "Given node is not in the same document as the range.");
return WebIDL::WrongDocumentError::create(global_object(), "Given node is not in the same document as the range.");
// 2. If node is a doctype, then throw an "InvalidNodeTypeError" DOMException.
if (is<DocumentType>(node))
return InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType.");
return WebIDL::InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType.");
// 3. If offset is greater than nodes length, then throw an "IndexSizeError" DOMException.
if (offset > node.length())
return IndexSizeError::create(global_object(), String::formatted("Node does not contain a child at offset {}", offset));
return WebIDL::IndexSizeError::create(global_object(), String::formatted("Node does not contain a child at offset {}", offset));
// 4. If (node, offset) is before start, return 1.
auto relative_position_to_start = position_of_boundary_point_relative_to_other_boundary_point(node, offset, m_start_container, m_start_offset);
@ -636,7 +636,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
// 12. If any member of contained children is a doctype, then throw a "HierarchyRequestError" DOMException.
for (auto const& child : contained_children) {
if (is<DocumentType>(*child))
return DOM::HierarchyRequestError::create(global_object(), "Contained child is a DocumentType");
return WebIDL::HierarchyRequestError::create(global_object(), "Contained child is a DocumentType");
}
JS::GCPtr<Node> new_node;
@ -783,7 +783,7 @@ WebIDL::ExceptionOr<void> Range::insert(JS::NonnullGCPtr<Node> node)
if ((is<ProcessingInstruction>(*m_start_container) || is<Comment>(*m_start_container))
|| (is<Text>(*m_start_container) && !m_start_container->parent_node())
|| m_start_container.ptr() == node.ptr()) {
return DOM::HierarchyRequestError::create(global_object(), "Range has inappropriate start node for insertion");
return WebIDL::HierarchyRequestError::create(global_object(), "Range has inappropriate start node for insertion");
}
// 2. Let referenceNode be null.
@ -854,11 +854,11 @@ WebIDL::ExceptionOr<void> Range::surround_contents(JS::NonnullGCPtr<Node> new_pa
if (is<Text>(*end_non_text_node))
end_non_text_node = end_non_text_node->parent_node();
if (start_non_text_node != end_non_text_node)
return InvalidStateError::create(global_object(), "Non-Text node is partially contained in range.");
return WebIDL::InvalidStateError::create(global_object(), "Non-Text node is partially contained in range.");
// 2. If newParent is a Document, DocumentType, or DocumentFragment node, then throw an "InvalidNodeTypeError" DOMException.
if (is<Document>(*new_parent) || is<DocumentType>(*new_parent) || is<DocumentFragment>(*new_parent))
return InvalidNodeTypeError::create(global_object(), "Invalid parent node type");
return WebIDL::InvalidNodeTypeError::create(global_object(), "Invalid parent node type");
// 3. Let fragment be the result of extracting this.
auto fragment = TRY(extract());
@ -962,7 +962,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_content
// 12. If any member of contained children is a doctype, then throw a "HierarchyRequestError" DOMException.
for (auto const& child : contained_children) {
if (is<DocumentType>(*child))
return DOM::HierarchyRequestError::create(global_object(), "Contained child is a DocumentType");
return WebIDL::HierarchyRequestError::create(global_object(), "Contained child is a DocumentType");
}
// 13. If first partially contained child is a CharacterData node, then: