1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 21:07:36 +00:00

LibWeb: Use FlyString for create_element() namespace strings

This commit is contained in:
Andreas Kling 2023-11-04 09:46:23 +01:00
parent 8f82bd044b
commit f052823f5f
21 changed files with 65 additions and 64 deletions

View file

@ -244,10 +244,10 @@ WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext
document->set_ready_for_post_load_tasks(true);
// 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 = TRY(DOM::create_element(document, HTML::TagNames::html, Namespace::HTML));
auto head_element = TRY(DOM::create_element(document, HTML::TagNames::head, Namespace::HTML));
auto html_node = TRY(DOM::create_element(document, HTML::TagNames::html, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
auto head_element = TRY(DOM::create_element(document, HTML::TagNames::head, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
TRY(html_node->append_child(head_element));
auto body_element = TRY(DOM::create_element(document, HTML::TagNames::body, Namespace::HTML));
auto body_element = TRY(DOM::create_element(document, HTML::TagNames::body, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
TRY(html_node->append_child(body_element));
TRY(document->append_child(html_node));

View file

@ -71,7 +71,7 @@ JS::NonnullGCPtr<DOM::Document> DOMParser::parse_from_string(StringView string,
// 1. Assert: document has no child nodes.
document->remove_all_children(true);
// 2. Let root be the result of creating an element given document, "parsererror", and "http://www.mozilla.org/newlayout/xml/parsererror.xml".
auto root = DOM::create_element(*document, "parsererror"_fly_string, "http://www.mozilla.org/newlayout/xml/parsererror.xml").release_value_but_fixme_should_propagate_errors();
auto root = DOM::create_element(*document, "parsererror"_fly_string, "http://www.mozilla.org/newlayout/xml/parsererror.xml"_fly_string).release_value_but_fixme_should_propagate_errors();
// FIXME: 3. Optionally, add attributes or children to root to describe the nature of the parsing error.
// 4. Append root to document.
MUST(document->append_child(*root));

View file

@ -112,11 +112,11 @@ WebIDL::ExceptionOr<void> HTMLDetailsElement::create_shadow_tree(JS::Realm& real
shadow_root->set_slot_assignment(Bindings::SlotAssignmentMode::Manual);
// The first slot is expected to take the details element's first summary element child, if any.
auto summary_slot = TRY(DOM::create_element(document(), HTML::TagNames::slot, Namespace::HTML));
auto summary_slot = TRY(DOM::create_element(document(), HTML::TagNames::slot, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
MUST(shadow_root->append_child(summary_slot));
// The second slot is expected to take the details element's remaining descendants, if any.
auto descendants_slot = TRY(DOM::create_element(document(), HTML::TagNames::slot, Namespace::HTML));
auto descendants_slot = TRY(DOM::create_element(document(), HTML::TagNames::slot, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
MUST(shadow_root->append_child(descendants_slot));
m_summary_slot = static_cast<HTML::HTMLSlotElement&>(*summary_slot);

View file

@ -536,7 +536,7 @@ void HTMLInputElement::create_text_input_shadow_tree()
{
auto shadow_root = heap().allocate<DOM::ShadowRoot>(realm(), document(), *this, Bindings::ShadowRootMode::Closed);
auto initial_value = m_value;
auto element = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
auto element = DOM::create_element(document(), HTML::TagNames::div, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
MUST(element->set_attribute(HTML::AttributeNames::style, R"~~~(
display: flex;
height: 100%;
@ -555,7 +555,7 @@ void HTMLInputElement::create_text_input_shadow_tree()
MUST(m_placeholder_element->append_child(*m_placeholder_text_node));
MUST(element->append_child(*m_placeholder_element));
m_inner_text_element = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
m_inner_text_element = DOM::create_element(document(), HTML::TagNames::div, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
MUST(m_inner_text_element->style_for_bindings()->set_property(CSS::PropertyID::Height, "1lh"sv));
m_text_node = heap().allocate<DOM::Text>(realm(), document(), MUST(String::from_deprecated_string(initial_value)));
@ -587,7 +587,7 @@ void HTMLInputElement::create_color_input_shadow_tree()
auto color = value_sanitization_algorithm(m_value);
auto border = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
auto border = DOM::create_element(document(), HTML::TagNames::div, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
MUST(border->set_attribute(HTML::AttributeNames::style, R"~~~(
width: fit-content;
height: fit-content;
@ -596,7 +596,7 @@ void HTMLInputElement::create_color_input_shadow_tree()
background-color: ButtonFace;
)~~~"_string));
m_color_well_element = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
m_color_well_element = DOM::create_element(document(), HTML::TagNames::div, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
MUST(m_color_well_element->set_attribute(HTML::AttributeNames::style, R"~~~(
width: 24px;
height: 24px;

View file

@ -118,7 +118,7 @@ JS::NonnullGCPtr<HTMLTableCaptionElement> HTMLTableElement::create_caption()
return *maybe_caption;
}
auto caption = DOM::create_element(document(), TagNames::caption, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
auto caption = DOM::create_element(document(), TagNames::caption, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
MUST(pre_insert(caption, first_child()));
return static_cast<HTMLTableCaptionElement&>(*caption);
}
@ -196,7 +196,7 @@ JS::NonnullGCPtr<HTMLTableSectionElement> HTMLTableElement::create_t_head()
if (maybe_thead)
return *maybe_thead;
auto thead = DOM::create_element(document(), TagNames::thead, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
auto thead = DOM::create_element(document(), TagNames::thead, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
// We insert the new thead after any <caption> or <colgroup> elements
DOM::Node* child_to_insert_before = nullptr;
@ -272,7 +272,7 @@ JS::NonnullGCPtr<HTMLTableSectionElement> HTMLTableElement::create_t_foot()
if (maybe_tfoot)
return *maybe_tfoot;
auto tfoot = DOM::create_element(document(), TagNames::tfoot, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
auto tfoot = DOM::create_element(document(), TagNames::tfoot, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
MUST(append_child(tfoot));
return static_cast<HTMLTableSectionElement&>(*tfoot);
}
@ -302,7 +302,7 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableElement::t_bodies()
// https://html.spec.whatwg.org/multipage/tables.html#dom-table-createtbody
JS::NonnullGCPtr<HTMLTableSectionElement> HTMLTableElement::create_t_body()
{
auto tbody = DOM::create_element(document(), TagNames::tbody, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
auto tbody = DOM::create_element(document(), TagNames::tbody, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
// We insert the new tbody after the last <tbody> element
DOM::Node* child_to_insert_before = nullptr;
@ -365,9 +365,9 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLTableRowElement>> HTMLTableElement::ins
if (index < -1 || index > (long)rows_length) {
return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than the number of rows"_fly_string);
}
auto& tr = static_cast<HTMLTableRowElement&>(*TRY(DOM::create_element(document(), TagNames::tr, Namespace::HTML)));
auto& tr = static_cast<HTMLTableRowElement&>(*TRY(DOM::create_element(document(), TagNames::tr, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)))));
if (rows_length == 0 && !has_child_of_type<HTMLTableRowElement>()) {
auto tbody = TRY(DOM::create_element(document(), TagNames::tbody, Namespace::HTML));
auto tbody = TRY(DOM::create_element(document(), TagNames::tbody, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
TRY(tbody->append_child(tr));
TRY(append_child(tbody));
} else if (rows_length == 0) {

View file

@ -132,7 +132,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLTableCellElement>> HTMLTableRowElement:
return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than the number of cells"_fly_string);
// 2. Let table cell be the result of creating an element given this tr element's node document, td, and the HTML namespace.
auto& table_cell = static_cast<HTMLTableCellElement&>(*TRY(DOM::create_element(document(), HTML::TagNames::td, Namespace::HTML)));
auto& table_cell = static_cast<HTMLTableCellElement&>(*TRY(DOM::create_element(document(), HTML::TagNames::td, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)))));
// 3. If index is equal to 1 or equal to the number of items in cells collection, then append table cell to this tr element.
if (index == -1 || index == cells_collection_size)

View file

@ -57,7 +57,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLTableRowElement>> HTMLTableSectionEleme
return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than the number of rows"_fly_string);
// 2. Let table row be the result of creating an element given this element's node document, tr, and the HTML namespace.
auto& table_row = static_cast<HTMLTableRowElement&>(*TRY(DOM::create_element(document(), TagNames::tr, Namespace::HTML)));
auto& table_row = static_cast<HTMLTableRowElement&>(*TRY(DOM::create_element(document(), TagNames::tr, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)))));
// 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)

View file

@ -97,9 +97,9 @@ void HTMLTextAreaElement::create_shadow_tree_if_needed()
return;
auto shadow_root = heap().allocate<DOM::ShadowRoot>(realm(), document(), *this, Bindings::ShadowRootMode::Closed);
auto element = MUST(DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML));
auto element = MUST(DOM::create_element(document(), HTML::TagNames::div, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
m_inner_text_element = MUST(DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML));
m_inner_text_element = MUST(DOM::create_element(document(), HTML::TagNames::div, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
m_text_node = heap().allocate<DOM::Text>(realm(), document(), String {});
m_text_node->set_always_editable(true);

View file

@ -564,7 +564,7 @@ void HTMLParser::handle_before_html(HTMLToken& token)
// -> Anything else
AnythingElse:
// Create an html element whose node document is the Document object. Append it to the Document object. Put this element in the stack of open elements.
auto element = create_element(document(), HTML::TagNames::html, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
auto element = create_element(document(), HTML::TagNames::html, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
MUST(document().append_child(element));
m_stack_of_open_elements.push(element);
@ -684,7 +684,7 @@ JS::NonnullGCPtr<DOM::Element> HTMLParser::create_element_for(HTMLToken const& t
// 9. Let element be the result of creating an element given document, localName, given namespace, null, and is.
// If will execute script is true, set the synchronous custom elements flag; otherwise, leave it unset.
auto element = create_element(*document, local_name, namespace_, {}, is_value, will_execute_script).release_value_but_fixme_should_propagate_errors();
auto element = create_element(*document, local_name, MUST(FlyString::from_deprecated_fly_string(namespace_)), {}, is_value, will_execute_script).release_value_but_fixme_should_propagate_errors();
// 10. Append each attribute in the given token to element.
// FIXME: This isn't the exact `append` the spec is talking about.
@ -3772,7 +3772,7 @@ Vector<JS::Handle<DOM::Node>> HTMLParser::parse_html_fragment(DOM::Element& cont
}
// 5. Let root be a new html element with no attributes.
auto root = create_element(context_element.document(), HTML::TagNames::html, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
auto root = create_element(context_element.document(), HTML::TagNames::html, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
// 6. Append the element root to the Document node created above.
MUST(temp_document->append_child(root));