1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:48:12 +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

@ -2677,14 +2677,14 @@ JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::@attribute.setter_callback@)
if (attribute.extended_attributes.contains("Reflect")) { if (attribute.extended_attributes.contains("Reflect")) {
if (attribute.type->name() != "boolean") { if (attribute.type->name() != "boolean") {
attribute_generator.append(R"~~~( 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 { } else {
attribute_generator.append(R"~~~( attribute_generator.append(R"~~~(
if (!cpp_value) if (!cpp_value)
impl->remove_attribute(HTML::AttributeNames::@attribute.reflect_name@); impl->remove_attribute(HTML::AttributeNames::@attribute.reflect_name@);
else else
impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, String::empty()); MUST(impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, String::empty()));
)~~~"); )~~~");
} }
} else { } else {

View file

@ -45,7 +45,7 @@ JS::ThrowCompletionOr<JS::Object*> AudioConstructor::construct(FunctionObject&)
auto audio = DOM::create_element(document, HTML::TagNames::audio, Namespace::HTML); auto audio = DOM::create_element(document, HTML::TagNames::audio, Namespace::HTML);
// 3. Set an attribute value for audio using "preload" and "auto". // 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); auto src_value = vm.argument(0);
@ -53,7 +53,7 @@ JS::ThrowCompletionOr<JS::Object*> AudioConstructor::construct(FunctionObject&)
// (This will cause the user agent to invoke the object's resource selection algorithm before returning.) // (This will cause the user agent to invoke the object's resource selection algorithm before returning.)
if (!src_value.is_undefined()) { if (!src_value.is_undefined()) {
auto src = TRY(src_value.to_string(vm)); 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. // 5. Return audio.

View file

@ -47,13 +47,13 @@ JS::ThrowCompletionOr<JS::Object*> ImageConstructor::construct(FunctionObject&)
// 3. If width is given, then set an attribute value for img using "width" and width. // 3. If width is given, then set an attribute value for img using "width" and width.
if (vm.argument_count() > 0) { if (vm.argument_count() > 0) {
u32 width = TRY(vm.argument(0).to_u32(vm)); 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. // 4. If height is given, then set an attribute value for img using "height" and height.
if (vm.argument_count() > 1) { if (vm.argument_count() > 1) {
u32 height = TRY(vm.argument(1).to_u32(vm)); 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. // 5. Return img.

View file

@ -52,21 +52,21 @@ JS::ThrowCompletionOr<JS::Object*> OptionConstructor::construct(FunctionObject&)
auto text = TRY(vm.argument(0).to_string(vm)); auto text = TRY(vm.argument(0).to_string(vm));
if (!text.is_empty()) { if (!text.is_empty()) {
auto new_text_node = vm.heap().allocate<DOM::Text>(realm, document, text); auto new_text_node = vm.heap().allocate<DOM::Text>(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. // 4. If value is given, then set an attribute value for option using "value" and value.
if (vm.argument_count() > 1) { if (vm.argument_count() > 1) {
auto value = TRY(vm.argument(1).to_string(vm)); 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. // 5. If defaultSelected is true, then set an attribute value for option using "selected" and the empty string.
if (vm.argument_count() > 2) { if (vm.argument_count() > 2) {
auto default_selected = vm.argument(2).to_boolean(); auto default_selected = vm.argument(2).to_boolean();
if (default_selected) { if (default_selected) {
option_element->set_attribute(HTML::AttributeNames::selected, ""); MUST(option_element->set_attribute(HTML::AttributeNames::selected, ""));
} }
} }

View file

@ -5,6 +5,7 @@
*/ */
#include <LibWeb/Bindings/CSSStyleDeclarationPrototype.h> #include <LibWeb/Bindings/CSSStyleDeclarationPrototype.h>
#include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/Bindings/Intrinsics.h> #include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/CSSStyleDeclaration.h> #include <LibWeb/CSS/CSSStyleDeclaration.h>
#include <LibWeb/CSS/Parser/Parser.h> #include <LibWeb/CSS/Parser/Parser.h>
@ -163,7 +164,7 @@ void ElementInlineCSSStyleDeclaration::update_style_attribute()
m_updating = true; m_updating = true;
// 5. Set an attribute value for owner node using "style" and the result of serializing declaration block. // 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 blocks updating flag. // 6. Unset declaration blocks updating flag.
m_updating = false; m_updating = false;
@ -346,15 +347,16 @@ JS::ThrowCompletionOr<JS::Value> CSSStyleDeclaration::internal_get(JS::PropertyK
JS::ThrowCompletionOr<bool> CSSStyleDeclaration::internal_set(JS::PropertyKey const& name, JS::Value value, JS::Value receiver) JS::ThrowCompletionOr<bool> CSSStyleDeclaration::internal_set(JS::PropertyKey const& name, JS::Value value, JS::Value receiver)
{ {
auto& vm = this->vm();
if (!name.is_string()) if (!name.is_string())
return Base::internal_set(name, value, receiver); return Base::internal_set(name, value, receiver);
auto property_id = property_id_from_name(name.to_string()); auto property_id = property_id_from_name(name.to_string());
if (property_id == CSS::PropertyID::Invalid) if (property_id == CSS::PropertyID::Invalid)
return Base::internal_set(name, value, receiver); 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; return true;
} }

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. // 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()) { for (auto& range : Range::live_ranges()) {
if (range->start_container() == this && range->start_offset() > offset && range->start_offset() <= (offset + count)) 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. // 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()) { for (auto& range : Range::live_ranges()) {
if (range->end_container() == this && range->end_offset() > offset && range->end_offset() <= (offset + count)) 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. // 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()) { for (auto& range : Range::live_ranges()) {
if (range->start_container() == this && range->start_offset() > (offset + count)) 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. // 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()) { for (auto& range : Range::live_ranges()) {
if (range->end_container() == this && range->end_offset() > (offset + count)) 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. // 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 */)); element = TRY(xml_document->create_element_ns(namespace_, qualified_name /* FIXME: and an empty dictionary */));
if (doctype) if (doctype)
xml_document->append_child(*doctype); TRY(xml_document->append_child(*doctype));
if (element) if (element)
xml_document->append_child(*element); TRY(xml_document->append_child(*element));
xml_document->set_origin(document().origin()); 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); auto doctype = heap().allocate<DocumentType>(realm(), html_document);
doctype->set_name("html"); 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); 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); 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()) { if (!title.is_null()) {
auto title_element = create_element(html_document, HTML::TagNames::title, Namespace::HTML); 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); 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); 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()); html_document->set_origin(document().origin());

View file

@ -227,7 +227,7 @@ void DOMTokenList::set_value(String value)
if (!associated_element) if (!associated_element)
return; 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 WebIDL::ExceptionOr<void> DOMTokenList::validate_token(StringView token) const
@ -251,7 +251,7 @@ void DOMTokenList::run_update_steps()
return; 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. // 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 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 {}; return {};
// 2. Run the document open steps with document. // 2. Run the document open steps with document.
open(); TRY(open());
} }
// 5. Insert input into the input stream just before the insertion point. // 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>(); JS::GCPtr<HTML::HTMLTitleElement> title_element = head_element->first_child_of_type<HTML::HTMLTitleElement>();
if (!title_element) { if (!title_element) {
title_element = &static_cast<HTML::HTMLTitleElement&>(*create_element(HTML::TagNames::title).release_value()); 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->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 (auto* page = this->page()) {
if (browsing_context() == &page->top_level_browsing_context()) 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. // 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()) { for (auto& range : Range::live_ranges()) {
if (range->start_container() == this && range->start_offset() > child->index()) 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. // 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()) { for (auto& range : Range::live_ranges()) {
if (range->end_container() == this && range->end_offset() > child->index()) 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). // 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()) { for (auto& range : Range::live_ranges()) {
if (range->start_container()->is_inclusive_descendant_of(*this)) 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). // 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()) { for (auto& range : Range::live_ranges()) {
if (range->end_container()->is_inclusive_descendant_of(*this)) 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. // 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()) { for (auto& range : Range::live_ranges()) {
if (range->start_container() == parent && range->start_offset() > index) 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. // 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()) { for (auto& range : Range::live_ranges()) {
if (range->end_container() == parent && range->end_offset() > index) 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. // 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) { element.for_each_attribute([&](auto& name, auto& value) {
// 1. Let copyAttribute be a clone of attribute. // 1. Let copyAttribute be a clone of attribute.
// 2. Append copyAttribute to copy. // 2. Append copyAttribute to copy.
element_copy->set_attribute(name, value); MUST(element_copy->set_attribute(name, value));
}); });
copy = move(element_copy); 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. // 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) { if (clone_children) {
for_each_child([&](auto& child) { 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)); verify_cast<CharacterData>(*clone).set_data(move(result));
// 3. Append clone to fragment. // 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. // 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. // 5. Return fragment.
return JS::NonnullGCPtr(*fragment); return JS::NonnullGCPtr(*fragment);
@ -668,10 +668,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
verify_cast<CharacterData>(*clone).set_data(move(result)); verify_cast<CharacterData>(*clone).set_data(move(result));
// 3. Append clone to fragment. // 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. // 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: // 16. Otherwise, if first partially contained child is not null:
else if (first_partially_contained_child) { 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(); auto clone = first_partially_contained_child->clone_node();
// 2. Append clone to fragment. // 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). // 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()); 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()); auto subfragment = TRY(subrange->extract());
// 5. Append subfragment to clone. // 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. // 17. For each contained child in contained children, append contained child to fragment.
for (auto& contained_child : contained_children) { 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: // 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)); verify_cast<CharacterData>(*clone).set_data(move(result));
// 3. Append clone to fragment. // 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. // 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: // 19. Otherwise, if last partially contained child is not null:
else if (last_partially_contained_child) { 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(); auto clone = last_partially_contained_child->clone_node();
// 2. Append clone to fragment. // 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). // 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); 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()); auto subfragment = TRY(subrange->extract());
// 5. Append subfragment to clone. // 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). // 20. Set ranges start and end to (new node, new offset).
set_start(*new_node, new_offset); TRY(set_start(*new_node, new_offset));
set_end(*new_node, new_offset); TRY(set_end(*new_node, new_offset));
// 21. Return fragment. // 21. Return fragment.
return JS::NonnullGCPtr(*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). // 13. If range is collapsed, then set ranges end to (parent, newOffset).
if (collapsed()) if (collapsed())
set_end(*parent, new_offset); TRY(set_end(*parent, new_offset));
return {}; return {};
} }
@ -907,7 +907,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_content
verify_cast<CharacterData>(*clone).set_data(move(result)); verify_cast<CharacterData>(*clone).set_data(move(result));
// 3. Append clone to fragment. // 3. Append clone to fragment.
fragment->append_child(clone); TRY(fragment->append_child(clone));
// 4. Return fragment. // 4. Return fragment.
return JS::NonnullGCPtr(*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)); verify_cast<CharacterData>(*clone).set_data(move(result));
// 3. Append clone to fragment. // 3. Append clone to fragment.
fragment->append_child(clone); TRY(fragment->append_child(clone));
} }
// 14. Otherwise, if first partially contained child is not null: // 14. Otherwise, if first partially contained child is not null:
else if (first_partially_contained_child) { 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(); auto clone = first_partially_contained_child->clone_node();
// 2. Append clone to fragment. // 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). // 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()); 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()); auto subfragment = TRY(subrange->clone_the_contents());
// 5. Append subfragment to clone. // 5. Append subfragment to clone.
clone->append_child(subfragment); TRY(clone->append_child(subfragment));
} }
// 15. For each contained child in contained children. // 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); auto clone = contained_child->clone_node(nullptr, true);
// 2. Append clone to fragment. // 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: // 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)); verify_cast<CharacterData>(*clone).set_data(move(result));
// 3. Append clone to fragment. // 3. Append clone to fragment.
fragment->append_child(clone); TRY(fragment->append_child(clone));
} }
// 17. Otherwise, if last partially contained child is not null: // 17. Otherwise, if last partially contained child is not null:
else if (last_partially_contained_child) { 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(); auto clone = last_partially_contained_child->clone_node();
// 2. Append clone to fragment. // 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). // 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); 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()); auto subfragment = TRY(subrange->clone_the_contents());
// 5. Append subfragment to clone. // 5. Append subfragment to clone.
clone->append_child(subfragment); TRY(clone->append_child(subfragment));
} }
// 18. Return fragment. // 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, "")); TRY(static_cast<CharacterData&>(*original_end_node).replace_data(0, original_end_offset, ""));
// 10. Set start and end to (new node, new offset). // 10. Set start and end to (new node, new offset).
set_start(*new_node, new_offset); TRY(set_start(*new_node, new_offset));
set_end(*new_node, new_offset); TRY(set_end(*new_node, new_offset));
return {}; 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. // 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()) { for (auto& range : Range::live_ranges()) {
if (range->start_container() == this && range->start_offset() > offset) 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. // 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()) { for (auto& range : Range::live_ranges()) {
if (range->end_container() == this && range->end_offset() > offset) 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. // 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()) { for (auto& range : Range::live_ranges()) {
if (range->start_container() == this && range->start_offset() == index() + 1) 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. // 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()) { for (auto& range : Range::live_ranges()) {
if (range->end_container() == parent.ptr() && range->end_offset() == index() + 1) { 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));
} }
} }
} }

