LibWeb: Bring fragment parsing up to spec

Corresponds to https://github.com/whatwg/html/pull/10874

Also, parse_fragment() returns ExceptionOr, so stop voiding the error
from append_child().
This commit is contained in:
Sam Atkins 2025-01-07 13:50:19 +00:00 committed by Jelle Raaijmakers
commit 89296b88a0
Notes: github-actions[bot] 2025-01-07 15:06:58 +00:00
2 changed files with 30 additions and 29 deletions

View file

@ -1545,18 +1545,17 @@ WebIDL::ExceptionOr<GC::Ref<DOM::DocumentFragment>> Element::parse_fragment(Stri
dbgln("FIXME: Handle fragment parsing of XML documents");
}
// 3. Let new children be the result of invoking algorithm given markup, with context set to context.
// 3. Let newChildren be the result of invoking algorithm given context and markup.
auto new_children = algorithm(*this, markup, HTML::HTMLParser::AllowDeclarativeShadowRoots::No);
// 4. Let fragment be a new DocumentFragment whose node document is context's node document.
auto fragment = realm().create<DOM::DocumentFragment>(document());
// 5. Append each Node in new children to fragment (in tree order).
for (auto& child : new_children) {
// I don't know if this can throw here, but let's be safe.
(void)TRY(fragment->append_child(*child));
}
// 5. For each node of newChildren, in tree order: append node to fragment.
for (auto& child : new_children)
TRY(fragment->append_child(*child));
// 6. Return fragment.
return fragment;
}