1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:07:34 +00:00

LibWeb: Pass DOM namespace strings as FlyString in more places

This commit is contained in:
Andreas Kling 2023-11-04 10:19:21 +01:00
parent b341aeb5c1
commit 6b20a109c6
7 changed files with 32 additions and 33 deletions

View file

@ -2432,10 +2432,10 @@ void Document::set_window(HTML::Window& window)
}
// https://html.spec.whatwg.org/multipage/custom-elements.html#look-up-a-custom-element-definition
JS::GCPtr<HTML::CustomElementDefinition> Document::lookup_custom_element_definition(DeprecatedFlyString const& namespace_, DeprecatedFlyString const& local_name, Optional<String> const& is) const
JS::GCPtr<HTML::CustomElementDefinition> Document::lookup_custom_element_definition(Optional<FlyString> const& namespace_, FlyString const& local_name, Optional<String> const& is) const
{
// 1. If namespace is not the HTML namespace, return null.
if (namespace_ != Namespace::HTML)
if (namespace_ != MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)))
return nullptr;
// 2. If document's browsing context is null, return null.
@ -2446,8 +2446,8 @@ JS::GCPtr<HTML::CustomElementDefinition> Document::lookup_custom_element_definit
auto registry = verify_cast<HTML::Window>(relevant_global_object(*this)).custom_elements();
// 4. If there is custom element definition in registry with name and local name both equal to localName, return that custom element definition.
auto converted_local_name = String::from_deprecated_string(local_name).release_value_but_fixme_should_propagate_errors();
auto maybe_definition = registry->get_definition_with_name_and_local_name(converted_local_name, converted_local_name);
auto converted_local_name = local_name;
auto maybe_definition = registry->get_definition_with_name_and_local_name(converted_local_name.to_string(), converted_local_name.to_string());
if (maybe_definition)
return maybe_definition;
@ -2458,7 +2458,7 @@ JS::GCPtr<HTML::CustomElementDefinition> Document::lookup_custom_element_definit
if (!is.has_value())
return nullptr;
return registry->get_definition_with_name_and_local_name(is.value(), converted_local_name);
return registry->get_definition_with_name_and_local_name(is.value(), converted_local_name.to_string());
}
CSS::StyleSheetList& Document::style_sheets()

View file

@ -435,7 +435,7 @@ public:
bool has_active_favicon() const { return m_active_favicon; }
void check_favicon_after_loading_link_resource();
JS::GCPtr<HTML::CustomElementDefinition> lookup_custom_element_definition(DeprecatedFlyString const& namespace_, DeprecatedFlyString const& local_name, Optional<String> const& is) const;
JS::GCPtr<HTML::CustomElementDefinition> lookup_custom_element_definition(Optional<FlyString> const& namespace_, FlyString const& local_name, Optional<String> const& is) const;
void increment_throw_on_dynamic_markup_insertion_counter(Badge<HTML::HTMLParser>);
void decrement_throw_on_dynamic_markup_insertion_counter(Badge<HTML::HTMLParser>);

View file

@ -647,7 +647,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ShadowRoot>> Element::attach_shadow(ShadowR
// 3. If thiss local name is a valid custom element name, or thiss is value is not null, then:
if (HTML::is_valid_custom_element_name(local_name()) || m_is_value.has_value()) {
// 1. Let definition be the result of looking up a custom element definition given thiss node document, its namespace, its local name, and its is value.
auto definition = document().lookup_custom_element_definition(namespace_(), local_name().to_deprecated_fly_string(), m_is_value);
auto definition = document().lookup_custom_element_definition(namespace_uri(), local_name(), m_is_value);
// 2. If definition is not null and definitions disable shadow is true, then throw a "NotSupportedError" DOMException.
if (definition && definition->disable_shadow())
@ -1844,7 +1844,7 @@ JS::ThrowCompletionOr<void> Element::upgrade_element(JS::NonnullGCPtr<HTML::Cust
void Element::try_to_upgrade()
{
// 1. Let definition be the result of looking up a custom element definition given element's node document, element's namespace, element's local name, and element's is value.
auto definition = document().lookup_custom_element_definition(namespace_(), local_name().to_deprecated_fly_string(), m_is_value);
auto definition = document().lookup_custom_element_definition(namespace_uri(), local_name(), m_is_value);
// 2. If definition is not null, then enqueue a custom element upgrade reaction given element and definition.
if (definition)

View file

@ -504,8 +504,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(Document& document
// NOTE: We collapse this into just returning an element where necessary.
// 4. Let definition be the result of looking up a custom element definition given document, namespace, localName, and is.
DeprecatedFlyString deprecated_namespace = namespace_.has_value() ? namespace_.value().to_deprecated_fly_string() : DeprecatedFlyString {};
auto definition = document.lookup_custom_element_definition(deprecated_namespace, local_name.to_deprecated_fly_string(), is_value);
auto definition = document.lookup_custom_element_definition(namespace_, local_name, is_value);
// 5. If definition is non-null, and definitions name is not equal to its local name (i.e., definition represents a customized built-in element), then:
if (definition && definition->name() != definition->local_name()) {