View file

@ -420,7 +420,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> Request::construct_impl(JS::Realm
} }
// 5. Otherwise, fill thiss headers with headers. // 5. Otherwise, fill thiss headers with headers.
else { else {
request_object->headers()->fill(headers.get<HeadersInit>()); TRY(request_object->headers()->fill(headers.get<HeadersInit>()));
} }
} }

View file

@ -96,7 +96,7 @@ WebIDL::ExceptionOr<void> Response::initialize_response(ResponseInit const& init
// 5. If init["headers"] exists, then fill responses headers with init["headers"]. // 5. If init["headers"] exists, then fill responses headers with init["headers"].
if (init.headers.has_value()) if (init.headers.has_value())
m_headers->fill(*init.headers); TRY(m_headers->fill(*init.headers));
// 6. If body was given, then: // 6. If body was given, then:
if (body.has_value()) { if (body.has_value()) {

View file

@ -188,9 +188,9 @@ JS::NonnullGCPtr<BrowsingContext> 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. // 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(); auto html_node = document->create_element(HTML::TagNames::html).release_value();
html_node->append_child(document->create_element(HTML::TagNames::head).release_value()); MUST(html_node->append_child(document->create_element(HTML::TagNames::head).release_value()));
html_node->append_child(document->create_element(HTML::TagNames::body).release_value()); MUST(html_node->append_child(document->create_element(HTML::TagNames::body).release_value()));
document->append_child(html_node); MUST(document->append_child(html_node));
// 19. Set the active document of browsingContext to document. // 19. Set the active document of browsingContext to document.
browsing_context->set_active_document(*document); browsing_context->set_active_document(*document);
@ -952,7 +952,7 @@ WebIDL::ExceptionOr<void> BrowsingContext::navigate(
&& resource->url().equals(active_document()->url(), AK::URL::ExcludeFragment::Yes) && resource->url().equals(active_document()->url(), AK::URL::ExcludeFragment::Yes)
&& !resource->url().fragment().is_null()) { && !resource->url().fragment().is_null()) {
// 1. Navigate to a fragment given browsingContext, resource's URL, historyHandling, and navigationId. // 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. // 2. Return.
return {}; return {};

View file

@ -220,7 +220,7 @@ void BrowsingContextContainer::navigate_an_iframe_or_frame(JS::NonnullGCPtr<Fetc
// FIXME: and processResponseEndOfBody set to reportFrameTiming. // FIXME: and processResponseEndOfBody set to reportFrameTiming.
auto* source_browsing_context = document().browsing_context(); auto* source_browsing_context = document().browsing_context();
VERIFY(source_browsing_context); VERIFY(source_browsing_context);
m_nested_browsing_context->navigate(resource, *source_browsing_context, false, history_handling); MUST(m_nested_browsing_context->navigate(resource, *source_browsing_context, false, history_handling));
} }
} }

View file

@ -64,7 +64,7 @@ JS::NonnullGCPtr<DOM::Document> DOMParser::parse_from_string(String const& strin
auto root = DOM::create_element(*document, "parsererror", "http://www.mozilla.org/newlayout/xml/parsererror.xml"); 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. // FIXME: 3. Optionally, add attributes or children to root to describe the nature of the parsing error.
// 4. Append root to document. // 4. Append root to document.
document->append_child(*root); MUST(document->append_child(*root));
} }
} }

