Skip to content

Commit

Permalink
Improve element reflection
Browse files Browse the repository at this point in the history
This attempts to make the following improvements:

1. Make it more clear that initializing attr is not the first step in an algorithm, but rather something that counts for all the list items.
2. Rewrite the associated element(s) fields as algorithms. As there are no downstream references so far this is a change we can still make.
3. Add another layer of caching that is separate from the FrozenArray to avoid having to compare a list of elements with a FrozenArray directly.

This helps with #10219.
  • Loading branch information
annevk authored Mar 26, 2024
1 parent 7ad555e commit c589287
Showing 1 changed file with 39 additions and 32 deletions.
71 changes: 39 additions & 32 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -8315,19 +8315,18 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

<p>If a <span>reflected IDL attribute</span> has the type <code data-x=""><var>T</var>?</code>,
where <var>T</var> is either <code>Element</code> or an interface that inherits from
<code>Element</code>, then:
<code>Element</code>, then with <var>attr</var> being the <span>reflected content attribute
name</span>:</p>

<ul>
<li><p>Let <var>attr</var> be the <span>reflected content attribute name</span>.</p></li>

<li><p>Its <span>reflected target</span> has an <dfn>explicitly set
<var>attr</var>-element</dfn>, which is a weak reference to an element or null. It is initially
null.</p></li>

<li>
<p>Its <span>reflected target</span> has an <dfn for="Element,ElementInternals"
export><var>attr</var>-associated element</dfn>. To compute the <span><var>attr</var>-associated
element</span> for such a <span>reflected target</span> <var>reflectedTarget</var>:</p>
<p>Its <span>reflected target</span> <var>reflectedTarget</var> has a <dfn
for="Element,ElementInternals" export id="attr-associated-element">get the
<var>attr</var>-associated element</dfn> algorithm, that runs these steps:</p>

<ol>
<li><p>Let <var>element</var> be the result of running <var>reflectedTarget</var>'s <span>get
Expand Down Expand Up @@ -8371,8 +8370,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
</ol>
</li>

<li><p>The getter steps are to return <span>this</span>'s <span><var>attr</var>-associated
element</span>.</p></li>
<li><p>The getter steps are to return the result of running <span>this</span>'s <span>get the
<var>attr</var>-associated element</span>.</p></li>

<li>
<p>The setter steps are:</p>
Expand Down Expand Up @@ -8421,24 +8420,25 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

<p>If a <span>reflected IDL attribute</span> has the type <code
data-x="">FrozenArray&lt;<var>T</var>&gt;?</code>, where <var>T</var> is either
<code>Element</code> or an interface that inherits from <code>Element</code>, then:</p>
<code>Element</code> or an interface that inherits from <code>Element</code>, then with
<var>attr</var> being the <span>reflected content attribute name</span>:</p>

<ul>
<li><p>Let <var>attr</var> be the <span>reflected content attribute name</span>.</p></li>

<li><p>Its <span>reflected target</span> has an <dfn>explicitly set
<var>attr</var>-elements</dfn>, which is either a <span>list</span> of weak references to
elements or null. It is initially null.</p></li>

<li><p>Its <span>reflected target</span> has a <dfn>cached <var>attr</var>-associated
elements</dfn>, which is a <code data-x="">FrozenArray&lt;<var>T</var>&gt;?</code>. It is
elements</dfn>, which is a <span>list</span> of elements. It is initially « ».</p></li>

<li><p>Its <span>reflected target</span> has a <dfn>cached <var>attr</var>-associated
elements object</dfn>, which is a <code data-x="">FrozenArray&lt;<var>T</var>&gt;?</code>. It is
initially null.</p></li>

<li>
<p>Its <span>reflected target</span> has an <dfn for="Element,ElementInternals"
export><var>attr</var>-associated elements</dfn>. To compute the
<span><var>attr</var>-associated elements</span> for such a <span>reflected target</span>
<var>reflectedTarget</var>:</p>
<p>Its <span>reflected target</span> <var>reflectedTarget</var> has a <dfn
for="Element,ElementInternals" export id="attr-associated-elements">get the
<var>attr</var>-associated elements</dfn> algorithm, which runs these steps:</p>

<ol>
<li><p>Let <var>elements</var> be an empty <span>list</span>.</p></li>
Expand Down Expand Up @@ -8515,19 +8515,22 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<p>The getter steps are:</p>

