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

LibWeb: Port DOMException interface from DeprecatedString to String

This commit is contained in:
Shannon Booth 2023-09-06 16:03:01 +12:00 committed by Tim Flynn
parent bcb6851c07
commit 41928c2902
65 changed files with 296 additions and 296 deletions

View file

@ -165,11 +165,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 WebIDL::InvalidNodeTypeError::create(realm(), "Node cannot be a DocumentType.");
return WebIDL::InvalidNodeTypeError::create(realm(), "Node cannot be a DocumentType."_fly_string);
// 2. If offset is greater than nodes length, then throw an "IndexSizeError" DOMException.
if (offset > node.length())
return WebIDL::IndexSizeError::create(realm(), DeprecatedString::formatted("Node does not contain a child at offset {}", offset));
return WebIDL::IndexSizeError::create(realm(), MUST(String::formatted("Node does not contain a child at offset {}", offset)));
// 3. Let bp be the boundary point (node, offset).
@ -225,7 +225,7 @@ WebIDL::ExceptionOr<void> Range::set_start_before(Node& node)
// 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException.
if (!parent)
return WebIDL::InvalidNodeTypeError::create(realm(), "Given node has no parent.");
return WebIDL::InvalidNodeTypeError::create(realm(), "Given node has no parent."_fly_string);
// 3. Set the start of this to boundary point (parent, nodes index).
return set_start_or_end(*parent, node.index(), StartOrEnd::Start);
@ -239,7 +239,7 @@ WebIDL::ExceptionOr<void> Range::set_start_after(Node& node)
// 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException.
if (!parent)
return WebIDL::InvalidNodeTypeError::create(realm(), "Given node has no parent.");
return WebIDL::InvalidNodeTypeError::create(realm(), "Given node has no parent."_fly_string);
// 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);
@ -253,7 +253,7 @@ WebIDL::ExceptionOr<void> Range::set_end_before(Node& node)
// 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException.
if (!parent)
return WebIDL::InvalidNodeTypeError::create(realm(), "Given node has no parent.");
return WebIDL::InvalidNodeTypeError::create(realm(), "Given node has no parent."_fly_string);
// 3. Set the end of this to boundary point (parent, nodes index).
return set_start_or_end(*parent, node.index(), StartOrEnd::End);
@ -267,7 +267,7 @@ WebIDL::ExceptionOr<void> Range::set_end_after(Node& node)
// 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException.
if (!parent)
return WebIDL::InvalidNodeTypeError::create(realm(), "Given node has no parent.");
return WebIDL::InvalidNodeTypeError::create(realm(), "Given node has no parent."_fly_string);
// 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);
@ -283,11 +283,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 WebIDL::NotSupportedError::create(realm(), DeprecatedString::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(realm(), MUST(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 WebIDL::WrongDocumentError::create(realm(), "This range is not in the same tree as the source range.");
return WebIDL::WrongDocumentError::create(realm(), "This range is not in the same tree as the source range."_fly_string);
JS::GCPtr<Node> this_point_node;
u32 this_point_offset = 0;
@ -368,7 +368,7 @@ WebIDL::ExceptionOr<void> Range::select(Node& node)
// 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException.
if (!parent)
return WebIDL::InvalidNodeTypeError::create(realm(), "Given node has no parent.");
return WebIDL::InvalidNodeTypeError::create(realm(), "Given node has no parent."_fly_string);
// 3. Let index be nodes index.
auto index = node.index();
@ -411,7 +411,7 @@ WebIDL::ExceptionOr<void> Range::select_node_contents(Node& node)
{
// 1. If node is a doctype, throw an "InvalidNodeTypeError" DOMException.
if (is<DocumentType>(node))
return WebIDL::InvalidNodeTypeError::create(realm(), "Node cannot be a DocumentType.");
return WebIDL::InvalidNodeTypeError::create(realm(), "Node cannot be a DocumentType."_fly_string);
// 2. Let length be the length of node.
auto length = node.length();
@ -505,11 +505,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 WebIDL::InvalidNodeTypeError::create(realm(), "Node cannot be a DocumentType.");
return WebIDL::InvalidNodeTypeError::create(realm(), "Node cannot be a DocumentType."_fly_string);
// 3. If offset is greater than nodes length, then throw an "IndexSizeError" DOMException.
if (offset > node.length())
return WebIDL::IndexSizeError::create(realm(), DeprecatedString::formatted("Node does not contain a child at offset {}", offset));
return WebIDL::IndexSizeError::create(realm(), MUST(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);
@ -526,15 +526,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 WebIDL::WrongDocumentError::create(realm(), "Given node is not in the same document as the range.");
return WebIDL::WrongDocumentError::create(realm(), "Given node is not in the same document as the range."_fly_string);
// 2. If node is a doctype, then throw an "InvalidNodeTypeError" DOMException.
if (is<DocumentType>(node))
return WebIDL::InvalidNodeTypeError::create(realm(), "Node cannot be a DocumentType.");
return WebIDL::InvalidNodeTypeError::create(realm(), "Node cannot be a DocumentType."_fly_string);
// 3. If offset is greater than nodes length, then throw an "IndexSizeError" DOMException.
if (offset > node.length())
return WebIDL::IndexSizeError::create(realm(), DeprecatedString::formatted("Node does not contain a child at offset {}", offset));
return WebIDL::IndexSizeError::create(realm(), MUST(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);
@ -667,7 +667,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 WebIDL::HierarchyRequestError::create(realm(), "Contained child is a DocumentType");
return WebIDL::HierarchyRequestError::create(realm(), "Contained child is a DocumentType"_fly_string);
}
JS::GCPtr<Node> new_node;
@ -814,7 +814,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 WebIDL::HierarchyRequestError::create(realm(), "Range has inappropriate start node for insertion");
return WebIDL::HierarchyRequestError::create(realm(), "Range has inappropriate start node for insertion"_fly_string);
}
// 2. Let referenceNode be null.
@ -885,11 +885,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 WebIDL::InvalidStateError::create(realm(), "Non-Text node is partially contained in range.");
return WebIDL::InvalidStateError::create(realm(), "Non-Text node is partially contained in range."_fly_string);
// 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 WebIDL::InvalidNodeTypeError::create(realm(), "Invalid parent node type");
return WebIDL::InvalidNodeTypeError::create(realm(), "Invalid parent node type"_fly_string);
// 3. Let fragment be the result of extracting this.
auto fragment = TRY(extract());
@ -993,7 +993,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 WebIDL::HierarchyRequestError::create(realm(), "Contained child is a DocumentType");
return WebIDL::HierarchyRequestError::create(realm(), "Contained child is a DocumentType"_fly_string);
}
// 13. If first partially contained child is a CharacterData node, then: