diff --git a/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp b/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp index 92ac445ba64..471ac58d692 100644 --- a/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp +++ b/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp @@ -337,6 +337,21 @@ Variant, JS::Value> CustomElementRegistry::get( return JS::js_undefined(); } +// https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-getname +Optional CustomElementRegistry::get_name(JS::Handle const& constructor) const +{ + // 1. If this CustomElementRegistry contains an entry with constructor constructor, then return that entry's name. + auto existing_definition_iterator = m_custom_element_definitions.find_if([&constructor](auto const& definition) { + return definition->constructor().callback == constructor.cell()->callback; + }); + + if (!existing_definition_iterator.is_end()) + return (*existing_definition_iterator)->name(); + + // 2. Return null. + return {}; +} + // https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-whendefined WebIDL::ExceptionOr> CustomElementRegistry::when_defined(String const& name) { diff --git a/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.h b/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.h index 6ac0ed90224..a20785e012a 100644 --- a/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.h +++ b/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.h @@ -26,6 +26,7 @@ public: JS::ThrowCompletionOr define(String const& name, WebIDL::CallbackType* constructor, ElementDefinitionOptions options); Variant, JS::Value> get(String const& name) const; + Optional get_name(JS::Handle const& constructor) const; WebIDL::ExceptionOr> when_defined(String const& name); void upgrade(JS::NonnullGCPtr root) const; diff --git a/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.idl b/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.idl index b295a438346..ce862ab7dec 100644 --- a/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.idl +++ b/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.idl @@ -5,6 +5,7 @@ interface CustomElementRegistry { [CEReactions] undefined define(DOMString name, CustomElementConstructor constructor, optional ElementDefinitionOptions options = {}); (CustomElementConstructor or undefined) get(DOMString name); + DOMString? getName(CustomElementConstructor constructor); Promise whenDefined(DOMString name); [CEReactions] undefined upgrade(Node root); };