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

LibWeb: Convert Element to use TRY for error propagation

This commit is contained in:
Linus Groh 2022-03-22 12:38:42 +00:00
parent b6f09aaef2
commit 3cb7c463a7

View file

@ -108,8 +108,7 @@ ExceptionOr<QualifiedName> validate_and_extract(FlyString namespace_, FlyString
namespace_ = {}; namespace_ = {};
// 2. Validate qualifiedName. // 2. Validate qualifiedName.
if (auto result = Document::validate_qualified_name(qualified_name); result.is_exception()) TRY(Document::validate_qualified_name(qualified_name));
return result.exception();
// 3. Let prefix be null. // 3. Let prefix be null.
FlyString prefix = {}; FlyString prefix = {};
@ -148,14 +147,12 @@ ExceptionOr<QualifiedName> validate_and_extract(FlyString namespace_, FlyString
ExceptionOr<void> Element::set_attribute_ns(FlyString const& namespace_, FlyString const& qualified_name, String const& value) ExceptionOr<void> Element::set_attribute_ns(FlyString const& namespace_, FlyString const& qualified_name, String const& value)
{ {
// 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract. // 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract.
auto result = validate_and_extract(namespace_, qualified_name); auto extracted_qualified_name = TRY(validate_and_extract(namespace_, qualified_name));
if (result.is_exception())
return result.exception();
// FIXME: 2. Set an attribute value for this using localName, value, and also prefix and namespace. // FIXME: 2. Set an attribute value for this using localName, value, and also prefix and namespace.
// FIXME: Don't just call through to setAttribute() here. // FIXME: Don't just call through to setAttribute() here.
return set_attribute(result.value().local_name(), value); return set_attribute(extracted_qualified_name.local_name(), value);
} }
// https://dom.spec.whatwg.org/#dom-element-removeattribute // https://dom.spec.whatwg.org/#dom-element-removeattribute
@ -408,9 +405,7 @@ DOM::ExceptionOr<DOM::Element const*> Element::closest(StringView selectors) con
ExceptionOr<void> Element::set_inner_html(String const& markup) ExceptionOr<void> Element::set_inner_html(String const& markup)
{ {
auto result = DOMParsing::inner_html_setter(*this, markup); TRY(DOMParsing::inner_html_setter(*this, markup));
if (result.is_exception())
return result.exception();
set_needs_style_update(true); set_needs_style_update(true);