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

LibWeb: Handle currently ignored WebIDL::ExceptionOr<T>s

This commit is contained in:
Linus Groh 2022-10-30 17:50:04 +00:00
parent f01d90aa63
commit acfb546048
38 changed files with 153 additions and 149 deletions

View file

@ -78,25 +78,25 @@ WebIDL::ExceptionOr<void> CharacterData::replace_data(size_t offset, size_t coun
// 8. For each live range whose start node is node and start offset is greater than offset but less than or equal to offset plus count, set its start offset to offset.
for (auto& range : Range::live_ranges()) {
if (range->start_container() == this && range->start_offset() > offset && range->start_offset() <= (offset + count))
range->set_start(*range->start_container(), offset);
TRY(range->set_start(*range->start_container(), offset));
}
// 9. For each live range whose end node is node and end offset is greater than offset but less than or equal to offset plus count, set its end offset to offset.
for (auto& range : Range::live_ranges()) {
if (range->end_container() == this && range->end_offset() > offset && range->end_offset() <= (offset + count))
range->set_end(*range->end_container(), range->end_offset());
TRY(range->set_end(*range->end_container(), range->end_offset()));
}
// 10. For each live range whose start node is node and start offset is greater than offset plus count, increase its start offset by datas length and decrease it by count.
for (auto& range : Range::live_ranges()) {
if (range->start_container() == this && range->start_offset() > (offset + count))
range->set_start(*range->start_container(), range->start_offset() + data.length() - count);
TRY(range->set_start(*range->start_container(), range->start_offset() + data.length() - count));
}
// 11. For each live range whose end node is node and end offset is greater than offset plus count, increase its end offset by datas length and decrease it by count.
for (auto& range : Range::live_ranges()) {
if (range->end_container() == this && range->end_offset() > (offset + count))
range->set_end(*range->end_container(), range->end_offset() + data.length() - count);
TRY(range->set_end(*range->end_container(), range->end_offset() + data.length() - count));
}
// 12. If nodes parent is non-null, then run the children changed steps for nodes parent.

View file

@ -51,10 +51,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> DOMImplementation::create_docume
element = TRY(xml_document->create_element_ns(namespace_, qualified_name /* FIXME: and an empty dictionary */));
if (doctype)
xml_document->append_child(*doctype);
TRY(xml_document->append_child(*doctype));
if (element)
xml_document->append_child(*element);
TRY(xml_document->append_child(*element));
xml_document->set_origin(document().origin());
@ -78,24 +78,24 @@ JS::NonnullGCPtr<Document> DOMImplementation::create_html_document(String const&
auto doctype = heap().allocate<DocumentType>(realm(), html_document);
doctype->set_name("html");
html_document->append_child(*doctype);
MUST(html_document->append_child(*doctype));
auto html_element = create_element(html_document, HTML::TagNames::html, Namespace::HTML);
html_document->append_child(html_element);
MUST(html_document->append_child(html_element));
auto head_element = create_element(html_document, HTML::TagNames::head, Namespace::HTML);
html_element->append_child(head_element);
MUST(html_element->append_child(head_element));
if (!title.is_null()) {
auto title_element = create_element(html_document, HTML::TagNames::title, Namespace::HTML);
head_element->append_child(title_element);
MUST(head_element->append_child(title_element));
auto text_node = heap().allocate<Text>(realm(), html_document, title);
title_element->append_child(*text_node);
MUST(title_element->append_child(*text_node));
}
auto body_element = create_element(html_document, HTML::TagNames::body, Namespace::HTML);
html_element->append_child(body_element);
MUST(html_element->append_child(body_element));
html_document->set_origin(document().origin());

View file

@ -227,7 +227,7 @@ void DOMTokenList::set_value(String value)
if (!associated_element)
return;
associated_element->set_attribute(m_associated_attribute, move(value));
MUST(associated_element->set_attribute(m_associated_attribute, move(value)));
}
WebIDL::ExceptionOr<void> DOMTokenList::validate_token(StringView token) const
@ -251,7 +251,7 @@ void DOMTokenList::run_update_steps()
return;
// 2. Set an attribute value for the associated element using associated attributes local name and the result of running the ordered set serializer for token set.
associated_element->set_attribute(m_associated_attribute, value());
MUST(associated_element->set_attribute(m_associated_attribute, value()));
}
JS::Value DOMTokenList::item_value(size_t index) const

