mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWeb: Make HTML fragment parsing return ExceptionOr
Update Element::parse_fragment and Node::unsafely_set_html to propagate exceptions. This refactor is needed as a prerequisite for implementing the XML fragment parser, which requires consistent error handling in fragment parsing.
This commit is contained in:
parent
8417d74328
commit
0b715b20a2
|
|
@ -2060,7 +2060,7 @@ WebIDL::ExceptionOr<GC::Ref<DOM::DocumentFragment>> Element::parse_fragment(Stri
|
|||
}
|
||||
|
||||
// 3. Let newChildren be the result of invoking algorithm given context and markup.
|
||||
auto new_children = algorithm(*this, markup, HTML::HTMLParser::AllowDeclarativeShadowRoots::No);
|
||||
auto new_children = TRY(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());
|
||||
|
|
|
|||
|
|
@ -2116,7 +2116,7 @@ WebIDL::ExceptionOr<String> Node::serialize_fragment(HTML::RequireWellFormed req
|
|||
WebIDL::ExceptionOr<void> Node::unsafely_set_html(Element& context_element, StringView html)
|
||||
{
|
||||
// 1. Let newChildren be the result of the HTML fragment parsing algorithm given contextElement, html, and true.
|
||||
auto new_children = HTML::HTMLParser::parse_html_fragment(context_element, html, HTML::HTMLParser::AllowDeclarativeShadowRoots::Yes);
|
||||
auto new_children = TRY(HTML::HTMLParser::parse_html_fragment(context_element, html, HTML::HTMLParser::AllowDeclarativeShadowRoots::Yes));
|
||||
|
||||
// 2. Let fragment be a new DocumentFragment whose node document is contextElement’s node document.
|
||||
auto fragment = realm().create<DocumentFragment>(context_element.document());
|
||||
|
|
|
|||
|
|
@ -5009,7 +5009,7 @@ DOM::Document& HTMLParser::document()
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
|
||||
Vector<GC::Root<DOM::Node>> HTMLParser::parse_html_fragment(DOM::Element& context_element, StringView markup, AllowDeclarativeShadowRoots allow_declarative_shadow_roots)
|
||||
WebIDL::ExceptionOr<Vector<GC::Root<DOM::Node>>> HTMLParser::parse_html_fragment(DOM::Element& context_element, StringView markup, AllowDeclarativeShadowRoots allow_declarative_shadow_roots)
|
||||
{
|
||||
// 1. Let document be a Document node whose type is "html".
|
||||
auto temp_document = DOM::Document::create_for_fragment_parsing(context_element.realm());
|
||||
|
|
|
|||
|
|
@ -75,7 +75,8 @@ public:
|
|||
No,
|
||||
Yes,
|
||||
};
|
||||
static Vector<GC::Root<DOM::Node>> parse_html_fragment(DOM::Element& context_element, StringView, AllowDeclarativeShadowRoots = AllowDeclarativeShadowRoots::No);
|
||||
static WebIDL::ExceptionOr<Vector<GC::Root<DOM::Node>>> parse_html_fragment(DOM::Element& context_element, StringView, AllowDeclarativeShadowRoots = AllowDeclarativeShadowRoots::No);
|
||||
|
||||
enum class SerializableShadowRoots {
|
||||
No,
|
||||
Yes,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user