Skip to content

Commit 24b8c4f

Browse files
committed
Fix #775: update HTMLAllCollection to match reality better
As discussed extensively in that issue, in most browsers HTMLAllCollection is more lenient than previously believed, especially with regard to its item() method and legacycaller behavior.
1 parent 50c6248 commit 24b8c4f

File tree

1 file changed

+66
-45
lines changed

1 file changed

+66
-45
lines changed

source

Lines changed: 66 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7142,11 +7142,9 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
71427142

71437143
<p>The <code>HTMLAllCollection</code> interface is used for the legacy <code
71447144
data-x="dom-document-all">document.all</code> attribute. It operates similarly to
7145-
<code>HTMLCollection</code>; the main differences are that its <code
7146-
data-x="dom-HTMLAllCollection-namedItem">namedItem()</code> method returns an
7147-
<code>HTMLCollection</code> object when there are multiple matching elements, and that its <code
7148-
data-x="dom-HTMLAllCollection-item">item()</code> method can be used as a synonym for its <code
7149-
data-x="dom-HTMLAllCollection-namedItem">namedItem()</code> method.</p>
7145+
<code>HTMLCollection</code>; the main differences are that it allows a staggering variety of
7146+
different (ab)uses of its methods to all end up returning something, and that it can be called as
7147+
a function as an alternative to property access.</p>
71507148

71517149
<p class="note">All <code>HTMLAllCollection</code> objects are rooted at a <code>Document</code>
71527150
and have a filter that matches all elements, so the elements <span>represented by the
@@ -7156,9 +7154,9 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
71567154
<pre class="idl">[LegacyUnenumerableNamedProperties]
71577155
interface <dfn>HTMLAllCollection</dfn> {
71587156
readonly attribute unsigned long <span data-x="dom-HTMLAllCollection-length">length</span>;
7159-
getter <span>Element</span>? <span data-x="dom-HTMLAllCollection-item">item</span>(unsigned long index);
7160-
(<span>HTMLCollection</span> or <span>Element</span>)? <span data-x="dom-HTMLAllCollection-item-string">item</span>(DOMString name);
7161-
legacycaller getter (<span>HTMLCollection</span> or <span>Element</span>)? <span data-x="dom-HTMLAllCollection-namedItem">namedItem</span>(DOMString name);
7157+
getter <span>Element</span>? (unsigned long index);
7158+
getter (<span>HTMLCollection</span> or <span>Element</span>)? <span data-x="dom-HTMLAllCollection-namedItem">namedItem</span>(DOMString name);
7159+
legacycaller (<span>HTMLCollection</span> or <span>Element</span>)? <span data-x="dom-HTMLAllCollection-item">item</span>(optional DOMString nameOrIndex);
71627160
};</pre>
71637161

71647162
<dl class="domintro">
@@ -7169,13 +7167,14 @@ interface <dfn>HTMLAllCollection</dfn> {
71697167
</dd>
71707168

71717169
<dt><var>element</var> = <var>collection</var> . <code subdfn data-x="dom-HTMLAllCollection-item">item</code>(<var>index</var>)</dt>
7170+
<dt><var>element</var> = <var>collection</var>(<var>index</var>)</dt>
71727171
<dt><var>element</var> = <var>collection</var>[<var>index</var>]</dt>
71737172
<dd>
7174-
<p>Returns the item with index <var>index</var> from the collection. The items are sorted in <span>tree order</span>.</p>
7173+
<p>Returns the item with index <var>index</var> from the collection (determined by <span>tree order</span>).</p>
71757174
</dd>
71767175

7177-
<dt><var>element</var> = <var>collection</var> . <code subdfn data-x="dom-HTMLAllCollection-item-string">item</code>(<var>name</var>)</dt>
7178-
<dt><var>collection</var> = <var>collection</var> . <code data-x="dom-HTMLAllCollection-item-string">item</code>(<var>name</var>)</dt>
7176+
<dt><var>element</var> = <var>collection</var> . <code data-x="dom-HTMLAllCollection-item">item</code>(<var>name</var>)</dt>
7177+
<dt><var>collection</var> = <var>collection</var> . <code data-x="dom-HTMLAllCollection-item">item</code>(<var>name</var>)</dt>
71797178
<dt><var>element</var> = <var>collection</var> . <code subdfn data-x="dom-HTMLAllCollection-namedItem">namedItem</code>(<var>name</var>)</dt>
71807179
<dt><var>collection</var> = <var>collection</var> . <code data-x="dom-HTMLAllCollection-namedItem">namedItem</code>(<var>name</var>)</dt>
71817180
<dt><var>element</var> = <var>collection</var>(<var>name</var>)</dt>
@@ -7199,6 +7198,43 @@ interface <dfn>HTMLAllCollection</dfn> {
71997198
<p>The object's <span>supported property indices</span> are as defined for
72007199
<code>HTMLCollection</code> objects.</p>
72017200

7201+
<p>The <span>supported property names</span> consist of the non-empty values of all the <code
7202+
data-x="attr-id">id</code> attributes of all the elements <span>represented by the
7203+
collection</span>, and the non-empty values of all the <code data-x="">name</code> attributes of
7204+
all the <span>"all"-named elements</span> <span>represented by the collection</span>, in
7205+
<span>tree order</span>, ignoring later duplicates, with the <code data-x="attr-id">id</code> of
7206+
an element preceding its <code data-x="">name</code> if it contributes both, they differ from each
7207+
other, and neither is the duplicate of an earlier entry.</p>
7208+
7209+
<p>On getting, the <dfn><code data-x="dom-HTMLAllCollection-length">length</code></dfn>
7210+
attribute must return the number of nodes <span>represented by the collection</span>.</p>
7211+
7212+
<p>The indexed property getter must return the result of <span
7213+
data-x="concept-get-all-indexed">getting the "all"-indexed element</span> from this
7214+
<code>HTMLAllCollection</code> given the passed index.</p>
7215+
7216+
<p>The <dfn><code data-x="dom-HTMLAllCollection-namedItem">namedItem(<var>name</var>)</code></dfn>
7217+
method must return the result of <span data-x="concept-get-all-named">getting the "all"-named
7218+
element(s)</span> from this <code>HTMLAllCollection</code> given <var>name</var>.</p>
7219+
7220+
<p>The <dfn><code data-x="dom-HTMLAllCollection-item">item(<var>nameOrIndex</var>)</code></dfn>
7221+
method (and the <code data-x="">legacycaller</code> behavior) must run the following steps:</p>
7222+
7223+
<ol>
7224+
<li><p>If <var>nameOrIndex</var> was not provided, return null.</p></li>
7225+
7226+
<li><p>If <var>nameOrIndex</var>, <span data-x="concept-idl-convert">converted</span> to a
7227+
JavaScript string value, is an <span>array index property name</span>, return the result of <span
7228+
data-x="concept-get-all-indexed">getting the "all"-indexed element</span> from this
7229+
<code>HTMLAllCollection</code> given the number represented by <var>nameOrIndex</var>.</p></li>
7230+
7231+
<li><p>Return the result of <span data-x="concept-get-all-named">getting the "all"-named
7232+
element(s)</span> from this <code>HTMLAllCollection</code> given
7233+
<var>nameOrIndex</var>.</p></li>
7234+
</ol>
7235+
7236+
<hr>
7237+
72027238
<!-- http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=2837 -->
72037239
<p>The following elements are <dfn>"all"-named elements</dfn>:
72047240
<code>a</code>, <!-- in some browsers -->
@@ -7219,53 +7255,37 @@ interface <dfn>HTMLAllCollection</dfn> {
72197255
<code>textarea</code> <!-- in some browsers -->
72207256
</p>
72217257

7222-
<p>The <span>supported property names</span> consist of the non-empty values of all the <code
7223-
data-x="attr-id">id</code> attributes of all the elements <span>represented by the
7224-
collection</span>, and the non-empty values of all the <code data-x="">name</code> attributes of
7225-
all the <span>"all"-named elements</span> <span>represented by the collection</span>, in
7226-
<span>tree order</span>, ignoring later duplicates, with the <code data-x="attr-id">id</code> of
7227-
an element preceding its <code data-x="">name</code> if it contributes both, they differ from each
7228-
other, and neither is the duplicate of an earlier entry.</p>
7229-
7230-
<p>On getting, the <dfn><code data-x="dom-HTMLAllCollection-length">length</code></dfn>
7231-
attribute must return the number of nodes <span>represented by the collection</span>.</p>
7258+
<p>To <dfn data-x="concept-get-all-indexed">get the "all"-indexed element</dfn> from an
7259+
<code>HTMLAllCollection</code> <var>collection</var> given an index <var>index</var>, return the
7260+
<var>index</var><sup>th</sup> element in <var>collection</var>, or null if there is no such
7261+
<var>index</var><sup>th</sup> element.</p>
72327262

7233-
<p>The <dfn><code data-x="dom-HTMLAllCollection-item">item(<var>index</var>)</code></dfn> method
7234-
must return the <var>index</var><sup>th</sup> element in the collection. If there is no
7235-
<var>index</var><sup>th</sup> element in the <span data-x="concept-collection">collection</span>,
7236-
then the method must return null.</p>
7237-
7238-
<p>The <dfn><code data-x="dom-HTMLAllCollection-item-string">item(<var>name</var>)</code></dfn> and <dfn><code data-x="dom-HTMLAllCollection-namedItem">namedItem(<var>name</var>)</code></dfn>
7239-
methods must act according to the following algorithm:</p>
7263+
<p>To <dfn data-x="concept-get-all-named">get the "all"-named element(s)</dfn> from an
7264+
<code>HTMLAllCollection</code> <var>collection</var> given a name <var>name</var>, perform the
7265+
following steps:</p>
72407266

72417267
<ol>
7242-
7243-
<li>If <var>name</var> is the empty string, return null and stop the algorithm.</li>
7268+
<li><p>If <var>name</var> is the empty string, return null.</p></li>
72447269

72457270
<li>
7246-
7247-
<p>Let <var>collection</var> be an <code>HTMLCollection</code> object rooted at the
7248-
same <code>Document</code> as the <code>HTMLAllCollection</code> object on which the method was
7249-
invoked, whose filter matches only elements that are either:</p>
7271+
<p>Let <var>subCollection</var> be an <code>HTMLCollection</code> object rooted at the same
7272+
<code>Document</code> as <var>collection</var>, whose filter matches only elements that are
7273+
either:</p>
72507274

72517275
<ul>
7276+
<li><p><span>"all"-named elements</span> with a <code data-x="">name</code> attribute equal to
7277+
<var>name</var>, or,</p></li>
72527278

7253-
<li><span>"all"-named elements</span> with a <code data-x="">name</code> attribute equal to
7254-
<var>name</var>, or,</li>
7255-
7256-
<li>elements with an <span data-x="concept-id">ID</span> equal to <var>name</var>.</li>
7257-
7279+
<li><p>elements with an <span data-x="concept-id">ID</span> equal to <var>name</var>.</p></li>
72587280
</ul>
7259-
72607281
</li>
72617282

7262-
<li>If, at the time the method is called, there is exactly one node in <var>collection</var>, then return that node and stop the algorithm.</li>
7263-
7264-
<li>Otherwise, if, at the time the method is called, <var>collection</var> is empty,
7265-
return null and stop the algorithm.</li>
7283+
<li><p>If there is exactly one element in <var>subCollection</var>, then return that
7284+
element.</p></li>
72667285

7267-
<li>Otherwise, return <var>collection</var>.</li>
7286+
<li><p>Otherwise, if <var>subCollection</var> is empty, return null.</p></li>
72687287

7288+
<li><p>Otherwise, return <var>subCollection</var>.</p></li>
72697289
</ol>
72707290

72717291
</div>
@@ -117160,6 +117180,7 @@ INSERT INTERFACES HERE
117160117180
Anthony Boyd,
117161117181
Anthony Bryan,
117162117182
Anthony Hickson,
117183+
Anthony Ramine,
117163117184
Anthony Ricaud,
117164117185
Antti Koivisto,
117165117186
Arkadiusz Michalski,

0 commit comments

Comments
 (0)