View file

@ -144,7 +144,7 @@ WebIDL::ExceptionOr<void> DOMStringMap::set_value_of_new_named_property(String c
// FIXME: 4. If name does not match the XML Name production, throw an "InvalidCharacterError" DOMException. // 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. // 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 {}; return {};
} }

View file

@ -36,7 +36,7 @@ String HTMLAnchorElement::hyperlink_element_utils_href() const
void HTMLAnchorElement::set_hyperlink_element_utils_href(String href) 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&) void HTMLAnchorElement::run_activation_behavior(Web::DOM::Event const&)

View file

@ -32,7 +32,7 @@ String HTMLAreaElement::hyperlink_element_utils_href() const
void HTMLAreaElement::set_hyperlink_element_utils_href(String href) void HTMLAreaElement::set_hyperlink_element_utils_href(String href)
{ {
set_attribute(HTML::AttributeNames::href, move(href)); MUST(set_attribute(HTML::AttributeNames::href, move(href)));
} }
} }

View file

@ -91,7 +91,7 @@ String HTMLBaseElement::href() const
void HTMLBaseElement::set_href(String const& href) void HTMLBaseElement::set_href(String const& href)
{ {
// The href IDL attribute, on setting, must set the href content attribute to the given new value. // 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));
} }
} }

View file

@ -83,7 +83,7 @@ HTMLButtonElement::TypeAttributeState HTMLButtonElement::type_state() const
void HTMLButtonElement::set_type(String const& type) void HTMLButtonElement::set_type(String const& type)
{ {
set_attribute(HTML::AttributeNames::type, type); MUST(set_attribute(HTML::AttributeNames::type, type));
} }
} }

View file

@ -66,14 +66,14 @@ void HTMLCanvasElement::reset_context_to_default_state()
void HTMLCanvasElement::set_width(unsigned value) 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; m_bitmap = nullptr;
reset_context_to_default_state(); reset_context_to_default_state();
} }
void HTMLCanvasElement::set_height(unsigned value) 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; m_bitmap = nullptr;
reset_context_to_default_state(); reset_context_to_default_state();
} }

View file

@ -101,11 +101,11 @@ WebIDL::ExceptionOr<void> HTMLElement::set_content_editable(String const& conten
return {}; return {};
} }
if (content_editable.equals_ignoring_case("true"sv)) { if (content_editable.equals_ignoring_case("true"sv)) {
set_attribute(HTML::AttributeNames::contenteditable, "true"); MUST(set_attribute(HTML::AttributeNames::contenteditable, "true"));
return {}; return {};
} }
if (content_editable.equals_ignoring_case("false"sv)) { if (content_editable.equals_ignoring_case("false"sv)) {
set_attribute(HTML::AttributeNames::contenteditable, "false"); MUST(set_attribute(HTML::AttributeNames::contenteditable, "false"));
return {}; return {};
} }
return WebIDL::SyntaxError::create(realm(), "Invalid contentEditable value, must be 'true', 'false', or 'inherit'"); return WebIDL::SyntaxError::create(realm(), "Invalid contentEditable value, must be 'true', 'false', or 'inherit'");
@ -114,7 +114,7 @@ WebIDL::ExceptionOr<void> HTMLElement::set_content_editable(String const& conten
void HTMLElement::set_inner_text(StringView text) void HTMLElement::set_inner_text(StringView text)
{ {
remove_all_children(); remove_all_children();
append_child(document().create_text_node(text)); MUST(append_child(document().create_text_node(text)));
set_needs_style_update(true); set_needs_style_update(true);
} }

View file

@ -120,7 +120,7 @@ unsigned HTMLImageElement::width() const
void HTMLImageElement::set_width(unsigned width) 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 // 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) 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 // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-naturalwidth

View file

@ -340,12 +340,12 @@ void HTMLInputElement::create_shadow_tree_if_needed()
if (initial_value.is_null()) if (initial_value.is_null())
initial_value = String::empty(); initial_value = String::empty();
auto element = document().create_element(HTML::TagNames::div).release_value(); 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<DOM::Text>(realm(), document(), initial_value); m_text_node = heap().allocate<DOM::Text>(realm(), document(), initial_value);
m_text_node->set_always_editable(m_type != TypeAttributeState::FileUpload); m_text_node->set_always_editable(m_type != TypeAttributeState::FileUpload);
m_text_node->set_owner_input_element({}, *this); m_text_node->set_owner_input_element({}, *this);
element->append_child(*m_text_node); MUST(element->append_child(*m_text_node));
shadow_root->append_child(move(element)); MUST(shadow_root->append_child(move(element)));
set_shadow_root(move(shadow_root)); set_shadow_root(move(shadow_root));
} }
@ -418,7 +418,7 @@ String HTMLInputElement::type() const
void HTMLInputElement::set_type(String const& type) 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 // https://html.spec.whatwg.org/multipage/input.html#value-sanitization-algorithm

