Skip to content

Commit

Permalink
Add customElements.getName(constructor)
Browse files Browse the repository at this point in the history
In CustomElements v0 you could use the `.name` field to get the defined
tag name, but CustomElements v1 does not offer such a field. `localName`
can be used within an instance but this prohibits use in, for example,
static methods.

This was discussed in the WCCG F2F, tracked in
WICG/webcomponents#566. The conclusion of the
F2F was to write up a spec change and WPT tests.
  • Loading branch information
keithamus authored Jun 30, 2023
1 parent 66e162f commit 76204f7
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -70865,6 +70865,7 @@ document.body.append(parent);
interface <dfn interface>CustomElementRegistry</dfn> {
[<span>CEReactions</span>] undefined <span data-x="dom-CustomElementRegistry-define">define</span>(DOMString name, <span>CustomElementConstructor</span> constructor, optional <span>ElementDefinitionOptions</span> options = {});
(<span>CustomElementConstructor</span> or undefined) <span data-x="dom-CustomElementRegistry-get">get</span>(DOMString name);
DOMString? <span data-x="dom-CustomElementRegistry-getName">getName</span>(CustomElementConstructor constructor);
Promise&lt;<span>CustomElementConstructor</span>&gt; <span data-x="dom-CustomElementRegistry-whenDefined">whenDefined</span>(DOMString name);
[<span>CEReactions</span>] undefined <span data-x="dom-CustomElementRegistry-upgrade">upgrade</span>(<span>Node</span> root);
};
Expand Down Expand Up @@ -70897,8 +70898,8 @@ dictionary <dfn dictionary>ElementDefinitionOptions</dfn> {
<dt><code data-x=""><var>window</var>.<span data-x="dom-window-customElements">customElements</span>.<span subdfn data-x="dom-CustomElementRegistry-define">define</span>(<var>name</var>,
<var>constructor</var>)</code></dt>

<dd>Defines a new <span>custom element</span>, mapping the given name to the given constructor as
an <span>autonomous custom element</span>.</dd>
<dd>Defines a new <span>custom element</span>, mapping the given name to the given constructor
as an <span>autonomous custom element</span>.</dd>


<dt><code data-x=""><var>window</var>.<span data-x="dom-window-customElements">customElements</span>.<span data-x="dom-CustomElementRegistry-define">define</span>(<var>name</var>, <var>constructor</var>,
Expand All @@ -70915,6 +70916,11 @@ dictionary <dfn dictionary>ElementDefinitionOptions</dfn> {
<dd>Retrieves the <span>custom element constructor</span> defined for the given <span data-x="concept-custom-element-definition-name">name</span>. Returns undefined if there is no
<span>custom element definition</span> with the given <span data-x="concept-custom-element-definition-name">name</span>.</dd>

<dt><code data-x=""><var>window</var>.<span data-x="dom-window-customElements">customElements</span>.<span subdfn data-x="dom-CustomElementRegistry-getName">getName</span>(<var>constructor</var>)</code></dt>

<dd>Retrieves the given name for a <span>custom element</span> defined for the given <span data-x="concept-custom-element-definition-constructor">constructor</span>. Returns null if there is no
<span>custom element definition</span> with the given <span data-x="concept-custom-element-definition-constructor">constructor</span>.</dd>

<dt><code data-x=""><var>window</var>.<span data-x="dom-window-customElements">customElements</span>.<span subdfn data-x="dom-CustomElementRegistry-whenDefined">whenDefined</span>(<var>name</var>)</code></dt>

<dd>Returns a promise that will be fulfilled with the <span>custom element</span>'s constructor
Expand Down Expand Up @@ -71154,6 +71160,19 @@ dictionary <dfn dictionary>ElementDefinitionOptions</dfn> {
<li><p>Otherwise, return undefined.</p></li>
</ol>

<p>The <dfn method for="CustomElementRegistry"><code
data-x="dom-CustomElementRegistry-getName">getName(<var>constructor</var>)</code></dfn> method
steps are:</p>

<ol>
<li><p>If this <code>CustomElementRegistry</code> contains an entry with <span
data-x="concept-custom-element-definition-constructor">constructor</span>
<var>constructor</var>, then return that entry's <span
data-x="concept-custom-element-definition-name">name</span>.</p></li>

<li><p>Return null.</p></li>
</ol>

<p>When invoked, the <dfn method for="CustomElementRegistry"><code
data-x="dom-CustomElementRegistry-whenDefined">whenDefined(<var>name</var>)</code></dfn> method
must run these steps:</p>
Expand Down Expand Up @@ -139077,6 +139096,7 @@ INSERT INTERFACES HERE
葛依寧 (Kat Hackett),
Kathy Walton,
河童エクマ(Kawarabe Ecma)<!-- heppokofrontend on GitHub -->
Keith Cirkel, <!-- keithamus on GitHub -->
Keith Rollin,
Keith Yeung,
Kelly Ford,
Expand Down

0 comments on commit 76204f7

Please sign in to comment.