<ol>
<li><p>Let <var>elements</var> be <span>this</span>'s <span><var>attr</var>-associated
elements</span>.</p></li>
<li><p>Let <var>elements</var> be the result of running <span>this</span>'s <span>get the
<var>attr</var>-associated elements</span>.</p></li>

<li><p>If the contents of <var>elements</var> is equal to the contents of <span>this</span>'s
<span>cached <var>attr</var>-associated elements</span>, then return <span>this</span>'s
<span>cached <var>attr</var>-associated elements</span>.</p></li>
<span>cached <var>attr</var>-associated elements object</span>.</p></li>

<li><p>Let <var>elementsAsFrozenArray</var> be <var>elements</var>, <span
data-x="concept-idl-convert">converted</span> to a <code
data-x="">FrozenArray&lt;<var>T</var>&gt;?</code>.</p></li>

<li><p>Set <span>this</span>'s <span>cached <var>attr</var>-associated elements</span> to
<var>elementsAsFrozenArray</var>.</p></li>
<var>elements</var>.</p></li>

<li><p>Set <span>this</span>'s <span>cached <var>attr</var>-associated elements object</span>
to <var>elementsAsFrozenArray</var>.</p></li>

<li><p>Return <var>elementsAsFrozenArray</var>.</p></li>
</ol>
Expand Down Expand Up @@ -8614,13 +8617,15 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
</ul>

<p>For those, specification authors must use the <span>reflected target</span>'s
<span><var>attr</var>-associated element</span> and <span><var>attr</var>-associated
elements</span>, respectively. The content attribute presence and value must not be used as they
cannot be fully synchronized with the <span>reflected IDL attribute</span>.</p>
<span>get the <var>attr</var>-associated element</span> and <span>get the
<var>attr</var>-associated elements</span>, respectively. The content attribute presence and value
must not be used as they cannot be fully synchronized with the <span>reflected IDL
attribute</span>.</p>

<p>A <span>reflected target</span>'s <span>explicitly set <var>attr</var>-element</span>,
<span>explicitly set <var>attr</var>-elements</span>, and <span>cached <var>attr</var>-associated
elements</span> are to be treated as internal implementation details and not to be built upon.</p>
<span>explicitly set <var>attr</var>-elements</span>, <span>cached <var>attr</var>-associated
elements</span>, and <span>cached <var>attr</var>-associated elements object</span> are to be
treated as internal implementation details and not to be built upon.</p>

</div>

Expand Down Expand Up @@ -14607,12 +14612,13 @@ interface <dfn interface>DOMStringMap</dfn> {
<p>If <var>element</var>'s <span>attached internals</span> is non-null:</p>

<ol>
<li><p>If <var>element</var>'s <span>attached internals</span>'s <span data-x="attr-associated
element"><var>stateOrProperty</var>-associated element</span> exists, then return it.</p></li>
<li><p>If <var>element</var>'s <span>attached internals</span>'s <span data-x="get the
attr-associated element">get the <var>stateOrProperty</var>-associated element</span> exists,
then return the result of running it.</p></li>

<li><p>If <var>element</var>'s <span>attached internals</span>'s <span data-x="attr-associated
elements"><var>stateOrProperty</var>-associated elements</span> exist, then return
them.</p></li>
<li><p>If <var>element</var>'s <span>attached internals</span>'s <span data-x="get the
attr-associated elements">get the <var>stateOrProperty</var>-associated elements</span> exists,
then return return the result of running it.</p></li>
</ol>
<!-- We check these first as they end up being redundantly stored in element's internal content
attribute map with an empty string value. -->
Expand Down Expand Up @@ -85617,8 +85623,9 @@ dictionary <dfn dictionary>DragEventInit</dfn> : <span>MouseEventInit</span> {
<li><p>If <var>node</var> has a <span>form owner</span> and <var>node</var> is a <span
data-x="concept-submit-button">submit button</span>, then return null.</p></li>

<li><p>Let <var>popoverElement</var> be <var>node</var>'s <span data-x="attr-associated
element"><code data-x="">popovertarget</code>-associated element</span>.</p></li>
<li><p>Let <var>popoverElement</var> be the result of running <var>node</var>'s <span data-x="get
the attr-associated element">get the <code data-x="">popovertarget</code>-associated
element</span>.</p></li>

<li><p>If <var>popoverElement</var> is null, then return null.</p></li>

Expand Down

0 comments on commit c589287

Please sign in to comment.