View file

@ -35,7 +35,7 @@ public:
virtual void parse_attribute(FlyString const& name, String const& value) override; virtual void parse_attribute(FlyString const& name, String const& value) override;
String data() const; 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); } String type() const { return attribute(HTML::AttributeNames::type); }

View file

@ -72,7 +72,7 @@ String HTMLOptionElement::value() const
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-value // https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-value
void HTMLOptionElement::set_value(String 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) static void concatenate_descendants_text_content(DOM::Node const* node, StringBuilder& builder)

View file

@ -67,7 +67,7 @@ void HTMLProgressElement::set_value(double value)
if (value < 0) if (value < 0)
return; return;
set_attribute(HTML::AttributeNames::value, String::number(value)); MUST(set_attribute(HTML::AttributeNames::value, String::number(value)));
progress_position_updated(); progress_position_updated();
} }
@ -93,7 +93,7 @@ void HTMLProgressElement::set_max(double value)
if (value <= 0) if (value <= 0)
return; return;
set_attribute(HTML::AttributeNames::max, String::number(value)); MUST(set_attribute(HTML::AttributeNames::max, String::number(value)));
progress_position_updated(); progress_position_updated();
} }

View file

@ -56,7 +56,7 @@ unsigned int HTMLTableCellElement::col_span() const
void HTMLTableCellElement::set_col_span(unsigned int value) 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 unsigned int HTMLTableCellElement::row_span() const
@ -66,7 +66,7 @@ unsigned int HTMLTableCellElement::row_span() const
void HTMLTableCellElement::set_row_span(unsigned int value) 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)));
} }
} }

View file