View file

@ -415,7 +415,7 @@ WebIDL::ExceptionOr<void> Document::run_the_document_write_steps(String input)
return {};
// 2. Run the document open steps with document.
open();
TRY(open());
}
// 5. Insert input into the input stream just before the insertion point.
@ -664,11 +664,11 @@ void Document::set_title(String const& title)
JS::GCPtr<HTML::HTMLTitleElement> title_element = head_element->first_child_of_type<HTML::HTMLTitleElement>();
if (!title_element) {
title_element = &static_cast<HTML::HTMLTitleElement&>(*create_element(HTML::TagNames::title).release_value());
head_element->append_child(*title_element);
MUST(head_element->append_child(*title_element));
}
title_element->remove_all_children(true);
title_element->append_child(*heap().allocate<Text>(realm(), *this, title));
MUST(title_element->append_child(*heap().allocate<Text>(realm(), *this, title)));
if (auto* page = this->page()) {
if (browsing_context() == &page->top_level_browsing_context())

View file

@ -399,13 +399,13 @@ void Node::insert_before(JS::NonnullGCPtr<Node> node, JS::GCPtr<Node> child, boo
// 1. For each live range whose start node is parent and start offset is greater than childs index, increase its start offset by count.
for (auto& range : Range::live_ranges()) {
if (range->start_container() == this && range->start_offset() > child->index())
range->set_start(*range->start_container(), range->start_offset() + count);
MUST(range->set_start(*range->start_container(), range->start_offset() + count));
}
// 2. For each live range whose end node is parent and end offset is greater than childs index, increase its end offset by count.
for (auto& range : Range::live_ranges()) {
if (range->end_container() == this && range->end_offset() > child->index())
range->set_end(*range->end_container(), range->end_offset() + count);
MUST(range->set_end(*range->end_container(), range->end_offset() + count));
}
}
@ -525,25 +525,25 @@ void Node::remove(bool suppress_observers)
// 4. For each live range whose start node is an inclusive descendant of node, set its start to (parent, index).
for (auto& range : Range::live_ranges()) {
if (range->start_container()->is_inclusive_descendant_of(*this))
range->set_start(*parent, index);
MUST(range->set_start(*parent, index));
}
// 5. For each live range whose end node is an inclusive descendant of node, set its end to (parent, index).
for (auto& range : Range::live_ranges()) {
if (range->end_container()->is_inclusive_descendant_of(*this))
range->set_end(*parent, index);
MUST(range->set_end(*parent, index));
}
// 6. For each live range whose start node is parent and start offset is greater than index, decrease its start offset by 1.
for (auto& range : Range::live_ranges()) {
if (range->start_container() == parent && range->start_offset() > index)
range->set_start(*range->start_container(), range->start_offset() - 1);
MUST(range->set_start(*range->start_container(), range->start_offset() - 1));
}
// 7. For each live range whose end node is parent and end offset is greater than index, decrease its end offset by 1.
for (auto& range : Range::live_ranges()) {
if (range->end_container() == parent && range->end_offset() > index)
range->set_end(*range->end_container(), range->end_offset() - 1);
MUST(range->set_end(*range->end_container(), range->end_offset() - 1));
}
// 8. For each NodeIterator object iterator whose roots node document is nodes node document, run the NodeIterator pre-removing steps given node and iterator.
@ -721,7 +721,7 @@ JS::NonnullGCPtr<Node> Node::clone_node(Document* document, bool clone_children)
element.for_each_attribute([&](auto& name, auto& value) {
// 1. Let copyAttribute be a clone of attribute.
// 2. Append copyAttribute to copy.
element_copy->set_attribute(name, value);
MUST(element_copy->set_attribute(name, value));
});
copy = move(element_copy);
@ -790,7 +790,7 @@ JS::NonnullGCPtr<Node> Node::clone_node(Document* document, bool clone_children)
// 6. If the clone children flag is set, clone all the children of node and append them to copy, with document as specified and the clone children flag being set.
if (clone_children) {
for_each_child([&](auto& child) {
copy->append_child(child.clone_node(document, true));
MUST(copy->append_child(child.clone_node(document, true)));
});
}

View file

@ -578,10 +578,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
verify_cast<CharacterData>(*clone).set_data(move(result));
// 3. Append clone to fragment.
fragment->append_child(clone);
TRY(fragment->append_child(clone));
// 4. Replace data with node original start node, offset original start offset, count original end offset minus original start offset, and data the empty string.
static_cast<CharacterData&>(*original_start_node).replace_data(original_start_offset, original_end_offset - original_start_offset, "");
TRY(static_cast<CharacterData&>(*original_start_node).replace_data(original_start_offset, original_end_offset - original_start_offset, ""));
// 5. Return fragment.
return JS::NonnullGCPtr(*fragment);
@ -668,10 +668,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
verify_cast<CharacterData>(*clone).set_data(move(result));
// 3. Append clone to fragment.
fragment->append_child(clone);
TRY(fragment->append_child(clone));
// 4. Replace data with node original start node, offset original start offset, count original start nodes length minus original start offset, and data the empty string.
static_cast<CharacterData&>(*original_start_node).replace_data(original_start_offset, original_start_node->length() - original_start_offset, "");
TRY(static_cast<CharacterData&>(*original_start_node).replace_data(original_start_offset, original_start_node->length() - original_start_offset, ""));
}
// 16. Otherwise, if first partially contained child is not null:
else if (first_partially_contained_child) {
@ -679,7 +679,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
auto clone = first_partially_contained_child->clone_node();
// 2. Append clone to fragment.
fragment->append_child(clone);
TRY(fragment->append_child(clone));
// 3. Let subrange be a new live range whose start is (original start node, original start offset) and whose end is (first partially contained child, first partially contained childs length).
auto subrange = Range::create(original_start_node, original_start_offset, *first_partially_contained_child, first_partially_contained_child->length());
@ -688,12 +688,12 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
auto subfragment = TRY(subrange->extract());
// 5. Append subfragment to clone.
clone->append_child(subfragment);
TRY(clone->append_child(subfragment));
}
// 17. For each contained child in contained children, append contained child to fragment.
for (auto& contained_child : contained_children) {
fragment->append_child(contained_child);
TRY(fragment->append_child(contained_child));
}
// 18. If last partially contained child is a CharacterData node, then:
@ -706,10 +706,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
verify_cast<CharacterData>(*clone).set_data(move(result));
// 3. Append clone to fragment.
fragment->append_child(clone);
TRY(fragment->append_child(clone));
// 4. Replace data with node original end node, offset 0, count original end offset, and data the empty string.
verify_cast<CharacterData>(*original_end_node).replace_data(0, original_end_offset, "");
TRY(verify_cast<CharacterData>(*original_end_node).replace_data(0, original_end_offset, ""));
}
// 19. Otherwise, if last partially contained child is not null:
else if (last_partially_contained_child) {
@ -717,7 +717,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
auto clone = last_partially_contained_child->clone_node();
// 2. Append clone to fragment.
fragment->append_child(clone);
TRY(fragment->append_child(clone));
// 3. Let subrange be a new live range whose start is (last partially contained child, 0) and whose end is (original end node, original end offset).
auto subrange = Range::create(*last_partially_contained_child, 0, original_end_node, original_end_offset);
@ -726,12 +726,12 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
auto subfragment = TRY(subrange->extract());
// 5. Append subfragment to clone.
clone->append_child(subfragment);
TRY(clone->append_child(subfragment));
}
// 20. Set ranges start and end to (new node, new offset).
set_start(*new_node, new_offset);
set_end(*new_node, new_offset);
TRY(set_start(*new_node, new_offset));
TRY(set_end(*new_node, new_offset));
// 21. Return fragment.
return JS::NonnullGCPtr(*fragment);
@ -834,7 +834,7 @@ WebIDL::ExceptionOr<void> Range::insert(JS::NonnullGCPtr<Node> node)
// 13. If range is collapsed, then set ranges end to (parent, newOffset).
if (collapsed())
set_end(*parent, new_offset);
TRY(set_end(*parent, new_offset));
return {};
}
@ -907,7 +907,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_content
verify_cast<CharacterData>(*clone).set_data(move(result));
// 3. Append clone to fragment.
fragment->append_child(clone);
TRY(fragment->append_child(clone));
// 4. Return fragment.
return JS::NonnullGCPtr(*fragment);
@ -972,7 +972,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_content
verify_cast<CharacterData>(*clone).set_data(move(result));
// 3. Append clone to fragment.
fragment->append_child(clone);
TRY(fragment->append_child(clone));
}
// 14. Otherwise, if first partially contained child is not null:
else if (first_partially_contained_child) {
@ -980,7 +980,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_content
auto clone = first_partially_contained_child->clone_node();
// 2. Append clone to fragment.
fragment->append_child(clone);
TRY(fragment->append_child(clone));
// 3. Let subrange be a new live range whose start is (original start node, original start offset) and whose end is (first partially contained child, first partially contained childs length).
auto subrange = Range::create(original_start_node, original_start_offset, *first_partially_contained_child, first_partially_contained_child->length());
@ -989,7 +989,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_content
auto subfragment = TRY(subrange->clone_the_contents());
// 5. Append subfragment to clone.
clone->append_child(subfragment);
TRY(clone->append_child(subfragment));
}
// 15. For each contained child in contained children.
@ -998,7 +998,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_content
auto clone = contained_child->clone_node(nullptr, true);
// 2. Append clone to fragment.
fragment->append_child(move(clone));
TRY(fragment->append_child(move(clone)));
}
// 16. If last partially contained child is a CharacterData node, then:
@ -1011,7 +1011,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_content
verify_cast<CharacterData>(*clone).set_data(move(result));
// 3. Append clone to fragment.
fragment->append_child(clone);
TRY(fragment->append_child(clone));
}
// 17. Otherwise, if last partially contained child is not null:
else if (last_partially_contained_child) {
@ -1019,7 +1019,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_content
auto clone = last_partially_contained_child->clone_node();
// 2. Append clone to fragment.
fragment->append_child(clone);
TRY(fragment->append_child(clone));
// 3. Let subrange be a new live range whose start is (last partially contained child, 0) and whose end is (original end node, original end offset).
auto subrange = Range::create(*last_partially_contained_child, 0, original_end_node, original_end_offset);
@ -1028,7 +1028,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_content
auto subfragment = TRY(subrange->clone_the_contents());
// 5. Append subfragment to clone.
clone->append_child(subfragment);
TRY(clone->append_child(subfragment));
}
// 18. Return fragment.
@ -1097,8 +1097,8 @@ WebIDL::ExceptionOr<void> Range::delete_contents()
TRY(static_cast<CharacterData&>(*original_end_node).replace_data(0, original_end_offset, ""));
// 10. Set start and end to (new node, new offset).
set_start(*new_node, new_offset);
set_end(*new_node, new_offset);
TRY(set_start(*new_node, new_offset));
TRY(set_end(*new_node, new_offset));
return {};
}

View file

@ -76,25 +76,25 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> Text::split_text(size_t offset)
// 2. For each live range whose start node is node and start offset is greater than offset, set its start node to new node and decrease its start offset by offset.
for (auto& range : Range::live_ranges()) {
if (range->start_container() == this && range->start_offset() > offset)
range->set_start(*new_node, range->start_offset() - offset);
TRY(range->set_start(*new_node, range->start_offset() - offset));
}
// 3. For each live range whose end node is node and end offset is greater than offset, set its end node to new node and decrease its end offset by offset.
for (auto& range : Range::live_ranges()) {
if (range->end_container() == this && range->end_offset() > offset)
range->set_end(*new_node, range->end_offset() - offset);
TRY(range->set_end(*new_node, range->end_offset() - offset));
}
// 4. For each live range whose start node is parent and start offset is equal to the index of node plus 1, increase its start offset by 1.
for (auto& range : Range::live_ranges()) {
if (range->start_container() == this && range->start_offset() == index() + 1)
range->set_start(*range->start_container(), range->start_offset() + 1);
TRY(range->set_start(*range->start_container(), range->start_offset() + 1));
}
// 5. For each live range whose end node is parent and end offset is equal to the index of node plus 1, increase its end offset by 1.
for (auto& range : Range::live_ranges()) {
if (range->end_container() == parent.ptr() && range->end_offset() == index() + 1) {
range->set_end(*range->end_container(), range->end_offset() + 1);
TRY(range->set_end(*range->end_container(), range->end_offset() + 1));
}
}
}