Re: [dom] HTMLCollection.namedItem() vs supported property names (#104)

@annevk Not sure who would be better.  Maybe @ms2ger in some cases.  Maybe Olli, but not sure what his Github account is.

I had not realized that the handling of the "name" attribute in `HTMLCollection.namedItem` and `HTMLCollection`'s supported names list was different in the spec.  In Gecko, these are aliases for each other.  And both have ignored the namespace of the element, for both name and id, since forever.  I don't think it would be a problem to check for HTML elements before checking the name.

Hilariously, Gecko _does_ check for HTML (though with some "XXX, is this part of the spec stable" comments) if you ask the object for its supported names directly.  So for example:

    <script>
      var parent = document.createElement("div")
      var child = document.createElementNS("", "x");
      child.setAttribute("name", "a");
      parent.appendChild(child);
      var child = document.createElement("y");
      child.setAttribute("name", "b");
      parent.appendChild(child);
      var kids = parent.children;
      console.log(Object.getOwnPropertyNames(kids)+"");
      console.log(kids.hasOwnProperty("a"));
      console.log(kids.hasOwnProperty("b"));
    </script>

logs, in Gecko:

    0,1,b
    true
    true

In Chrome it logs:

    0,1,b
    false
    true

which is at least self-consistent.  In Safari it logs:

    0,1,constructor,length
    false
    true

so it's got a buggy `getOwnPropertyNames` situation too.  Anyway, always checking for HTML before doing the name thing in HTMLCollection makes sense to me.

@ArkadiuszMichalski as far as your questions go:

1. There is no spec for what devtools should do.  In practice, devtools end up using something like for-in enumeration or `Object.getOwnPropertyNames` to do their work.  So in Firefox, in my testcase, if I type `kids.` in the console, "b" appears in the completion list and "a" does not.  For `NamedNodeMap`, still in Gecko, looks like the code dates back to when there was no way to make the supported names non-enumerable but we wanted them non-enumerable on `NamedNodeMap`, so we just claim to not have any when asked directly.  Should get fixed.  I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1222079 and looks like Chrome at least has a similar bug.

2. `obj.hasOwnProperty` should return true if http://heycam.github.io/webidl/#dfn-named-property-visibility returns true for the given property name (or if the property was directly defined on the object, of course).  This may not be true for all supported property names, per that algorithm, but the ones for which `hasOwnProperty` returns false are also the ones for which `[]` access should not invoke the named getter.

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/104#issuecomment-154133228

Received on Thursday, 5 November 2015 17:39:05 UTC