Bug 22749 - Common array iteration schemes fail on NamedNodeMaps.
Summary: Common array iteration schemes fail on NamedNodeMaps.
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 525.x (Safari 3.1)
Hardware: Mac (Intel) OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-08 20:26 PST by mikesamuel@gmail.com
Modified: 2022-05-31 10:32 PDT (History)
4 users (show)

See Also:


Attachments
test case (1.54 KB, text/html)
2008-12-09 03:29 PST, Alexey Proskuryakov
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description mikesamuel@gmail.com 2008-12-08 20:26:14 PST
Symptom
=======
The HTML below tries a number of common array iteration schemes over a form's elements list.

Safari is the only common browser that fails on the second, common one.  The third works on all browsers but is never used.

Note, Safari breaks in other ways if <input name=elements id=elements> is present.


Expected
========
In a NamedNodeMap or HtmlCollection, Elements with ids or name properties should not mask properties specified in the DOM2 Core or HTML APIs.



Test
====
<html>
  <head>
    <title>NamedNodeList Iteration</title>
  </head>
  <body>
    <form>
      <input name=length id=length>
      <input name=3 id=3>
      <input name=0 id=0>
    </form>
    <p>The correct output is</p>
    <ol>
    <li>i=0 : length
    <li>i=1 : 3
    <li>i=2 : 0
    </ol>

    <script>(function () {
      function testIteration(nodeList, description) {
        document.write('<h1>' + description + ' Method 1</h1><ul>');
        // Fails on IE6 & Opera9
        // Works on FF2, Safari3
        for (var i = 0, len = nodeList.length; i < len; ++i) {
          var node = nodeList[i];
          document.write('<li>i=' + i + ' : ' + node.name);
        }
        document.write('</ul>');

        document.write('<h1>' + description + ' Method 2</h1><ul>');
        // Works on IE6, Opera9, FF2
        // Fails on Safari
        for (var i = 0, node; (node = nodeList[i]); ++i) {
          document.write('<li>i=' + i + ' : ' + node.name);
        }
        document.write('</ul>');

        document.write('<h1>' + description + ' Method 3</h1><ul>');
        // Works on IE6, Opera9, FF2, Safari
        var limit = nodeList.length;
        if (limit !== +limit) { limit = 1/0; }
        for (var i = 0, node; i < limit && (node = nodeList[i]); ++i) {
          document.write('<li>i=' + i + ' : ' + node.name);
        }
        document.write('</ul>');
      }

      testIteration(document.forms[0].elements, 'Form Elements');
      testIteration(document.getElementsByTagName('input'), 'ByTagName');
    })();
    </script>
  </body>
</html>
Comment 1 Alexey Proskuryakov 2008-12-09 03:29:03 PST
Created attachment 25880 [details]
test case

Same test as an attachment.
Comment 2 Ahmad Saleem 2022-05-29 08:16:35 PDT
Unable to reproduce on Safari 15.4 on macOS and the output from attachment test case is consistent across Chrome Canary 104 and Firefox Nightly 102. This bug can be closed. Thanks!
Comment 3 Alexey Proskuryakov 2022-05-31 10:32:35 PDT
Thank you for checking!