AK+Everywhere: Change StringView case conversions to return String

There's a bit of a UTF-8 assumption with this change. But nearly every
caller of these methods were immediately creating a String from the
resulting ByteString anyways.
This commit is contained in:
Timothy Flynn 2025-04-06 10:19:35 -04:00 committed by Andreas Kling
commit 0a256b0a9a
Notes: github-actions[bot] 2025-04-07 15:45:50 +00:00
15 changed files with 57 additions and 56 deletions

View file

@ -227,7 +227,7 @@ WebIDL::ExceptionOr<bool> DOMTokenList::supports(StringView token)
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Attribute {} does not define any supported tokens", m_associated_attribute)) };
// 2. Let lowercase token be a copy of token, in ASCII lowercase.
auto lowercase_token = token.to_lowercase_string();
auto lowercase_token = token.to_ascii_lowercase_string();
// 3. If lowercase token is present in supported tokens, return true.
if (supported_tokens->contains_slow(lowercase_token))

View file

@ -2072,17 +2072,16 @@ HTML::EnvironmentSettingsObject& Document::relevant_settings_object() const
}
// https://dom.spec.whatwg.org/#dom-document-createelement
WebIDL::ExceptionOr<GC::Ref<Element>> Document::create_element(String const& a_local_name, Variant<String, ElementCreationOptions> const& options)
WebIDL::ExceptionOr<GC::Ref<Element>> Document::create_element(String const& local_name, Variant<String, ElementCreationOptions> const& options)
{
auto local_name = a_local_name.to_byte_string();
// 1. If localName does not match the Name production, then throw an "InvalidCharacterError" DOMException.
if (!is_valid_name(a_local_name))
if (!is_valid_name(local_name))
return WebIDL::InvalidCharacterError::create(realm(), "Invalid character in tag name."_string);
// 2. If this is an HTML document, then set localName to localName in ASCII lowercase.
if (document_type() == Type::HTML)
local_name = local_name.to_lowercase();
auto local_name_lower = document_type() == Type::HTML
? local_name.to_ascii_lowercase()
: local_name;
// 3. Let is be null.
Optional<String> is_value;
@ -2100,7 +2099,7 @@ WebIDL::ExceptionOr<GC::Ref<Element>> Document::create_element(String const& a_l
namespace_ = Namespace::HTML;
// 6. Return the result of creating an element given this, localName, namespace, null, is, and with the synchronous custom elements flag set.
return TRY(DOM::create_element(*this, FlyString::from_utf8_without_validation(local_name.bytes()), move(namespace_), {}, move(is_value), true));
return TRY(DOM::create_element(*this, FlyString::from_utf8_without_validation(local_name_lower.bytes()), move(namespace_), {}, move(is_value), true));
}
// https://dom.spec.whatwg.org/#dom-document-createelementns