mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:57:35 +00:00
LibJS: Make Heap::allocate<T>() infallible
Stop worrying about tiny OOMs. Work towards #20449. While going through these, I also changed the function signature in many places where returning ThrowCompletionOr<T> is no longer necessary.
This commit is contained in:
parent
980e7164fe
commit
72c9f56c66
337 changed files with 1229 additions and 1251 deletions
|
@ -109,7 +109,7 @@ JS::GCPtr<DOM::Attr> prescan_get_attribute(DOM::Document& document, ByteBuffer c
|
|||
} else if (input[position] == '\t' || input[position] == '\n' || input[position] == '\f' || input[position] == '\r' || input[position] == ' ')
|
||||
goto spaces;
|
||||
else if (input[position] == '/' || input[position] == '>')
|
||||
return *DOM::Attr::create(document, attribute_name.to_deprecated_string(), "").release_value_but_fixme_should_propagate_errors();
|
||||
return *DOM::Attr::create(document, attribute_name.to_deprecated_string(), "");
|
||||
else
|
||||
attribute_name.append_as_lowercase(input[position]);
|
||||
++position;
|
||||
|
@ -121,7 +121,7 @@ spaces:
|
|||
if (!prescan_skip_whitespace_and_slashes(input, position))
|
||||
return {};
|
||||
if (input[position] != '=')
|
||||
return DOM::Attr::create(document, attribute_name.to_deprecated_string(), "").release_value_but_fixme_should_propagate_errors();
|
||||
return DOM::Attr::create(document, attribute_name.to_deprecated_string(), "");
|
||||
++position;
|
||||
|
||||
value:
|
||||
|
@ -134,13 +134,13 @@ value:
|
|||
++position;
|
||||
for (; !prescan_should_abort(input, position); ++position) {
|
||||
if (input[position] == quote_character)
|
||||
return DOM::Attr::create(document, attribute_name.to_deprecated_string(), attribute_value.to_deprecated_string()).release_value_but_fixme_should_propagate_errors();
|
||||
return DOM::Attr::create(document, attribute_name.to_deprecated_string(), attribute_value.to_deprecated_string());
|
||||
else
|
||||
attribute_value.append_as_lowercase(input[position]);
|
||||
}
|
||||
return {};
|
||||
} else if (input[position] == '>')
|
||||
return DOM::Attr::create(document, attribute_name.to_deprecated_string(), "").release_value_but_fixme_should_propagate_errors();
|
||||
return DOM::Attr::create(document, attribute_name.to_deprecated_string(), "");
|
||||
else
|
||||
attribute_value.append_as_lowercase(input[position]);
|
||||
|
||||
|
@ -150,7 +150,7 @@ value:
|
|||
|
||||
for (; !prescan_should_abort(input, position); ++position) {
|
||||
if (input[position] == '\t' || input[position] == '\n' || input[position] == '\f' || input[position] == '\r' || input[position] == ' ' || input[position] == '>')
|
||||
return DOM::Attr::create(document, attribute_name.to_deprecated_string(), attribute_value.to_deprecated_string()).release_value_but_fixme_should_propagate_errors();
|
||||
return DOM::Attr::create(document, attribute_name.to_deprecated_string(), attribute_value.to_deprecated_string());
|
||||
else
|
||||
attribute_value.append_as_lowercase(input[position]);
|
||||
}
|
||||
|
|
|
@ -281,7 +281,7 @@ void HTMLParser::the_end()
|
|||
document->load_timing_info().dom_content_loaded_event_start_time = HighResolutionTime::unsafe_shared_current_time();
|
||||
|
||||
// 2. Fire an event named DOMContentLoaded at the Document object, with its bubbles attribute initialized to true.
|
||||
auto content_loaded_event = DOM::Event::create(document->realm(), HTML::EventNames::DOMContentLoaded).release_value_but_fixme_should_propagate_errors();
|
||||
auto content_loaded_event = DOM::Event::create(document->realm(), HTML::EventNames::DOMContentLoaded);
|
||||
content_loaded_event->set_bubbles(true);
|
||||
document->dispatch_event(content_loaded_event);
|
||||
|
||||
|
@ -322,7 +322,7 @@ void HTMLParser::the_end()
|
|||
// 5. Fire an event named load at window, with legacy target override flag set.
|
||||
// FIXME: The legacy target override flag is currently set by a virtual override of dispatch_event()
|
||||
// We should reorganize this so that the flag appears explicitly here instead.
|
||||
window->dispatch_event(DOM::Event::create(document->realm(), HTML::EventNames::load).release_value_but_fixme_should_propagate_errors());
|
||||
window->dispatch_event(DOM::Event::create(document->realm(), HTML::EventNames::load));
|
||||
|
||||
// FIXME: 6. Invoke WebDriver BiDi load complete with the Document's browsing context, and a new WebDriver BiDi navigation status whose id is the Document object's navigation id, status is "complete", and url is the Document object's URL.
|
||||
|
||||
|
@ -490,13 +490,13 @@ void HTMLParser::handle_initial(HTMLToken& token)
|
|||
}
|
||||
|
||||
if (token.is_comment()) {
|
||||
auto comment = realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment()).release_allocated_value_but_fixme_should_propagate_errors();
|
||||
auto comment = realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment());
|
||||
MUST(document().append_child(*comment));
|
||||
return;
|
||||
}
|
||||
|
||||
if (token.is_doctype()) {
|
||||
auto doctype = realm().heap().allocate<DOM::DocumentType>(realm(), document()).release_allocated_value_but_fixme_should_propagate_errors();
|
||||
auto doctype = realm().heap().allocate<DOM::DocumentType>(realm(), document());
|
||||
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);
|
||||
|
@ -525,7 +525,7 @@ void HTMLParser::handle_before_html(HTMLToken& token)
|
|||
// -> A comment token
|
||||
if (token.is_comment()) {
|
||||
// Insert a comment as the last child of the Document object.
|
||||
auto comment = realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment()).release_allocated_value_but_fixme_should_propagate_errors();
|
||||
auto comment = realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment());
|
||||
MUST(document().append_child(*comment));
|
||||
return;
|
||||
}
|
||||
|
@ -822,7 +822,7 @@ AnythingElse:
|
|||
void HTMLParser::insert_comment(HTMLToken& token)
|
||||
{
|
||||
auto adjusted_insertion_location = find_appropriate_place_for_inserting_node();
|
||||
adjusted_insertion_location.parent->insert_before(realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment()).release_allocated_value_but_fixme_should_propagate_errors(), adjusted_insertion_location.insert_before_sibling);
|
||||
adjusted_insertion_location.parent->insert_before(realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment()), adjusted_insertion_location.insert_before_sibling);
|
||||
}
|
||||
|
||||
void HTMLParser::handle_in_head(HTMLToken& token)
|
||||
|
@ -1004,7 +1004,7 @@ DOM::Text* HTMLParser::find_character_insertion_node()
|
|||
if (adjusted_insertion_location.insert_before_sibling) {
|
||||
if (adjusted_insertion_location.insert_before_sibling->previous_sibling() && adjusted_insertion_location.insert_before_sibling->previous_sibling()->is_text())
|
||||
return static_cast<DOM::Text*>(adjusted_insertion_location.insert_before_sibling->previous_sibling());
|
||||
auto new_text_node = realm().heap().allocate<DOM::Text>(realm(), document(), "").release_allocated_value_but_fixme_should_propagate_errors();
|
||||
auto new_text_node = realm().heap().allocate<DOM::Text>(realm(), document(), "");
|
||||
adjusted_insertion_location.parent->insert_before(*new_text_node, *adjusted_insertion_location.insert_before_sibling);
|
||||
return new_text_node;
|
||||
}
|
||||
|
@ -1012,7 +1012,7 @@ DOM::Text* HTMLParser::find_character_insertion_node()
|
|||
return nullptr;
|
||||
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(), "").release_allocated_value_but_fixme_should_propagate_errors();
|
||||
auto new_text_node = realm().heap().allocate<DOM::Text>(realm(), document(), "");
|
||||
MUST(adjusted_insertion_location.parent->append_child(*new_text_node));
|
||||
return new_text_node;
|
||||
}
|
||||
|
@ -1137,7 +1137,7 @@ void HTMLParser::handle_after_body(HTMLToken& token)
|
|||
|
||||
if (token.is_comment()) {
|
||||
auto& insertion_location = m_stack_of_open_elements.first();
|
||||
MUST(insertion_location.append_child(realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment()).release_allocated_value_but_fixme_should_propagate_errors()));
|
||||
MUST(insertion_location.append_child(realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment())));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1173,7 +1173,7 @@ void HTMLParser::handle_after_body(HTMLToken& token)
|
|||
void HTMLParser::handle_after_after_body(HTMLToken& token)
|
||||
{
|
||||
if (token.is_comment()) {
|
||||
auto comment = realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment()).release_allocated_value_but_fixme_should_propagate_errors();
|
||||
auto comment = realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment());
|
||||
MUST(document().append_child(*comment));
|
||||
return;
|
||||
}
|
||||
|
@ -3402,7 +3402,7 @@ void HTMLParser::handle_after_frameset(HTMLToken& token)
|
|||
void HTMLParser::handle_after_after_frameset(HTMLToken& token)
|
||||
{
|
||||
if (token.is_comment()) {
|
||||
auto comment = document().heap().allocate<DOM::Comment>(document().realm(), document(), token.comment()).release_allocated_value_but_fixme_should_propagate_errors();
|
||||
auto comment = document().heap().allocate<DOM::Comment>(document().realm(), document(), token.comment());
|
||||
MUST(document().append_child(comment));
|
||||
return;
|
||||
}
|
||||
|
@ -3669,7 +3669,7 @@ DOM::Document& HTMLParser::document()
|
|||
Vector<JS::Handle<DOM::Node>> HTMLParser::parse_html_fragment(DOM::Element& context_element, StringView markup)
|
||||
{
|
||||
// 1. Create a new Document node, and mark it as being an HTML document.
|
||||
auto temp_document = DOM::Document::create(context_element.realm()).release_value_but_fixme_should_propagate_errors();
|
||||
auto temp_document = DOM::Document::create(context_element.realm());
|
||||
temp_document->set_document_type(DOM::Document::Type::HTML);
|
||||
|
||||
temp_document->set_is_temporary_document_for_fragment_parsing({});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue