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>
Created attachment 25880 [details] test case Same test as an attachment.
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!
Thank you for checking!