mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
LibWeb: Match spec changes to "create an element" algorithm
Corresponds to https://github.com/whatwg/html/pull/10857 No code changes, only comments.
This commit is contained in:
parent
aa29a3ff6b
commit
4c5a40579a
Notes:
github-actions[bot]
2024-12-18 19:23:42 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/4c5a40579ae Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2967
12 changed files with 25 additions and 25 deletions
|
@ -44,7 +44,7 @@ JS::ThrowCompletionOr<GC::Ref<JS::Object>> AudioConstructor::construct(FunctionO
|
|||
auto& window = verify_cast<HTML::Window>(HTML::current_principal_global_object());
|
||||
auto& document = window.associated_document();
|
||||
|
||||
// 2. Let audio be the result of creating an element given document, audio, and the HTML namespace.
|
||||
// 2. Let audio be the result of creating an element given document, "audio", and the HTML namespace.
|
||||
auto audio = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { return DOM::create_element(document, HTML::TagNames::audio, Namespace::HTML); }));
|
||||
|
||||
// 3. Set an attribute value for audio using "preload" and "auto".
|
||||
|
|
|
@ -45,7 +45,7 @@ JS::ThrowCompletionOr<GC::Ref<JS::Object>> ImageConstructor::construct(FunctionO
|
|||
auto& window = verify_cast<HTML::Window>(HTML::current_principal_global_object());
|
||||
auto& document = window.associated_document();
|
||||
|
||||
// 2. Let img be the result of creating an element given document, img, and the HTML namespace.
|
||||
// 2. Let img be the result of creating an element given document, "img", and the HTML namespace.
|
||||
auto image_element = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { return DOM::create_element(document, HTML::TagNames::img, Namespace::HTML); }));
|
||||
|
||||
// 3. If width is given, then set an attribute value for img using "width" and width.
|
||||
|
|
|
@ -54,7 +54,7 @@ JS::ThrowCompletionOr<GC::Ref<JS::Object>> OptionConstructor::construct(Function
|
|||
auto& window = verify_cast<HTML::Window>(HTML::current_principal_global_object());
|
||||
auto& document = window.associated_document();
|
||||
|
||||
// 2. Let option be the result of creating an element given document, option, and the HTML namespace.
|
||||
// 2. Let option be the result of creating an element given document, "option", and the HTML namespace.
|
||||
auto element = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { return DOM::create_element(document, HTML::TagNames::option, Namespace::HTML); }));
|
||||
GC::Ref<HTML::HTMLOptionElement> option_element = verify_cast<HTML::HTMLOptionElement>(*element);
|
||||
|
||||
|
|
|
@ -101,7 +101,8 @@ void Attr::handle_attribute_changes(Element& element, Optional<String> const& ol
|
|||
// 1. Queue a mutation record of "attributes" for element with attribute’s local name, attribute’s namespace, oldValue, « », « », null, and null.
|
||||
element.queue_mutation_record(MutationType::attributes, local_name(), namespace_uri(), old_value, {}, {}, nullptr, nullptr);
|
||||
|
||||
// 2. If element is custom, then enqueue a custom element callback reaction with element, callback name "attributeChangedCallback", and an argument list containing attribute’s local name, oldValue, newValue, and attribute’s namespace.
|
||||
// 2. If element is custom, then enqueue a custom element callback reaction with element, callback name "attributeChangedCallback",
|
||||
// and « attribute’s local name, oldValue, newValue, attribute’s namespace ».
|
||||
if (element.is_custom()) {
|
||||
auto& vm = this->vm();
|
||||
|
||||
|
|
|
@ -106,17 +106,17 @@ GC::Ref<Document> DOMImplementation::create_html_document(Optional<String> const
|
|||
doctype->set_name("html"_string);
|
||||
MUST(html_document->append_child(*doctype));
|
||||
|
||||
// 4. Append the result of creating an element given doc, html, and the HTML namespace, to doc.
|
||||
// 4. Append the result of creating an element given doc, "html", and the HTML namespace, to doc.
|
||||
auto html_element = create_element(html_document, HTML::TagNames::html, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
|
||||
MUST(html_document->append_child(html_element));
|
||||
|
||||
// 5. Append the result of creating an element given doc, head, and the HTML namespace, to the html element created earlier.
|
||||
// 5. Append the result of creating an element given doc, "head", and the HTML namespace, to the html element created earlier.
|
||||
auto head_element = create_element(html_document, HTML::TagNames::head, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
|
||||
MUST(html_element->append_child(head_element));
|
||||
|
||||
// 6. If title is given:
|
||||
if (title.has_value()) {
|
||||
// 1. Append the result of creating an element given doc, title, and the HTML namespace, to the head element created earlier.
|
||||
// 1. Append the result of creating an element given doc, "title", and the HTML namespace, to the head element created earlier.
|
||||
auto title_element = create_element(html_document, HTML::TagNames::title, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
|
||||
MUST(head_element->append_child(title_element));
|
||||
|
||||
|
@ -125,7 +125,7 @@ GC::Ref<Document> DOMImplementation::create_html_document(Optional<String> const
|
|||
MUST(title_element->append_child(*text_node));
|
||||
}
|
||||
|
||||
// 7. Append the result of creating an element given doc, body, and the HTML namespace, to the html element created earlier.
|
||||
// 7. Append the result of creating an element given doc, "body", and the HTML namespace, to the html element created earlier.
|
||||
auto body_element = create_element(html_document, HTML::TagNames::body, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
|
||||
MUST(html_element->append_child(body_element));
|
||||
|
||||
|
|
|
@ -442,13 +442,13 @@ void Document::initialize(JS::Realm& realm)
|
|||
// https://html.spec.whatwg.org/multipage/document-lifecycle.html#populate-with-html/head/body
|
||||
WebIDL::ExceptionOr<void> Document::populate_with_html_head_and_body()
|
||||
{
|
||||
// 1. Let html be the result of creating an element given document, html, and the HTML namespace.
|
||||
// 1. Let html be the result of creating an element given document, "html", and the HTML namespace.
|
||||
auto html = TRY(DOM::create_element(*this, HTML::TagNames::html, Namespace::HTML));
|
||||
|
||||
// 2. Let head be the result of creating an element given document, head, and the HTML namespace.
|
||||
// 2. Let head be the result of creating an element given document, "head", and the HTML namespace.
|
||||
auto head = TRY(DOM::create_element(*this, HTML::TagNames::head, Namespace::HTML));
|
||||
|
||||
// 3. Let body be the result of creating an element given document, body, and the HTML namespace.
|
||||
// 3. Let body be the result of creating an element given document, "body", and the HTML namespace.
|
||||
auto body = TRY(DOM::create_element(*this, HTML::TagNames::body, Namespace::HTML));
|
||||
|
||||
// 4. Append html to document.
|
||||
|
@ -930,7 +930,7 @@ WebIDL::ExceptionOr<void> Document::set_title(String const& title)
|
|||
}
|
||||
// 2. Otherwise:
|
||||
else {
|
||||
// 1. Let element be the result of creating an element given the document element's node document, title,
|
||||
// 1. Let element be the result of creating an element given the document element's node document, "title",
|
||||
// and the SVG namespace.
|
||||
element = TRY(DOM::create_element(*this, HTML::TagNames::title, Namespace::SVG));
|
||||
|
||||
|
@ -959,7 +959,7 @@ WebIDL::ExceptionOr<void> Document::set_title(String const& title)
|
|||
}
|
||||
// 3. Otherwise:
|
||||
else {
|
||||
// 1. Let element be the result of creating an element given the document element's node document, title,
|
||||
// 1. Let element be the result of creating an element given the document element's node document, "title",
|
||||
// and the HTML namespace.
|
||||
element = TRY(DOM::create_element(*this, HTML::TagNames::title, Namespace::HTML));
|
||||
|
||||
|
|
|
@ -1520,7 +1520,7 @@ WebIDL::ExceptionOr<void> Element::set_outer_html(String const& value)
|
|||
if (parent->is_document())
|
||||
return WebIDL::NoModificationAllowedError::create(realm(), "Cannot set outer HTML on document"_string);
|
||||
|
||||
// 5. If parent is a DocumentFragment, set parent to the result of creating an element given this's node document, body, and the HTML namespace.
|
||||
// 5. If parent is a DocumentFragment, set parent to the result of creating an element given this's node document, "body", and the HTML namespace.
|
||||
if (parent->is_document_fragment())
|
||||
parent = TRY(create_element(document(), HTML::TagNames::body, Namespace::HTML));
|
||||
|
||||
|
@ -2084,7 +2084,7 @@ JS::ThrowCompletionOr<void> Element::upgrade_element(GC::Ref<HTML::CustomElement
|
|||
set_custom_element_state(CustomElementState::Failed);
|
||||
|
||||
// 4. For each attribute in element's attribute list, in order, enqueue a custom element callback reaction with element, callback name "attributeChangedCallback",
|
||||
// and an argument list containing attribute's local name, null, attribute's value, and attribute's namespace.
|
||||
// and « attribute's local name, null, attribute's value, attribute's namespace ».
|
||||
for (size_t attribute_index = 0; attribute_index < m_attributes->length(); ++attribute_index) {
|
||||
auto const* attribute = m_attributes->item(attribute_index);
|
||||
VERIFY(attribute);
|
||||
|
@ -2099,7 +2099,7 @@ JS::ThrowCompletionOr<void> Element::upgrade_element(GC::Ref<HTML::CustomElement
|
|||
enqueue_a_custom_element_callback_reaction(HTML::CustomElementReactionNames::attributeChangedCallback, move(arguments));
|
||||
}
|
||||
|
||||
// 5. If element is connected, then enqueue a custom element callback reaction with element, callback name "connectedCallback", and an empty argument list.
|
||||
// 5. If element is connected, then enqueue a custom element callback reaction with element, callback name "connectedCallback", and « ».
|
||||
if (is_connected()) {
|
||||
GC::MarkedVector<JS::Value> empty_arguments { vm.heap() };
|
||||
enqueue_a_custom_element_callback_reaction(HTML::CustomElementReactionNames::connectedCallback, move(empty_arguments));
|
||||
|
|
|
@ -1275,7 +1275,7 @@ WebIDL::ExceptionOr<GC::Ref<DocumentFragment>> Range::create_contextual_fragment
|
|||
// - element's namespace is the HTML namespace;
|
||||
if (!element || is<HTML::HTMLHtmlElement>(*element)) {
|
||||
// then set element to the result of creating an element given this's node document,
|
||||
// body, and the HTML namespace.
|
||||
// "body", and the HTML namespace.
|
||||
element = TRY(DOM::create_element(node->document(), HTML::TagNames::body, Namespace::HTML));
|
||||
}
|
||||
|
||||
|
|
|
@ -237,7 +237,7 @@ GC::Ref<DOM::DocumentFragment> HTMLElement::rendered_text_fragment(StringView in
|
|||
input = input.substring_view(1);
|
||||
}
|
||||
|
||||
// 3. Append the result of creating an element given document, br, and the HTML namespace to fragment.
|
||||
// 3. Append the result of creating an element given document, "br", and the HTML namespace to fragment.
|
||||
auto br_element = DOM::create_element(document(), HTML::TagNames::br, Namespace::HTML).release_value();
|
||||
MUST(fragment->append_child(br_element));
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ WebIDL::ExceptionOr<GC::Ref<HTMLTableCellElement>> HTMLTableRowElement::insert_c
|
|||
if (index < -1 || index > cells_collection_size)
|
||||
return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than the number of cells"_string);
|
||||
|
||||
// 2. Let table cell be the result of creating an element given this tr element's node document, td, and the HTML namespace.
|
||||
// 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)));
|
||||
|
||||
// 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.
|
||||
|
|
|
@ -64,7 +64,7 @@ WebIDL::ExceptionOr<GC::Ref<HTMLTableRowElement>> HTMLTableSectionElement::inser
|
|||
if (index < -1 || index > rows_collection_size)
|
||||
return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than the number of rows"_string);
|
||||
|
||||
// 2. Let table row be the result of creating an element given this element's node document, tr, and the HTML namespace.
|
||||
// 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)));
|
||||
|
||||
// 3. If index is −1 or equal to the number of items in the rows collection, then append table row to this element.
|
||||
|
|
|
@ -735,10 +735,10 @@ GC::Ref<DOM::Element> HTMLParser::create_element_for(HTMLToken const& token, Opt
|
|||
// 6. Let definition be the result of looking up a custom element definition given document, given namespace, local name, and is.
|
||||
auto definition = document->lookup_custom_element_definition(namespace_, local_name, is_value);
|
||||
|
||||
// 7. If definition is non-null and the parser was not created as part of the HTML fragment parsing algorithm, then let will execute script be true. Otherwise, let it be false.
|
||||
// 7. Let willExecuteScript be true if definition is non-null and the parser was not created as part of the HTML fragment parsing algorithm; otherwise false.
|
||||
bool will_execute_script = definition && !m_parsing_fragment;
|
||||
|
||||
// 8. If will execute script is true, then:
|
||||
// 8. If willExecuteScript is true:
|
||||
if (will_execute_script) {
|
||||
// 1. Increment document's throw-on-dynamic-markup-insertion counter.
|
||||
document->increment_throw_on_dynamic_markup_insertion_counter({});
|
||||
|
@ -753,8 +753,7 @@ GC::Ref<DOM::Element> HTMLParser::create_element_for(HTMLToken const& token, Opt
|
|||
custom_data.custom_element_reactions_stack.element_queue_stack.append({});
|
||||
}
|
||||
|
||||
// 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.
|
||||
// 9. Let element be the result of creating an element given document, localName, given namespace, null, is, and willExecuteScript.
|
||||
auto element = create_element(*document, local_name, namespace_, {}, is_value, will_execute_script).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
// 10. Append each attribute in the given token to element.
|
||||
|
@ -765,7 +764,7 @@ GC::Ref<DOM::Element> HTMLParser::create_element_for(HTMLToken const& token, Opt
|
|||
return IterationDecision::Continue;
|
||||
});
|
||||
|
||||
// 11. If will execute script is true, then:
|
||||
// 11. If willExecuteScript is true:
|
||||
if (will_execute_script) {
|
||||
// 1. Let queue be the result of popping from document's relevant agent's custom element reactions stack. (This will be the same element queue as was pushed above.)
|
||||
auto& vm = main_thread_event_loop().vm();
|
||||
|
|
Loading…
Add table
Reference in a new issue