diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 9eac9832379..49f3fa9d763 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -2677,14 +2677,14 @@ JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::@attribute.setter_callback@) if (attribute.extended_attributes.contains("Reflect")) { if (attribute.type->name() != "boolean") { attribute_generator.append(R"~~~( - impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, cpp_value); + MUST(impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, cpp_value)); )~~~"); } else { attribute_generator.append(R"~~~( if (!cpp_value) impl->remove_attribute(HTML::AttributeNames::@attribute.reflect_name@); else - impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, String::empty()); + MUST(impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, String::empty())); )~~~"); } } else { diff --git a/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp index 9cefc752856..8017818ae41 100644 --- a/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp @@ -45,7 +45,7 @@ JS::ThrowCompletionOr AudioConstructor::construct(FunctionObject&) auto audio = DOM::create_element(document, HTML::TagNames::audio, Namespace::HTML); // 3. Set an attribute value for audio using "preload" and "auto". - audio->set_attribute(HTML::AttributeNames::preload, "auto"sv); + MUST(audio->set_attribute(HTML::AttributeNames::preload, "auto"sv)); auto src_value = vm.argument(0); @@ -53,7 +53,7 @@ JS::ThrowCompletionOr AudioConstructor::construct(FunctionObject&) // (This will cause the user agent to invoke the object's resource selection algorithm before returning.) if (!src_value.is_undefined()) { auto src = TRY(src_value.to_string(vm)); - audio->set_attribute(HTML::AttributeNames::src, move(src)); + MUST(audio->set_attribute(HTML::AttributeNames::src, move(src))); } // 5. Return audio. diff --git a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp index e5ff56eadae..fd63ed49949 100644 --- a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp @@ -47,13 +47,13 @@ JS::ThrowCompletionOr ImageConstructor::construct(FunctionObject&) // 3. If width is given, then set an attribute value for img using "width" and width. if (vm.argument_count() > 0) { u32 width = TRY(vm.argument(0).to_u32(vm)); - image_element->set_attribute(HTML::AttributeNames::width, String::formatted("{}", width)); + MUST(image_element->set_attribute(HTML::AttributeNames::width, String::formatted("{}", width))); } // 4. If height is given, then set an attribute value for img using "height" and height. if (vm.argument_count() > 1) { u32 height = TRY(vm.argument(1).to_u32(vm)); - image_element->set_attribute(HTML::AttributeNames::height, String::formatted("{}", height)); + MUST(image_element->set_attribute(HTML::AttributeNames::height, String::formatted("{}", height))); } // 5. Return img. diff --git a/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp index b9f04080757..f015d326dd7 100644 --- a/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp @@ -52,21 +52,21 @@ JS::ThrowCompletionOr OptionConstructor::construct(FunctionObject&) auto text = TRY(vm.argument(0).to_string(vm)); if (!text.is_empty()) { auto new_text_node = vm.heap().allocate(realm, document, text); - option_element->append_child(*new_text_node); + MUST(option_element->append_child(*new_text_node)); } } // 4. If value is given, then set an attribute value for option using "value" and value. if (vm.argument_count() > 1) { auto value = TRY(vm.argument(1).to_string(vm)); - option_element->set_attribute(HTML::AttributeNames::value, value); + MUST(option_element->set_attribute(HTML::AttributeNames::value, value)); } // 5. If defaultSelected is true, then set an attribute value for option using "selected" and the empty string. if (vm.argument_count() > 2) { auto default_selected = vm.argument(2).to_boolean(); if (default_selected) { - option_element->set_attribute(HTML::AttributeNames::selected, ""); + MUST(option_element->set_attribute(HTML::AttributeNames::selected, "")); } } diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp index 04bb10de925..0da2e75c04c 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -163,7 +164,7 @@ void ElementInlineCSSStyleDeclaration::update_style_attribute() m_updating = true; // 5. Set an attribute value for owner node using "style" and the result of serializing declaration block. - m_element->set_attribute(HTML::AttributeNames::style, serialized()); + MUST(m_element->set_attribute(HTML::AttributeNames::style, serialized())); // 6. Unset declaration block’s updating flag. m_updating = false; @@ -346,15 +347,16 @@ JS::ThrowCompletionOr CSSStyleDeclaration::internal_get(JS::PropertyK JS::ThrowCompletionOr CSSStyleDeclaration::internal_set(JS::PropertyKey const& name, JS::Value value, JS::Value receiver) { + auto& vm = this->vm(); if (!name.is_string()) return Base::internal_set(name, value, receiver); auto property_id = property_id_from_name(name.to_string()); if (property_id == CSS::PropertyID::Invalid) return Base::internal_set(name, value, receiver); - auto css_text = TRY(value.to_string(vm())); + auto css_text = TRY(value.to_string(vm)); - set_property(property_id, css_text); + TRY(Bindings::throw_dom_exception_if_needed(vm, [&] { return set_property(property_id, css_text); })); return true; } diff --git a/Userland/Libraries/LibWeb/DOM/CharacterData.cpp b/Userland/Libraries/LibWeb/DOM/CharacterData.cpp index dfafb077b56..fd775c36e67 100644 --- a/Userland/Libraries/LibWeb/DOM/CharacterData.cpp +++ b/Userland/Libraries/LibWeb/DOM/CharacterData.cpp @@ -78,25 +78,25 @@ WebIDL::ExceptionOr 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 data’s 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 data’s 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 node’s parent is non-null, then run the children changed steps for node’s parent. diff --git a/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp b/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp index 910353fc422..eb2337ae3bf 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp +++ b/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp @@ -51,10 +51,10 @@ WebIDL::ExceptionOr> 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 DOMImplementation::create_html_document(String const& auto doctype = heap().allocate(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(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()); diff --git a/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp b/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp index 3fc75d3f72a..7438f43a80c 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp +++ b/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp @@ -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 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 attribute’s 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 diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 865bf0338f1..3f4f271ced7 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -415,7 +415,7 @@ WebIDL::ExceptionOr 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 title_element = head_element->first_child_of_type(); if (!title_element) { title_element = &static_cast(*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(realm(), *this, title)); + MUST(title_element->append_child(*heap().allocate(realm(), *this, title))); if (auto* page = this->page()) { if (browsing_context() == &page->top_level_browsing_context()) diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 32442ad081d..54ff241352a 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -399,13 +399,13 @@ void Node::insert_before(JS::NonnullGCPtr node, JS::GCPtr child, boo // 1. For each live range whose start node is parent and start offset is greater than child’s 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 child’s 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 root’s node document is node’s node document, run the NodeIterator pre-removing steps given node and iterator. @@ -721,7 +721,7 @@ JS::NonnullGCPtr 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::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))); }); } diff --git a/Userland/Libraries/LibWeb/DOM/Range.cpp b/Userland/Libraries/LibWeb/DOM/Range.cpp index 29a6566e664..4b770d1810c 100644 --- a/Userland/Libraries/LibWeb/DOM/Range.cpp +++ b/Userland/Libraries/LibWeb/DOM/Range.cpp @@ -578,10 +578,10 @@ WebIDL::ExceptionOr> Range::extract() verify_cast(*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(*original_start_node).replace_data(original_start_offset, original_end_offset - original_start_offset, ""); + TRY(static_cast(*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> Range::extract() verify_cast(*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 node’s length minus original start offset, and data the empty string. - static_cast(*original_start_node).replace_data(original_start_offset, original_start_node->length() - original_start_offset, ""); + TRY(static_cast(*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> 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 child’s 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> 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> Range::extract() verify_cast(*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(*original_end_node).replace_data(0, original_end_offset, ""); + TRY(verify_cast(*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> 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> Range::extract() auto subfragment = TRY(subrange->extract()); // 5. Append subfragment to clone. - clone->append_child(subfragment); + TRY(clone->append_child(subfragment)); } // 20. Set range’s 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 Range::insert(JS::NonnullGCPtr node) // 13. If range is collapsed, then set range’s end to (parent, newOffset). if (collapsed()) - set_end(*parent, new_offset); + TRY(set_end(*parent, new_offset)); return {}; } @@ -907,7 +907,7 @@ WebIDL::ExceptionOr> Range::clone_the_content verify_cast(*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> Range::clone_the_content verify_cast(*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> 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 child’s 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> 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> 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> Range::clone_the_content verify_cast(*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> 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> 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 Range::delete_contents() TRY(static_cast(*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 {}; } diff --git a/Userland/Libraries/LibWeb/DOM/Text.cpp b/Userland/Libraries/LibWeb/DOM/Text.cpp index 1002e664c9f..f7191c52cc0 100644 --- a/Userland/Libraries/LibWeb/DOM/Text.cpp +++ b/Userland/Libraries/LibWeb/DOM/Text.cpp @@ -76,25 +76,25 @@ WebIDL::ExceptionOr> 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)); } } } diff --git a/Userland/Libraries/LibWeb/Fetch/Request.cpp b/Userland/Libraries/LibWeb/Fetch/Request.cpp index 09db283bf15..8c15539835b 100644 --- a/Userland/Libraries/LibWeb/Fetch/Request.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Request.cpp @@ -420,7 +420,7 @@ WebIDL::ExceptionOr> Request::construct_impl(JS::Realm } // 5. Otherwise, fill this’s headers with headers. else { - request_object->headers()->fill(headers.get()); + TRY(request_object->headers()->fill(headers.get())); } } diff --git a/Userland/Libraries/LibWeb/Fetch/Response.cpp b/Userland/Libraries/LibWeb/Fetch/Response.cpp index cd5151be47a..919414c5eff 100644 --- a/Userland/Libraries/LibWeb/Fetch/Response.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Response.cpp @@ -96,7 +96,7 @@ WebIDL::ExceptionOr Response::initialize_response(ResponseInit const& init // 5. If init["headers"] exists, then fill response’s headers with init["headers"]. if (init.headers.has_value()) - m_headers->fill(*init.headers); + TRY(m_headers->fill(*init.headers)); // 6. If body was given, then: if (body.has_value()) { diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index 2e0006599c3..b87ca7bb303 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -188,9 +188,9 @@ JS::NonnullGCPtr BrowsingContext::create_a_new_browsing_context // 18. Ensure that document has a single child html node, which itself has two empty child nodes: a head element, and a body element. auto html_node = document->create_element(HTML::TagNames::html).release_value(); - html_node->append_child(document->create_element(HTML::TagNames::head).release_value()); - html_node->append_child(document->create_element(HTML::TagNames::body).release_value()); - document->append_child(html_node); + MUST(html_node->append_child(document->create_element(HTML::TagNames::head).release_value())); + MUST(html_node->append_child(document->create_element(HTML::TagNames::body).release_value())); + MUST(document->append_child(html_node)); // 19. Set the active document of browsingContext to document. browsing_context->set_active_document(*document); @@ -952,7 +952,7 @@ WebIDL::ExceptionOr BrowsingContext::navigate( && resource->url().equals(active_document()->url(), AK::URL::ExcludeFragment::Yes) && !resource->url().fragment().is_null()) { // 1. Navigate to a fragment given browsingContext, resource's URL, historyHandling, and navigationId. - navigate_to_a_fragment(resource->url(), history_handling, *navigation_id); + TRY(navigate_to_a_fragment(resource->url(), history_handling, *navigation_id)); // 2. Return. return {}; diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp index fea13d277f2..7b584560198 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp @@ -220,7 +220,7 @@ void BrowsingContextContainer::navigate_an_iframe_or_frame(JS::NonnullGCPtrnavigate(resource, *source_browsing_context, false, history_handling); + MUST(m_nested_browsing_context->navigate(resource, *source_browsing_context, false, history_handling)); } } diff --git a/Userland/Libraries/LibWeb/HTML/DOMParser.cpp b/Userland/Libraries/LibWeb/HTML/DOMParser.cpp index 9083241248d..2bfa9472711 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/DOMParser.cpp @@ -64,7 +64,7 @@ JS::NonnullGCPtr DOMParser::parse_from_string(String const& strin auto root = DOM::create_element(*document, "parsererror", "http://www.mozilla.org/newlayout/xml/parsererror.xml"); // FIXME: 3. Optionally, add attributes or children to root to describe the nature of the parsing error. // 4. Append root to document. - document->append_child(*root); + MUST(document->append_child(*root)); } } diff --git a/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp b/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp index c3121c7ee22..9e3b4cb76ce 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp +++ b/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp @@ -144,7 +144,7 @@ WebIDL::ExceptionOr DOMStringMap::set_value_of_new_named_property(String c // FIXME: 4. If name does not match the XML Name production, throw an "InvalidCharacterError" DOMException. // 5. Set an attribute value for the DOMStringMap's associated element using name and value. - m_associated_element->set_attribute(data_name, value); + MUST(m_associated_element->set_attribute(data_name, value)); return {}; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp index 6517fba4cad..fb565e80426 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp @@ -36,7 +36,7 @@ String HTMLAnchorElement::hyperlink_element_utils_href() const void HTMLAnchorElement::set_hyperlink_element_utils_href(String href) { - set_attribute(HTML::AttributeNames::href, move(href)); + MUST(set_attribute(HTML::AttributeNames::href, move(href))); } void HTMLAnchorElement::run_activation_behavior(Web::DOM::Event const&) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp index 99bc7b563d4..c41d3c6ba25 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp @@ -32,7 +32,7 @@ String HTMLAreaElement::hyperlink_element_utils_href() const void HTMLAreaElement::set_hyperlink_element_utils_href(String href) { - set_attribute(HTML::AttributeNames::href, move(href)); + MUST(set_attribute(HTML::AttributeNames::href, move(href))); } } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp index 37e780d1ec0..19f28a84fc7 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp @@ -91,7 +91,7 @@ String HTMLBaseElement::href() const void HTMLBaseElement::set_href(String const& href) { // The href IDL attribute, on setting, must set the href content attribute to the given new value. - set_attribute(AttributeNames::href, href); + MUST(set_attribute(AttributeNames::href, href)); } } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.cpp index 0474691b092..6698264878b 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.cpp @@ -83,7 +83,7 @@ HTMLButtonElement::TypeAttributeState HTMLButtonElement::type_state() const void HTMLButtonElement::set_type(String const& type) { - set_attribute(HTML::AttributeNames::type, type); + MUST(set_attribute(HTML::AttributeNames::type, type)); } } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index 9ec5a469a25..6fd19f4c2a8 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -66,14 +66,14 @@ void HTMLCanvasElement::reset_context_to_default_state() void HTMLCanvasElement::set_width(unsigned value) { - set_attribute(HTML::AttributeNames::width, String::number(value)); + MUST(set_attribute(HTML::AttributeNames::width, String::number(value))); m_bitmap = nullptr; reset_context_to_default_state(); } void HTMLCanvasElement::set_height(unsigned value) { - set_attribute(HTML::AttributeNames::height, String::number(value)); + MUST(set_attribute(HTML::AttributeNames::height, String::number(value))); m_bitmap = nullptr; reset_context_to_default_state(); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index 32c675bfa36..09ed9578250 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -101,11 +101,11 @@ WebIDL::ExceptionOr HTMLElement::set_content_editable(String const& conten return {}; } if (content_editable.equals_ignoring_case("true"sv)) { - set_attribute(HTML::AttributeNames::contenteditable, "true"); + MUST(set_attribute(HTML::AttributeNames::contenteditable, "true")); return {}; } if (content_editable.equals_ignoring_case("false"sv)) { - set_attribute(HTML::AttributeNames::contenteditable, "false"); + MUST(set_attribute(HTML::AttributeNames::contenteditable, "false")); return {}; } return WebIDL::SyntaxError::create(realm(), "Invalid contentEditable value, must be 'true', 'false', or 'inherit'"); @@ -114,7 +114,7 @@ WebIDL::ExceptionOr HTMLElement::set_content_editable(String const& conten void HTMLElement::set_inner_text(StringView text) { remove_all_children(); - append_child(document().create_text_node(text)); + MUST(append_child(document().create_text_node(text))); set_needs_style_update(true); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp index 0d4ff161417..f1845bdb3f5 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -120,7 +120,7 @@ unsigned HTMLImageElement::width() const void HTMLImageElement::set_width(unsigned width) { - set_attribute(HTML::AttributeNames::width, String::number(width)); + MUST(set_attribute(HTML::AttributeNames::width, String::number(width))); } // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-height @@ -148,7 +148,7 @@ unsigned HTMLImageElement::height() const void HTMLImageElement::set_height(unsigned height) { - set_attribute(HTML::AttributeNames::height, String::number(height)); + MUST(set_attribute(HTML::AttributeNames::height, String::number(height))); } // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-naturalwidth diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 833f0adbf34..6466577c507 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -340,12 +340,12 @@ void HTMLInputElement::create_shadow_tree_if_needed() if (initial_value.is_null()) initial_value = String::empty(); auto element = document().create_element(HTML::TagNames::div).release_value(); - element->set_attribute(HTML::AttributeNames::style, "white-space: pre; padding-top: 1px; padding-bottom: 1px; padding-left: 2px; padding-right: 2px"); + MUST(element->set_attribute(HTML::AttributeNames::style, "white-space: pre; padding-top: 1px; padding-bottom: 1px; padding-left: 2px; padding-right: 2px")); m_text_node = heap().allocate(realm(), document(), initial_value); m_text_node->set_always_editable(m_type != TypeAttributeState::FileUpload); m_text_node->set_owner_input_element({}, *this); - element->append_child(*m_text_node); - shadow_root->append_child(move(element)); + MUST(element->append_child(*m_text_node)); + MUST(shadow_root->append_child(move(element))); set_shadow_root(move(shadow_root)); } @@ -418,7 +418,7 @@ String HTMLInputElement::type() const void HTMLInputElement::set_type(String const& type) { - set_attribute(HTML::AttributeNames::type, type); + MUST(set_attribute(HTML::AttributeNames::type, type)); } // https://html.spec.whatwg.org/multipage/input.html#value-sanitization-algorithm diff --git a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.h b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.h index a2b02b2f63f..ad9a0b1fcbd 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.h @@ -35,7 +35,7 @@ public: virtual void parse_attribute(FlyString const& name, String const& value) override; String data() const; - void set_data(String const& data) { set_attribute(HTML::AttributeNames::data, data); } + void set_data(String const& data) { MUST(set_attribute(HTML::AttributeNames::data, data)); } String type() const { return attribute(HTML::AttributeNames::type); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp index 270337d22d3..cfe13f966f4 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp @@ -72,7 +72,7 @@ String HTMLOptionElement::value() const // https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-value void HTMLOptionElement::set_value(String value) { - set_attribute(HTML::AttributeNames::value, value); + MUST(set_attribute(HTML::AttributeNames::value, value)); } static void concatenate_descendants_text_content(DOM::Node const* node, StringBuilder& builder) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp index fd10fdb73ff..0ae42cdd530 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp @@ -67,7 +67,7 @@ void HTMLProgressElement::set_value(double value) if (value < 0) return; - set_attribute(HTML::AttributeNames::value, String::number(value)); + MUST(set_attribute(HTML::AttributeNames::value, String::number(value))); progress_position_updated(); } @@ -93,7 +93,7 @@ void HTMLProgressElement::set_max(double value) if (value <= 0) return; - set_attribute(HTML::AttributeNames::max, String::number(value)); + MUST(set_attribute(HTML::AttributeNames::max, String::number(value))); progress_position_updated(); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp index 49aafae7f0a..3e0cf4450ee 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp @@ -56,7 +56,7 @@ unsigned int HTMLTableCellElement::col_span() const void HTMLTableCellElement::set_col_span(unsigned int value) { - set_attribute(HTML::AttributeNames::colspan, String::number(value)); + MUST(set_attribute(HTML::AttributeNames::colspan, String::number(value))); } unsigned int HTMLTableCellElement::row_span() const @@ -66,7 +66,7 @@ unsigned int HTMLTableCellElement::row_span() const void HTMLTableCellElement::set_row_span(unsigned int value) { - set_attribute(HTML::AttributeNames::rowspan, String::number(value)); + MUST(set_attribute(HTML::AttributeNames::rowspan, String::number(value))); } } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp index 32fa50d1b8d..d779dabce88 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp @@ -61,7 +61,7 @@ void HTMLTableElement::set_caption(HTMLTableCaptionElement* caption) // Currently the wrapper generator doesn't send us a nullable value delete_caption(); - pre_insert(*caption, first_child()); + MUST(pre_insert(*caption, first_child())); } JS::NonnullGCPtr HTMLTableElement::create_caption() @@ -72,7 +72,7 @@ JS::NonnullGCPtr HTMLTableElement::create_caption() } auto caption = DOM::create_element(document(), TagNames::caption, Namespace::HTML); - pre_insert(caption, first_child()); + MUST(pre_insert(caption, first_child())); return static_cast(*caption); } @@ -127,7 +127,7 @@ WebIDL::ExceptionOr HTMLTableElement::set_t_head(HTMLTableSectionElement* break; } - pre_insert(*thead, child_to_append_after); + TRY(pre_insert(*thead, child_to_append_after)); return {}; } @@ -158,7 +158,7 @@ JS::NonnullGCPtr HTMLTableElement::create_t_head() break; } - pre_insert(thead, child_to_append_after); + MUST(pre_insert(thead, child_to_append_after)); return static_cast(*thead); } @@ -197,7 +197,7 @@ WebIDL::ExceptionOr HTMLTableElement::set_t_foot(HTMLTableSectionElement* delete_t_foot(); // We insert the new tfoot at the end of the table - append_child(*tfoot); + TRY(append_child(*tfoot)); return {}; } @@ -209,7 +209,7 @@ JS::NonnullGCPtr HTMLTableElement::create_t_foot() return *maybe_tfoot; auto tfoot = DOM::create_element(document(), TagNames::tfoot, Namespace::HTML); - append_child(tfoot); + MUST(append_child(tfoot)); return static_cast(*tfoot); } @@ -247,7 +247,7 @@ JS::NonnullGCPtr HTMLTableElement::create_t_body() } } - pre_insert(tbody, child_to_append_after); + MUST(pre_insert(tbody, child_to_append_after)); return static_cast(*tbody); } @@ -291,14 +291,14 @@ WebIDL::ExceptionOr> HTMLTableElement::ins auto& tr = static_cast(*DOM::create_element(document(), TagNames::tr, Namespace::HTML)); if (rows_length == 0 && !has_child_of_type()) { auto tbody = DOM::create_element(document(), TagNames::tbody, Namespace::HTML); - tbody->append_child(tr); - append_child(tbody); + TRY(tbody->append_child(tr)); + TRY(append_child(tbody)); } else if (rows_length == 0) { auto tbody = last_child_of_type(); - tbody->append_child(tr); + TRY(tbody->append_child(tr)); } else if (index == -1 || index == (long)rows_length) { auto parent_of_last_tr = rows->item(rows_length - 1)->parent_element(); - parent_of_last_tr->append_child(tr); + TRY(parent_of_last_tr->append_child(tr)); } else { rows->item(index)->parent_element()->insert_before(tr, rows->item(index)); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp index 76146bef10a..dfa40a6dd40 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp @@ -50,7 +50,7 @@ WebIDL::ExceptionOr> HTMLTableSectionEleme // 3. If index is −1 or equal to the number of items in the rows collection, then append table row to this element. if (index == -1 || index == rows_collection_size) - append_child(table_row); + TRY(append_child(table_row)); // 4. Otherwise, insert table row as a child of this element, immediately before the index-th tr element in the rows collection. else table_row.insert_before(*this, rows_collection->item(index)); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp index 5d7ecfd01dd..109417fd127 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp @@ -53,7 +53,7 @@ void HTMLTemplateElement::cloned(Node& copy, bool clone_children) auto cloned_child = child.clone_node(&template_clone.content()->document(), true); // FIXME: Should this use TreeNode::append_child instead? - template_clone.content()->append_child(cloned_child); + MUST(template_clone.content()->append_child(cloned_child)); }); } diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index 289ced3ed7b..a11250d6c79 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -465,7 +465,7 @@ void HTMLParser::handle_initial(HTMLToken& token) if (token.is_comment()) { auto comment = realm().heap().allocate(realm(), document(), token.comment()); - document().append_child(*comment); + MUST(document().append_child(*comment)); return; } @@ -474,7 +474,7 @@ void HTMLParser::handle_initial(HTMLToken& token) doctype->set_name(token.doctype_data().name); doctype->set_public_id(token.doctype_data().public_identifier); doctype->set_system_id(token.doctype_data().system_identifier); - document().append_child(*doctype); + MUST(document().append_child(*doctype)); document().set_quirks_mode(which_quirks_mode(token)); m_insertion_mode = InsertionMode::BeforeHTML; return; @@ -495,7 +495,7 @@ void HTMLParser::handle_before_html(HTMLToken& token) if (token.is_comment()) { auto comment = realm().heap().allocate(realm(), document(), token.comment()); - document().append_child(*comment); + MUST(document().append_child(*comment)); return; } @@ -505,7 +505,7 @@ void HTMLParser::handle_before_html(HTMLToken& token) if (token.is_start_tag() && token.tag_name() == HTML::TagNames::html) { auto element = create_element_for(token, Namespace::HTML, document()); - document().append_child(*element); + MUST(document().append_child(*element)); m_stack_of_open_elements.push(move(element)); m_insertion_mode = InsertionMode::BeforeHead; return; @@ -522,7 +522,7 @@ void HTMLParser::handle_before_html(HTMLToken& token) AnythingElse: auto element = create_element(document(), HTML::TagNames::html, Namespace::HTML); - document().append_child(*element); + MUST(document().append_child(*element)); m_stack_of_open_elements.push(element); // FIXME: If the Document is being loaded as part of navigation of a browsing context, then: run the application cache selection algorithm with no manifest, passing it the Document object. m_insertion_mode = InsertionMode::BeforeHead; @@ -627,7 +627,7 @@ JS::NonnullGCPtr HTMLParser::create_element_for(HTMLToken const& t // 10. Append each attribute in the given token to element. // FIXME: This isn't the exact `append` the spec is talking about. token.for_each_attribute([&](auto& attribute) { - element->set_attribute(attribute.local_name, attribute.value); + MUST(element->set_attribute(attribute.local_name, attribute.value)); return IterationDecision::Continue; }); @@ -930,7 +930,7 @@ DOM::Text* HTMLParser::find_character_insertion_node() if (adjusted_insertion_location.parent->last_child() && adjusted_insertion_location.parent->last_child()->is_text()) return verify_cast(adjusted_insertion_location.parent->last_child()); auto new_text_node = realm().heap().allocate(realm(), document(), ""); - adjusted_insertion_location.parent->append_child(*new_text_node); + MUST(adjusted_insertion_location.parent->append_child(*new_text_node)); return new_text_node; } @@ -1055,7 +1055,7 @@ void HTMLParser::handle_after_body(HTMLToken& token) if (token.is_comment()) { auto& insertion_location = m_stack_of_open_elements.first(); - insertion_location.append_child(*realm().heap().allocate(realm(), document(), token.comment())); + MUST(insertion_location.append_child(*realm().heap().allocate(realm(), document(), token.comment()))); return; } @@ -1092,7 +1092,7 @@ void HTMLParser::handle_after_after_body(HTMLToken& token) { if (token.is_comment()) { auto comment = realm().heap().allocate(realm(), document(), token.comment()); - document().append_child(*comment); + MUST(document().append_child(*comment)); return; } @@ -1311,7 +1311,7 @@ HTMLParser::AdoptionAgencyAlgorithmOutcome HTMLParser::run_the_adoption_agency_a } // 8. Append last node to node. - node->append_child(*last_node); + MUST(node->append_child(*last_node)); // 9. Set last node to node. last_node = node; @@ -1329,10 +1329,10 @@ HTMLParser::AdoptionAgencyAlgorithmOutcome HTMLParser::run_the_adoption_agency_a // 16. Take all of the child nodes of furthest block and append them to the element created in the last step. for (auto& child : furthest_block->children_as_vector()) - element->append_child(furthest_block->remove_child(*child).release_value()); + MUST(element->append_child(furthest_block->remove_child(*child).release_value())); // 17. Append that new element to furthest block. - furthest_block->append_child(*element); + MUST(furthest_block->append_child(*element)); // 18. Remove formatting element from the list of active formatting elements, // and insert the new element into the list of active formatting elements at the position of the aforementioned bookmark. @@ -1481,7 +1481,7 @@ void HTMLParser::handle_in_body(HTMLToken& token) return; token.for_each_attribute([&](auto& attribute) { if (!current_node().has_attribute(attribute.local_name)) - current_node().set_attribute(attribute.local_name, attribute.value); + MUST(current_node().set_attribute(attribute.local_name, attribute.value)); return IterationDecision::Continue; }); return; @@ -1508,7 +1508,7 @@ void HTMLParser::handle_in_body(HTMLToken& token) auto& body_element = m_stack_of_open_elements.elements().at(1); token.for_each_attribute([&](auto& attribute) { if (!body_element->has_attribute(attribute.local_name)) - body_element->set_attribute(attribute.local_name, attribute.value); + MUST(body_element->set_attribute(attribute.local_name, attribute.value)); return IterationDecision::Continue; }); return; @@ -3126,7 +3126,7 @@ void HTMLParser::handle_after_after_frameset(HTMLToken& token) { if (token.is_comment()) { auto* comment = document().heap().allocate(document().realm(), document(), token.comment()); - document().append_child(*comment); + MUST(document().append_child(*comment)); return; } @@ -3446,7 +3446,7 @@ Vector> HTMLParser::parse_html_fragment(DOM::Element& cont auto root = create_element(context_element.document(), HTML::TagNames::html, Namespace::HTML); // 6. Append the element root to the Document node created above. - temp_document->append_child(root); + MUST(temp_document->append_child(root)); // 7. Set up the parser's stack of open elements so that it contains just the single element root. parser->m_stack_of_open_elements.push(root); @@ -3475,7 +3475,7 @@ Vector> HTMLParser::parse_html_fragment(DOM::Element& cont // 14. Return the child nodes of root, in tree order. Vector> children; while (JS::GCPtr child = root->first_child()) { - root->remove_child(*child); + MUST(root->remove_child(*child)); context_element.document().adopt_node(*child); children.append(JS::make_handle(*child)); } diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index a9e65a927f7..81d520f8234 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -1423,7 +1423,9 @@ JS_DEFINE_NATIVE_FUNCTION(Window::post_message) { auto* impl = TRY(impl_from(vm)); auto target_origin = TRY(vm.argument(1).to_string(vm)); - impl->post_message_impl(vm.argument(0), target_origin); + TRY(Bindings::throw_dom_exception_if_needed(vm, [&] { + return impl->post_message_impl(vm.argument(0), target_origin); + })); return JS::js_undefined(); } diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp index 357ad0efbe4..a8e78c3d686 100644 --- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp @@ -104,23 +104,23 @@ static bool build_markdown_document(DOM::Document& document, ByteBuffer const& d static bool build_text_document(DOM::Document& document, ByteBuffer const& data) { auto html_element = document.create_element("html").release_value(); - document.append_child(html_element); + MUST(document.append_child(html_element)); auto head_element = document.create_element("head").release_value(); - html_element->append_child(head_element); + MUST(html_element->append_child(head_element)); auto title_element = document.create_element("title").release_value(); - head_element->append_child(title_element); + MUST(head_element->append_child(title_element)); auto title_text = document.create_text_node(document.url().basename()); - title_element->append_child(title_text); + MUST(title_element->append_child(title_text)); auto body_element = document.create_element("body").release_value(); - html_element->append_child(body_element); + MUST(html_element->append_child(body_element)); auto pre_element = document.create_element("pre").release_value(); - body_element->append_child(pre_element); + MUST(body_element->append_child(pre_element)); - pre_element->append_child(document.create_text_node(String::copy(data))); + MUST(pre_element->append_child(document.create_text_node(String::copy(data)))); return true; } @@ -135,23 +135,23 @@ static bool build_image_document(DOM::Document& document, ByteBuffer const& data return false; auto html_element = document.create_element("html").release_value(); - document.append_child(html_element); + MUST(document.append_child(html_element)); auto head_element = document.create_element("head").release_value(); - html_element->append_child(head_element); + MUST(html_element->append_child(head_element)); auto title_element = document.create_element("title").release_value(); - head_element->append_child(title_element); + MUST(head_element->append_child(title_element)); auto basename = LexicalPath::basename(document.url().path()); auto title_text = document.heap().allocate(document.realm(), document, String::formatted("{} [{}x{}]", basename, bitmap->width(), bitmap->height())); - title_element->append_child(*title_text); + MUST(title_element->append_child(*title_text)); auto body_element = document.create_element("body").release_value(); - html_element->append_child(body_element); + MUST(html_element->append_child(body_element)); auto image_element = document.create_element("img").release_value(); - image_element->set_attribute(HTML::AttributeNames::src, document.url().to_string()); - body_element->append_child(image_element); + MUST(image_element->set_attribute(HTML::AttributeNames::src, document.url().to_string())); + MUST(body_element->append_child(image_element)); return true; } diff --git a/Userland/Libraries/LibWeb/Selection/Selection.cpp b/Userland/Libraries/LibWeb/Selection/Selection.cpp index 20f7dbef308..fa2e4ab13d1 100644 --- a/Userland/Libraries/LibWeb/Selection/Selection.cpp +++ b/Userland/Libraries/LibWeb/Selection/Selection.cpp @@ -211,16 +211,16 @@ WebIDL::ExceptionOr Selection::extend(JS::NonnullGCPtr node, un // 5. If node's root is not the same as the this's range's root, set the start newRange's start and end to newFocus. if (&node->root() != &m_range->start_container()->root()) { - new_range->set_start(new_focus_node, new_focus_offset); + TRY(new_range->set_start(new_focus_node, new_focus_offset)); } // 6. Otherwise, if oldAnchor is before or equal to newFocus, set the start newRange's start to oldAnchor, then set its end to newFocus. else if (old_anchor_node.is_before(new_focus_node) || &old_anchor_node == new_focus_node.ptr()) { - new_range->set_end(new_focus_node, new_focus_offset); + TRY(new_range->set_end(new_focus_node, new_focus_offset)); } // 7. Otherwise, set the start newRange's start to newFocus, then set its end to oldAnchor. else { - new_range->set_start(new_focus_node, new_focus_offset); - new_range->set_end(old_anchor_node, old_anchor_offset); + TRY(new_range->set_start(new_focus_node, new_focus_offset)); + TRY(new_range->set_end(old_anchor_node, old_anchor_offset)); } // 8. Set this's range to newRange. diff --git a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp index d67c9505c01..05d616039be 100644 --- a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp +++ b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp @@ -70,13 +70,13 @@ void XMLDocumentBuilder::element_start(const XML::Name& name, HashMapnode_name()) { // When an XML parser would append a node to a template element, it must instead append it to the template element's template contents (a DocumentFragment node). - static_cast(*m_current_node).content()->append_child(node); + MUST(static_cast(*m_current_node).content()->append_child(node)); } else { - m_current_node->append_child(node); + MUST(m_current_node->append_child(node)); } for (auto& attribute : attributes) - node->set_attribute(attribute.key, attribute.value); + MUST(node->set_attribute(attribute.key, attribute.value)); m_current_node = node.ptr(); } @@ -131,7 +131,7 @@ void XMLDocumentBuilder::text(String const& data) text_builder.clear(); } else { auto node = m_document.create_text_node(data); - m_current_node->append_child(node); + MUST(m_current_node->append_child(node)); } } @@ -139,7 +139,7 @@ void XMLDocumentBuilder::comment(String const& data) { if (m_has_error) return; - m_document.append_child(m_document.create_comment(data)); + MUST(m_document.append_child(m_document.create_comment(data))); } void XMLDocumentBuilder::document_end()