@ -61,7 +61,7 @@ void HTMLTableElement::set_caption(HTMLTableCaptionElement* caption)
// Currently the wrapper generator doesn't send us a nullable value // Currently the wrapper generator doesn't send us a nullable value
delete_caption(); delete_caption();
pre_insert(*caption, first_child()); MUST(pre_insert(*caption, first_child()));
} }
JS::NonnullGCPtr<HTMLTableCaptionElement> HTMLTableElement::create_caption() JS::NonnullGCPtr<HTMLTableCaptionElement> HTMLTableElement::create_caption()
@ -72,7 +72,7 @@ JS::NonnullGCPtr<HTMLTableCaptionElement> HTMLTableElement::create_caption()
} }
auto caption = DOM::create_element(document(), TagNames::caption, Namespace::HTML); auto caption = DOM::create_element(document(), TagNames::caption, Namespace::HTML);
pre_insert(caption, first_child()); MUST(pre_insert(caption, first_child()));
return static_cast<HTMLTableCaptionElement&>(*caption); return static_cast<HTMLTableCaptionElement&>(*caption);
} }
@ -127,7 +127,7 @@ WebIDL::ExceptionOr<void> HTMLTableElement::set_t_head(HTMLTableSectionElement*
break; break;
} }
pre_insert(*thead, child_to_append_after); TRY(pre_insert(*thead, child_to_append_after));
return {}; return {};
} }
@ -158,7 +158,7 @@ JS::NonnullGCPtr<HTMLTableSectionElement> HTMLTableElement::create_t_head()
break; break;
} }
pre_insert(thead, child_to_append_after); MUST(pre_insert(thead, child_to_append_after));
return static_cast<HTMLTableSectionElement&>(*thead); return static_cast<HTMLTableSectionElement&>(*thead);
} }
@ -197,7 +197,7 @@ WebIDL::ExceptionOr<void> HTMLTableElement::set_t_foot(HTMLTableSectionElement*
delete_t_foot(); delete_t_foot();
// We insert the new tfoot at the end of the table // We insert the new tfoot at the end of the table
append_child(*tfoot); TRY(append_child(*tfoot));
return {}; return {};
} }
@ -209,7 +209,7 @@ JS::NonnullGCPtr<HTMLTableSectionElement> HTMLTableElement::create_t_foot()
return *maybe_tfoot; return *maybe_tfoot;
auto tfoot = DOM::create_element(document(), TagNames::tfoot, Namespace::HTML); auto tfoot = DOM::create_element(document(), TagNames::tfoot, Namespace::HTML);
append_child(tfoot); MUST(append_child(tfoot));
return static_cast<HTMLTableSectionElement&>(*tfoot); return static_cast<HTMLTableSectionElement&>(*tfoot);
} }
@ -247,7 +247,7 @@ JS::NonnullGCPtr<HTMLTableSectionElement> HTMLTableElement::create_t_body()
} }
} }
pre_insert(tbody, child_to_append_after); MUST(pre_insert(tbody, child_to_append_after));
return static_cast<HTMLTableSectionElement&>(*tbody); return static_cast<HTMLTableSectionElement&>(*tbody);
} }
@ -291,14 +291,14 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLTableRowElement>> HTMLTableElement::ins
auto& tr = static_cast<HTMLTableRowElement&>(*DOM::create_element(document(), TagNames::tr, Namespace::HTML)); auto& tr = static_cast<HTMLTableRowElement&>(*DOM::create_element(document(), TagNames::tr, Namespace::HTML));
if (rows_length == 0 && !has_child_of_type<HTMLTableRowElement>()) { if (rows_length == 0 && !has_child_of_type<HTMLTableRowElement>()) {
auto tbody = DOM::create_element(document(), TagNames::tbody, Namespace::HTML); auto tbody = DOM::create_element(document(), TagNames::tbody, Namespace::HTML);
tbody->append_child(tr); TRY(tbody->append_child(tr));
append_child(tbody); TRY(append_child(tbody));
} else if (rows_length == 0) { } else if (rows_length == 0) {
auto tbody = last_child_of_type<HTMLTableRowElement>(); auto tbody = last_child_of_type<HTMLTableRowElement>();
tbody->append_child(tr); TRY(tbody->append_child(tr));
} else if (index == -1 || index == (long)rows_length) { } else if (index == -1 || index == (long)rows_length) {
auto parent_of_last_tr = rows->item(rows_length - 1)->parent_element(); 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 { } else {
rows->item(index)->parent_element()->insert_before(tr, rows->item(index)); rows->item(index)->parent_element()->insert_before(tr, rows->item(index));
} }

View file

@ -50,7 +50,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLTableRowElement>> HTMLTableSectionEleme
// 3. If index is 1 or equal to the number of items in the rows collection, then append table row to this element. // 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) 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. // 4. Otherwise, insert table row as a child of this element, immediately before the index-th tr element in the rows collection.
else else
table_row.insert_before(*this, rows_collection->item(index)); table_row.insert_before(*this, rows_collection->item(index));

View file

@ -53,7 +53,7 @@ void HTMLTemplateElement::cloned(Node& copy, bool clone_children)
auto cloned_child = child.clone_node(&template_clone.content()->document(), true); auto cloned_child = child.clone_node(&template_clone.content()->document(), true);
// FIXME: Should this use TreeNode::append_child instead? // FIXME: Should this use TreeNode::append_child instead?
template_clone.content()->append_child(cloned_child); MUST(template_clone.content()->append_child(cloned_child));
}); });
} }

