mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 17:52:26 -05:00
LibWeb: Use the new "ensure_pre_insertion_validity" in the HTML document parser
Previously we didn't check if we could insert the element in the adjusted insertion location's parent. Also makes the return type NonnullRefPtr, as that's what element is.
This commit is contained in:
parent
5beacf08a2
commit
b82a00d657
Notes:
sideshowbarker
2024-07-18 20:42:41 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/b82a00d657d Pull-request: https://github.com/SerenityOS/serenity/pull/6158
2 changed files with 23 additions and 6 deletions
|
@ -457,17 +457,34 @@ NonnullRefPtr<DOM::Element> HTMLDocumentParser::create_element_for(const HTMLTok
|
|||
return element;
|
||||
}
|
||||
|
||||
RefPtr<DOM::Element> HTMLDocumentParser::insert_foreign_element(const HTMLToken& token, const FlyString& namespace_)
|
||||
// https://html.spec.whatwg.org/multipage/parsing.html#insert-a-foreign-element
|
||||
NonnullRefPtr<DOM::Element> HTMLDocumentParser::insert_foreign_element(const HTMLToken& token, const FlyString& namespace_)
|
||||
{
|
||||
auto adjusted_insertion_location = find_appropriate_place_for_inserting_node();
|
||||
|
||||
// FIXME: Pass in adjusted_insertion_location.parent as the intended parent.
|
||||
auto element = create_element_for(token, namespace_);
|
||||
// FIXME: Check if it's possible to insert `element` at `adjusted_insertion_location`
|
||||
adjusted_insertion_location.parent->insert_before(element, adjusted_insertion_location.insert_before_sibling);
|
||||
|
||||
auto pre_insertion_validity = adjusted_insertion_location.parent->ensure_pre_insertion_validity(element, adjusted_insertion_location.insert_before_sibling);
|
||||
|
||||
// NOTE: If it's not possible to insert the element at the adjusted insertion location, the element is simply dropped.
|
||||
if (!pre_insertion_validity.is_exception()) {
|
||||
if (!m_parsing_fragment) {
|
||||
// FIXME: push a new element queue onto element's relevant agent's custom element reactions stack.
|
||||
}
|
||||
|
||||
adjusted_insertion_location.parent->insert_before(element, adjusted_insertion_location.insert_before_sibling);
|
||||
|
||||
if (!m_parsing_fragment) {
|
||||
// FIXME: pop the element queue from element's relevant agent's custom element reactions stack, and invoke custom element reactions in that queue.
|
||||
}
|
||||
}
|
||||
|
||||
m_stack_of_open_elements.push(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
RefPtr<DOM::Element> HTMLDocumentParser::insert_html_element(const HTMLToken& token)
|
||||
NonnullRefPtr<DOM::Element> HTMLDocumentParser::insert_html_element(const HTMLToken& token)
|
||||
{
|
||||
return insert_foreign_element(token, Namespace::HTML);
|
||||
}
|
||||
|
|
|
@ -127,8 +127,8 @@ private:
|
|||
|
||||
DOM::Text* find_character_insertion_node();
|
||||
void flush_character_insertions();
|
||||
RefPtr<DOM::Element> insert_foreign_element(const HTMLToken&, const FlyString&);
|
||||
RefPtr<DOM::Element> insert_html_element(const HTMLToken&);
|
||||
NonnullRefPtr<DOM::Element> insert_foreign_element(const HTMLToken&, const FlyString&);
|
||||
NonnullRefPtr<DOM::Element> insert_html_element(const HTMLToken&);
|
||||
DOM::Element& current_node();
|
||||
DOM::Element& adjusted_current_node();
|
||||
DOM::Element& node_before_current_node();
|
||||
|
|
Loading…
Add table
Reference in a new issue