1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

LibWeb: Use Optional<FlyString> directly in Document & DOMImplementation

Use the [FlyString] extended attribute to allow these functions to take
an Optional<FlyString> directly, allowing us to tidy up some conversions
from Optional<String>.
This commit is contained in:
Shannon Booth 2024-01-12 22:01:45 +13:00 committed by Andreas Kling
parent 7cf2674061
commit 636a85f04e
6 changed files with 13 additions and 28 deletions

View file

@ -1426,15 +1426,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element(String c
// https://dom.spec.whatwg.org/#dom-document-createelementns
// https://dom.spec.whatwg.org/#internal-createelementns-steps
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element_ns(Optional<String> const& namespace_, String const& qualified_name, Variant<String, ElementCreationOptions> const& options)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element_ns(Optional<FlyString> const& namespace_, String const& qualified_name, Variant<String, ElementCreationOptions> const& options)
{
// FIXME: This conversion is ugly
Optional<FlyString> namespace_to_use;
if (namespace_.has_value())
namespace_to_use = namespace_.value();
// 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract.
auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_to_use, qualified_name));
auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_, qualified_name));
// 2. Let is be null.
Optional<String> is_value;
@ -3082,15 +3077,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> Document::create_attribute(String co
}
// https://dom.spec.whatwg.org/#dom-document-createattributens
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> Document::create_attribute_ns(Optional<String> const& namespace_, String const& qualified_name)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> Document::create_attribute_ns(Optional<FlyString> const& namespace_, String const& qualified_name)
{
// FIXME: This conversion is ugly
Optional<FlyString> namespace_to_use;
if (namespace_.has_value())
namespace_to_use = namespace_.value();
// 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract.
auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_to_use, qualified_name));
auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_, qualified_name));
// 2. Return a new attribute whose namespace is namespace, namespace prefix is prefix, local name is localName, and node document is this.