View file

@ -465,7 +465,7 @@ void HTMLParser::handle_initial(HTMLToken& token)
if (token.is_comment()) { if (token.is_comment()) {
auto comment = realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment()); auto comment = realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment());
document().append_child(*comment); MUST(document().append_child(*comment));
return; return;
} }
@ -474,7 +474,7 @@ void HTMLParser::handle_initial(HTMLToken& token)
doctype->set_name(token.doctype_data().name); doctype->set_name(token.doctype_data().name);
doctype->set_public_id(token.doctype_data().public_identifier); doctype->set_public_id(token.doctype_data().public_identifier);
doctype->set_system_id(token.doctype_data().system_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)); document().set_quirks_mode(which_quirks_mode(token));
m_insertion_mode = InsertionMode::BeforeHTML; m_insertion_mode = InsertionMode::BeforeHTML;
return; return;
@ -495,7 +495,7 @@ void HTMLParser::handle_before_html(HTMLToken& token)
if (token.is_comment()) { if (token.is_comment()) {
auto comment = realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment()); auto comment = realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment());
document().append_child(*comment); MUST(document().append_child(*comment));
return; return;
} }
@ -505,7 +505,7 @@ void HTMLParser::handle_before_html(HTMLToken& token)
if (token.is_start_tag() && token.tag_name() == HTML::TagNames::html) { if (token.is_start_tag() && token.tag_name() == HTML::TagNames::html) {
auto element = create_element_for(token, Namespace::HTML, document()); 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_stack_of_open_elements.push(move(element));
m_insertion_mode = InsertionMode::BeforeHead; m_insertion_mode = InsertionMode::BeforeHead;
return; return;
@ -522,7 +522,7 @@ void HTMLParser::handle_before_html(HTMLToken& token)
AnythingElse: AnythingElse:
auto element = create_element(document(), HTML::TagNames::html, Namespace::HTML); 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); 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. // 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; m_insertion_mode = InsertionMode::BeforeHead;
@ -627,7 +627,7 @@ JS::NonnullGCPtr<DOM::Element> HTMLParser::create_element_for(HTMLToken const& t
// 10. Append each attribute in the given token to element. // 10. Append each attribute in the given token to element.
// FIXME: This isn't the exact `append` the spec is talking about. // FIXME: This isn't the exact `append` the spec is talking about.
token.for_each_attribute([&](auto& attribute) { 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; 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()) if (adjusted_insertion_location.parent->last_child() && adjusted_insertion_location.parent->last_child()->is_text())
return verify_cast<DOM::Text>(adjusted_insertion_location.parent->last_child()); return verify_cast<DOM::Text>(adjusted_insertion_location.parent->last_child());
auto new_text_node = realm().heap().allocate<DOM::Text>(realm(), document(), ""); auto new_text_node = realm().heap().allocate<DOM::Text>(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; return new_text_node;
} }
@ -1055,7 +1055,7 @@ void HTMLParser::handle_after_body(HTMLToken& token)
if (token.is_comment()) { if (token.is_comment()) {
auto& insertion_location = m_stack_of_open_elements.first(); auto& insertion_location = m_stack_of_open_elements.first();
insertion_location.append_child(*realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment())); MUST(insertion_location.append_child(*realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment())));
return; return;
} }
@ -1092,7 +1092,7 @@ void HTMLParser::handle_after_after_body(HTMLToken& token)
{ {
if (token.is_comment()) { if (token.is_comment()) {
auto comment = realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment()); auto comment = realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment());
document().append_child(*comment); MUST(document().append_child(*comment));
return; return;
} }
@ -1311,7 +1311,7 @@ HTMLParser::AdoptionAgencyAlgorithmOutcome HTMLParser::run_the_adoption_agency_a
} }
// 8. Append last node to node. // 8. Append last node to node.
node->append_child(*last_node); MUST(node->append_child(*last_node));
// 9. Set last node to node. // 9. Set last node to node.
last_node = 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. // 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()) 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. // 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, // 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. // 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; return;
token.for_each_attribute([&](auto& attribute) { token.for_each_attribute([&](auto& attribute) {
if (!current_node().has_attribute(attribute.local_name)) 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 IterationDecision::Continue;
}); });
return; return;
@ -1508,7 +1508,7 @@ void HTMLParser::handle_in_body(HTMLToken& token)
auto& body_element = m_stack_of_open_elements.elements().at(1); auto& body_element = m_stack_of_open_elements.elements().at(1);
token.for_each_attribute([&](auto& attribute) { token.for_each_attribute([&](auto& attribute) {
if (!body_element->has_attribute(attribute.local_name)) 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 IterationDecision::Continue;
}); });
return; return;
@ -3126,7 +3126,7 @@ void HTMLParser::handle_after_after_frameset(HTMLToken& token)
{ {
if (token.is_comment()) { if (token.is_comment()) {
auto* comment = document().heap().allocate<DOM::Comment>(document().realm(), document(), token.comment()); auto* comment = document().heap().allocate<DOM::Comment>(document().realm(), document(), token.comment());
document().append_child(*comment); MUST(document().append_child(*comment));
return; return;
} }
@ -3446,7 +3446,7 @@ Vector<JS::Handle<DOM::Node>> HTMLParser::parse_html_fragment(DOM::Element& cont
auto root = create_element(context_element.document(), HTML::TagNames::html, Namespace::HTML); auto root = create_element(context_element.document(), HTML::TagNames::html, Namespace::HTML);
// 6. Append the element root to the Document node created above. // 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. // 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); parser->m_stack_of_open_elements.push(root);
@ -3475,7 +3475,7 @@ Vector<JS::Handle<DOM::Node>> HTMLParser::parse_html_fragment(DOM::Element& cont
// 14. Return the child nodes of root, in tree order. // 14. Return the child nodes of root, in tree order.
Vector<JS::Handle<DOM::Node>> children; Vector<JS::Handle<DOM::Node>> children;
while (JS::GCPtr<DOM::Node> child = root->first_child()) { while (JS::GCPtr<DOM::Node> child = root->first_child()) {
root->remove_child(*child); MUST(root->remove_child(*child));
context_element.document().adopt_node(*child); context_element.document().adopt_node(*child);
children.append(JS::make_handle(*child)); children.append(JS::make_handle(*child));
} }

View file

@ -1423,7 +1423,9 @@ JS_DEFINE_NATIVE_FUNCTION(Window::post_message)
{ {
auto* impl = TRY(impl_from(vm)); auto* impl = TRY(impl_from(vm));
auto target_origin = TRY(vm.argument(1).to_string(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(); return JS::js_undefined();
} }

View file

@ -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) static bool build_text_document(DOM::Document& document, ByteBuffer const& data)
{ {
auto html_element = document.create_element("html").release_value(); 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(); 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(); 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()); 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(); 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(); 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; return true;
} }
@ -135,23 +135,23 @@ static bool build_image_document(DOM::Document& document, ByteBuffer const& data
return false; return false;
auto html_element = document.create_element("html").release_value(); 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(); 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(); 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 basename = LexicalPath::basename(document.url().path());
auto title_text = document.heap().allocate<DOM::Text>(document.realm(), document, String::formatted("{} [{}x{}]", basename, bitmap->width(), bitmap->height())); auto title_text = document.heap().allocate<DOM::Text>(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(); 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(); auto image_element = document.create_element("img").release_value();
image_element->set_attribute(HTML::AttributeNames::src, document.url().to_string()); MUST(image_element->set_attribute(HTML::AttributeNames::src, document.url().to_string()));
body_element->append_child(image_element); MUST(body_element->append_child(image_element));
return true; return true;
} }

View file

@ -211,16 +211,16 @@ WebIDL::ExceptionOr<void> Selection::extend(JS::NonnullGCPtr<DOM::Node> 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. // 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()) { 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. // 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()) { 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. // 7. Otherwise, set the start newRange's start to newFocus, then set its end to oldAnchor.
else { else {
new_range->set_start(new_focus_node, new_focus_offset); TRY(new_range->set_start(new_focus_node, new_focus_offset));
new_range->set_end(old_anchor_node, old_anchor_offset); TRY(new_range->set_end(old_anchor_node, old_anchor_offset));
} }
// 8. Set this's range to newRange. // 8. Set this's range to newRange.

View file

@ -70,13 +70,13 @@ void XMLDocumentBuilder::element_start(const XML::Name& name, HashMap<XML::Name,
} }
if (HTML::TagNames::template_ == m_current_node->node_name()) { if (HTML::TagNames::template_ == m_current_node->node_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). // 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<HTML::HTMLTemplateElement&>(*m_current_node).content()->append_child(node); MUST(static_cast<HTML::HTMLTemplateElement&>(*m_current_node).content()->append_child(node));
} else { } else {
m_current_node->append_child(node); MUST(m_current_node->append_child(node));
} }
for (auto& attribute : attributes) for (auto& attribute : attributes)
node->set_attribute(attribute.key, attribute.value); MUST(node->set_attribute(attribute.key, attribute.value));
m_current_node = node.ptr(); m_current_node = node.ptr();
} }
@ -131,7 +131,7 @@ void XMLDocumentBuilder::text(String const& data)
text_builder.clear(); text_builder.clear();
} else { } else {
auto node = m_document.create_text_node(data); 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) if (m_has_error)
return; return;
m_document.append_child(m_document.create_comment(data)); MUST(m_document.append_child(m_document.create_comment(data)));
} }
void XMLDocumentBuilder::document_end() void XMLDocumentBuilder::document_end()