1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:47:34 +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

@ -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.
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<void> 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 {};

View file

@ -220,7 +220,7 @@ void BrowsingContextContainer::navigate_an_iframe_or_frame(JS::NonnullGCPtr<Fetc
// FIXME: and processResponseEndOfBody set to reportFrameTiming.
auto* source_browsing_context = document().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");
// 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));
}
}

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.
// 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 {};
}

View file

@ -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&)

View file

@ -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)));
}
}

View file

@ -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));
}
}

View file

@ -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));
}
}

View file

@ -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();
}

View file

@ -101,11 +101,11 @@ WebIDL::ExceptionOr<void> 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<void> 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);
}

View file

@ -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

View file

@ -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<DOM::Text>(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

View file

@ -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); }

View file

@ -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)

View file

@ -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();
}

View file

@ -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)));
}
}

View file

@ -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<HTMLTableCaptionElement> HTMLTableElement::create_caption()
@ -72,7 +72,7 @@ JS::NonnullGCPtr<HTMLTableCaptionElement> 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<HTMLTableCaptionElement&>(*caption);
}
@ -127,7 +127,7 @@ WebIDL::ExceptionOr<void> 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<HTMLTableSectionElement> HTMLTableElement::create_t_head()
break;
}
pre_insert(thead, child_to_append_after);
MUST(pre_insert(thead, child_to_append_after));
return static_cast<HTMLTableSectionElement&>(*thead);
}
@ -197,7 +197,7 @@ WebIDL::ExceptionOr<void> 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<HTMLTableSectionElement> 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<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);
}
@ -291,14 +291,14 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLTableRowElement>> HTMLTableElement::ins
auto& tr = static_cast<HTMLTableRowElement&>(*DOM::create_element(document(), TagNames::tr, Namespace::HTML));
if (rows_length == 0 && !has_child_of_type<HTMLTableRowElement>()) {
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<HTMLTableRowElement>();
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));
}

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.
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));

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);
// 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()) {
auto comment = realm().heap().allocate<DOM::Comment>(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<DOM::Comment>(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<DOM::Element> 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<DOM::Text>(adjusted_insertion_location.parent->last_child());
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;
}
@ -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<DOM::Comment>(realm(), document(), token.comment()));
MUST(insertion_location.append_child(*realm().heap().allocate<DOM::Comment>(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<DOM::Comment>(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<DOM::Comment>(document().realm(), document(), token.comment());
document().append_child(*comment);
MUST(document().append_child(*comment));
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);
// 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<JS::Handle<DOM::Node>> HTMLParser::parse_html_fragment(DOM::Element& cont
// 14. Return the child nodes of root, in tree order.
Vector<JS::Handle<DOM::Node>> children;
while (JS::GCPtr<DOM::Node> 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));
}

View file

@ -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();
}