Skip to content

Commit

Permalink
LibWeb: Match spec changes for "custom element registry" concept
Browse files Browse the repository at this point in the history
  • Loading branch information
AtkinsSJ committed Dec 18, 2024
1 parent ce65457 commit 7aef8c9
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 73 deletions.
16 changes: 8 additions & 8 deletions Libraries/LibWeb/DOM/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3156,31 +3156,31 @@ void Document::set_window(HTML::Window& window)
// https://html.spec.whatwg.org/multipage/custom-elements.html#look-up-a-custom-element-definition
GC::Ptr<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.
// 1. If namespace is not the HTML namespace, then return null.
if (namespace_ != Namespace::HTML)
return nullptr;

// 2. If document's browsing context is null, return null.
// 2. If document's browsing context is null, then return null.
if (!browsing_context())
return nullptr;

// 3. Let registry be document's relevant global object's CustomElementRegistry object.
// 3. Let registry be document's relevant global object's custom element registry.
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 = local_name;
auto maybe_definition = registry->get_definition_with_name_and_local_name(converted_local_name.to_string(), converted_local_name.to_string());
// 4. If registry's custom element definition set contains an item with name and local name both equal to localName, then return that item.
auto converted_local_name = local_name.to_string();
auto maybe_definition = registry->get_definition_with_name_and_local_name(converted_local_name, converted_local_name);
if (maybe_definition)
return maybe_definition;

// 5. If there is a custom element definition in registry with name equal to is and local name equal to localName, return that custom element definition.
// 5. If registry's custom element definition set contains an item with name equal to is and local name equal to localName, then return that item.
// 6. Return null.

// NOTE: If `is` has no value, it can never match as custom element definitions always have a name and localName (i.e. not stored as Optional<String>)
if (!is.has_value())
return nullptr;

return registry->get_definition_with_name_and_local_name(is.value(), converted_local_name.to_string());
return registry->get_definition_with_name_and_local_name(is.value(), converted_local_name);
}

CSS::StyleSheetList& Document::style_sheets()
Expand Down
Loading

0 comments on commit 7aef8c9

Please sign in to comment.