mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
LibWeb: Add customElements.getName
This commit is contained in:
parent
51f5da00d7
commit
8d593bcfeb
Notes:
sideshowbarker
2024-07-17 05:00:08 +09:00
Author: https://github.com/keithamus 🔰 Commit: https://github.com/LadybirdBrowser/ladybird/commit/8d593bcfeb Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/458 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/tcl3
3 changed files with 17 additions and 0 deletions
|
@ -337,6 +337,21 @@ Variant<JS::Handle<WebIDL::CallbackType>, JS::Value> CustomElementRegistry::get(
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-getname
|
||||||
|
Optional<String> CustomElementRegistry::get_name(JS::Handle<WebIDL::CallbackType> 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
|
// https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-whendefined
|
||||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> CustomElementRegistry::when_defined(String const& name)
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> CustomElementRegistry::when_defined(String const& name)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,7 @@ public:
|
||||||
|
|
||||||
JS::ThrowCompletionOr<void> define(String const& name, WebIDL::CallbackType* constructor, ElementDefinitionOptions options);
|
JS::ThrowCompletionOr<void> define(String const& name, WebIDL::CallbackType* constructor, ElementDefinitionOptions options);
|
||||||
Variant<JS::Handle<WebIDL::CallbackType>, JS::Value> get(String const& name) const;
|
Variant<JS::Handle<WebIDL::CallbackType>, JS::Value> get(String const& name) const;
|
||||||
|
Optional<String> get_name(JS::Handle<WebIDL::CallbackType> const& constructor) const;
|
||||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> when_defined(String const& name);
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> when_defined(String const& name);
|
||||||
void upgrade(JS::NonnullGCPtr<DOM::Node> root) const;
|
void upgrade(JS::NonnullGCPtr<DOM::Node> root) const;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
interface CustomElementRegistry {
|
interface CustomElementRegistry {
|
||||||
[CEReactions] undefined define(DOMString name, CustomElementConstructor constructor, optional ElementDefinitionOptions options = {});
|
[CEReactions] undefined define(DOMString name, CustomElementConstructor constructor, optional ElementDefinitionOptions options = {});
|
||||||
(CustomElementConstructor or undefined) get(DOMString name);
|
(CustomElementConstructor or undefined) get(DOMString name);
|
||||||
|
DOMString? getName(CustomElementConstructor constructor);
|
||||||
Promise<CustomElementConstructor> whenDefined(DOMString name);
|
Promise<CustomElementConstructor> whenDefined(DOMString name);
|
||||||
[CEReactions] undefined upgrade(Node root);
|
[CEReactions] undefined upgrade(Node root);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue