This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 24624 - Is the order of HTMLCollection's supported property names valid?
Summary: Is the order of HTMLCollection's supported property names valid?
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-11 22:05 UTC by Chris Dumez
Modified: 2014-02-12 15:56 UTC (History)
3 users (show)

See Also:


Attachments

Description Chris Dumez 2014-02-11 22:05:51 UTC
The current dom spec says at:
http://dom.spec.whatwg.org/#interface-htmlcollection

"""
The supported property names are the values from the list returned by these steps:

    1. Let result be an empty list.

    2. For each element represented by the collection, in tree order, run these substes:

      1. If element is in the HTML namespace and has a name attribute whose value is neither the empty string nor is in result, append element's name attribute value to result.

      2. If element has an ID which is neither the empty string nor is in result, append element's ID to result. 

    3. Return result. 
"""

This means that when an element contributes both its id and name, the name will precede the id in result. This seems odd because this is the opposite behavior of HTMLCollection subclasses:
http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#collections-0

The HTML5 spec for these collections always indicates:
"with the id of an element preceding its name if it contributes both".

Behavior of existing browsers:
- Firefox 27 has the id preceding the name (see http://jsfiddle.net/59wrt/2/)
- IE11 does not return the Element's id if the Element contributes its name :(
- Chrome. This is not supported yet in stable releases but I have recently implemented this as per the spec (http://code.google.com/p/chromium/issues/detail?id=341269). For HTMLCollection, the name precedes the id. For HTMLCollection subclasses the id precedes the name. However, this has not shipped yet so there is still time to fix it if the spec gets updated.
Comment 1 Boris Zbarsky 2014-02-11 23:24:45 UTC
Arguably, we should not enumerate the names/ids at all and just enumerate the indices.  That's what Gecko used to do, and more closely matches what websites expect, which is for every element to be the value for one single key during the enumeration.

Of course getOwnPropertyNames still needs to be defined.
Comment 2 Anne 2014-02-12 10:57:28 UTC
I agree with bz that enumeration should ideally only give you back elements. Can anyone help out with IDL hooks for that?

Christophe, do I understand it correctly that you would like step 2.1 and 2.2 swapped? Aligning this with HTML makes sense to me. I should have been more careful here.
Comment 3 Chris Dumez 2014-02-12 13:18:57 UTC
(In reply to Anne from comment #2)
> Christophe, do I understand it correctly that you would like step 2.1 and
> 2.2 swapped? Aligning this with HTML makes sense to me. I should have been
> more careful here.

Yes, you understood correctly. This is would be great.
Comment 4 Anne 2014-02-12 13:26:12 UTC
https://github.com/whatwg/dom/commit/8b9338049201d075b1cae365562dfb40fe46d567

Leaving open for the comment bz made.
Comment 5 Boris Zbarsky 2014-02-12 15:16:36 UTC
We have IDL hooks for this.  Or rather prose hooks.  See <http://heycam.github.io/webidl/#property-enumeration>, but basically you can just say that some subset (or all) of the named properties are "unenumerable" to have them not show up during enumeration.