5 <script src=
"../../resources/js-test.js"></script>
8 <div style=
"display: none">
17 <option id=o
>a
</option>
18 <option name=z
>b
</option>
22 <a href=
"http://c.example.org" id=c name=cc
></a>
23 <a href=
"http://d.example.org" name=z
></a>
27 description("HTMLCollection.item() shouldn't fallback to namedItem().");
29 function runTests(collection
, expectedElement
) {
30 shouldBe(collection
+ ".item(0)", expectedElement
);
31 shouldBe(collection
+ ".item('0')", expectedElement
);
32 shouldBe(collection
+ ".item('z')", expectedElement
);
33 shouldBe(collection
+ ".item(undefined)", expectedElement
);
34 shouldBe(collection
+ ".item(null)", expectedElement
);
35 shouldBe(collection
+ ".item({a: 'blah'})", expectedElement
);
36 shouldBe(collection
+ ".item(false)", expectedElement
);
37 shouldBe(collection
+ ".item(true)", collection
+ ".item(1)");
38 shouldBe(collection
+ ".item(4294967297)", collection
+ ".item(1)");
39 shouldBeNull(collection
+ ".item(10000)");
40 shouldBeNull(collection
+ ".item(-1)");
43 runTests("document.forms", "document.getElementById('a')");
44 runTests("document.forms[0].elements", "document.getElementById('x')");
45 runTests("document.forms[1].elements[2].options", "document.getElementById('o')");
46 runTests("document.anchors", "document.getElementById('c')");
48 // document.all is an ugly mutant (i.e. not an HTMLCollection).
50 if ("all" in document
) {
51 shouldBe("document.all.item('z')[0]", "document.forms[0].elements.namedItem('z')");
52 shouldBe("document.all.item('z')[1]", "document.forms.namedItem('z')");
53 shouldBe("document.all.item('z')[2]", "document.forms.namedItem('z').elements.namedItem('z')");