Skip to content

Commit 4bfa713

Browse files
domenicannevk
authored andcommitted
Simplify the reentrance guard for custom element definition
Previously, we would allow reentrance as long as it was not with the same name or constructor as was currently being defined, using the mechanism of a "set of being-defined names" and "set of being-defined constructors". This was overly complex, given that there are not really any use cases for defining a custom element in a getter triggered by the element definition algorithm. So instead, we move to just using an overall reentrance-guard flag. Fixes WICG/webcomponents#545.
1 parent 00b9b91 commit 4bfa713

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

source

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66355,12 +66355,9 @@ dictionary <dfn>ElementDefinitionOptions</dfn> {
6635566355
data-x="concept-custom-element-definition-local-name">local name</span>, or <span
6635666356
data-x="concept-custom-element-definition-constructor">constructor</span>.</p>
6635766357

66358-
<p>Every <code>CustomElementsRegistry</code> also has a <dfn>set of being-defined names</dfn> and
66359-
a <dfn>set of being-defined constructors</dfn>, containing <span data-x="valid custom element
66360-
name">valid custom element names</span> and JavaScript function objects, respectively. These are
66361-
used to ensure that when script executes during <span>element definition</span>, which can
66362-
reentrantly cause <span>element definition</span> again, the script cannot define another element
66363-
using the same name or constructor.</p>
66358+
<p>Every <code>CustomElementsRegistry</code> also has an <dfn>element definition is running</dfn>
66359+
flag which is used to prevent reentrant invocations of <span>element definition</span>. It is
66360+
initially unset.</p>
6636466361

6636566362
<p>Every <code>CustomElementsRegistry</code> also has a <dfn>when-defined promise map</dfn>,
6636666363
mapping <span data-x="valid custom element name">valid custom element names</span> to promises. It
@@ -66448,20 +66445,11 @@ dictionary <dfn>ElementDefinitionOptions</dfn> {
6644866445
<span>"<code>NotSupportedError</code>"</span> <code>DOMException</code> and abort these
6644966446
steps.</p></li>
6645066447

66451-
<li><p>If this <code>CustomElementsRegistry</code>'s <span>set of being-defined names</span>
66452-
contains <var>name</var>, then throw a <span>"<code>NotSupportedError</code>"</span>
66453-
<code>DOMException</code> and abort these steps.</p></li>
66454-
6645566448
<li><p>If this <code>CustomElementsRegistry</code> contains an entry with <span
6645666449
data-x="concept-custom-element-definition-constructor">constructor</span> <var>constructor</var>,
6645766450
then throw a <span>"<code>NotSupportedError</code>"</span> <code>DOMException</code> and abort
6645866451
these steps.</p></li>
6645966452

66460-
<li><p>If this <code>CustomElementsRegistry</code>'s <span>set of being-defined
66461-
constructors</span> contains <var>constructor</var>, then throw a
66462-
<span>"<code>NotSupportedError</code>"</span> <code>DOMException</code> and abort these
66463-
steps.</p></li>
66464-
6646566453
<li><p>Let <var>localName</var> be <var>name</var>.</p></li>
6646666454

6646766455
<li><p>Let <var>extends</var> be the value of the <code data-x="">extends</code> member of
@@ -66483,11 +66471,12 @@ dictionary <dfn>ElementDefinitionOptions</dfn> {
6648366471
</ol>
6648466472
</li>
6648566473

66486-
<li><p>Add <var>name</var> to this <code>CustomElementsRegistry</code>'s <span>set of
66487-
being-defined names</span>.</p></li>
66474+
<li><p>If this <code>CustomElementsRegistry</code>'s <span>element definition is running</span>
66475+
flag is set, then throw a <span>"<code>NotSupportedError</code>"</span> <code>DOMException</code>
66476+
and abort these steps.</p></li>
6648866477

66489-
<li><p>Add <var>constructor</var> to this <code>CustomElementsRegistry</code>'s <span>set of
66490-
being-defined constructors</span>.</p></li>
66478+
<li><p>Set this <code>CustomElementsRegistry</code>'s <span>element definition is running</span>
66479+
flag.</p></li>
6649166480

6649266481
<li>
6649366482
<p>Run the following substeps while catching any exceptions:</p>
@@ -66540,18 +66529,15 @@ dictionary <dfn>ElementDefinitionOptions</dfn> {
6654066529
</ol>
6654166530
</ol>
6654266531

66543-
<p>Then, perform the following substeps, regardless of whether the above steps threw an
66544-
exception or not:</p>
66532+
<p>Then, perform the following substep, regardless of whether the above steps threw an exception
66533+
or not:</p>
6654566534

6654666535
<ol>
66547-
<li><p>Remove <var>name</var> from this <code>CustomElementsRegistry</code>'s <span>set of
66548-
being-defined names</span>.</p></li>
66549-
66550-
<li><p>Remove <var>constructor</var> from this <code>CustomElementsRegistry</code>'s <span>set
66551-
of being-defined constructors</span>.</p></li>
66536+
<li><p>Unset this <code>CustomElementsRegistry</code>'s <span>element definition is
66537+
running</span> flag.</p></li>
6655266538
</ol>
6655366539

66554-
<p>Finally, if the first set of steps threw an exception, then rethrow that exception, and
66540+
<p>Finally, if the first set of substeps threw an exception, then rethrow that exception, and
6655566541
terminate this algorithm. Otherwise, continue onward.</p>
6655666542
</li>
6655766543

0 commit comments

Comments
 (0)