NodeList.item() does not behave according to specification

https://bugs.webkit.org/show_bug.cgi?id=119722

Reviewed by Darin Adler.

Source/WebCore:

Make NodeList.item() indexed getter behave according to specification:
http://dom.spec.whatwg.org/#nodelist

Namely, we no longer throw if the index is negative (meaning the
[IsIndex] extended attribute is dropped) and the argument is now
mandatory.

This behavior is consistent with both IE10 and Firefox and since
recently Blink.

Test: fast/dom/nodelist-item-parameter.html

* dom/NodeList.idl:

LayoutTests:

Add a layout test to check that the NodeList.item() indexed getter's
argument is properly validated. Also, update the following test case now
that the argument is mandatory:
fast/dom/non-numeric-values-numeric-parameters.html

* fast/dom/nodelist-item-parameter-expected.txt: Added.
* fast/dom/nodelist-item-parameter.html: Added.
* fast/dom/non-numeric-values-numeric-parameters-expected.txt:
* fast/dom/script-tests/non-numeric-values-numeric-parameters.js:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154012 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 04bbde04
2013-08-13 Christophe Dumez <ch.dumez@sisa.samsung.com>
NodeList.item() does not behave according to specification
https://bugs.webkit.org/show_bug.cgi?id=119722
Reviewed by Darin Adler.
Add a layout test to check that the NodeList.item() indexed getter's
argument is properly validated. Also, update the following test case now
that the argument is mandatory:
fast/dom/non-numeric-values-numeric-parameters.html
* fast/dom/nodelist-item-parameter-expected.txt: Added.
* fast/dom/nodelist-item-parameter.html: Added.
* fast/dom/non-numeric-values-numeric-parameters-expected.txt:
* fast/dom/script-tests/non-numeric-values-numeric-parameters.js:
2013-08-13 Allan Sandfeld Jensen <allan.jensen@digia.com>
REGRESSION(SUBPIXEL_LAYOUT) Composited layers can cause one pixel shifts
Tests that the NodeList.item() argument is correctly validated.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS nodeList.__proto__ is NodeList.prototype
PASS nodeList.item(0).id is "a"
PASS nodeList.item(1).id is "b"
PASS nodeList.item(2) is null
PASS nodeList.item(-1) is null
PASS nodeList.item(-4294967295).id is "b"
PASS nodeList.item() threw exception TypeError: Not enough arguments.
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<link rel="help" href="http://www.w3.org/TR/2012/WD-dom-20121206/#dom-nodelist-item">
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<span id="target">
<div id="a"></div>
<div id="b"></div>
</span>
<script>
description("Tests that the NodeList.item() argument is correctly validated.");
var nodeList = document.getElementById("target").querySelectorAll('div');
shouldBe("nodeList.__proto__", "NodeList.prototype");
shouldBeEqualToString("nodeList.item(0).id", "a");
shouldBeEqualToString("nodeList.item(1).id", "b");
shouldBeNull("nodeList.item(2)");
shouldBeNull("nodeList.item(-1)");
shouldBeEqualToString("nodeList.item(-4294967295).id", "b"); // Wraps to 1.
shouldThrow("nodeList.item()", "'TypeError: Not enough arguments'");
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
......@@ -50,7 +50,7 @@ PASS nonNumericPolicy('document.createEvent("MouseEvent").initMouseEvent("a", fa
PASS nonNumericPolicy('document.createEvent("MouseEvent").initMouseEvent("a", false, false, null, 0, 0, 0, 0, 0, false, false, false, false, x, null)') is 'any type allowed'
PASS nonNumericPolicy('document.body.attributes.item(x)') is 'any type allowed'
PASS nonNumericPolicy('document.createNodeIterator(document, x, null, false)') is 'any type allowed'
PASS nonNumericPolicy('document.getElementsByTagName("div").item(x)') is 'any type allowed'
PASS nonNumericPolicy('document.getElementsByTagName("div").item(x)') is 'any type allowed (but not omitted)'
PASS nonNumericPolicy('document.createRange().setStart(document, x)') is 'any type allowed'
PASS nonNumericPolicy('document.createRange().setEnd(document, x)') is 'any type allowed'
PASS nonNumericPolicy('document.createRange().comparePoint(document, x)') is 'any type allowed'
......
......@@ -299,7 +299,7 @@ shouldBe("nonNumericPolicy('document.createNodeIterator(document, x, null, false
// NodeList
shouldBe("nonNumericPolicy('document.getElementsByTagName(\"div\").item(x)')", "'any type allowed'");
shouldBe("nonNumericPolicy('document.getElementsByTagName(\"div\").item(x)')", "'any type allowed (but not omitted)'");
// Range
......
2013-08-13 Christophe Dumez <ch.dumez@sisa.samsung.com>
NodeList.item() does not behave according to specification
https://bugs.webkit.org/show_bug.cgi?id=119722
Reviewed by Darin Adler.
Make NodeList.item() indexed getter behave according to specification:
http://dom.spec.whatwg.org/#nodelist
Namely, we no longer throw if the index is negative (meaning the
[IsIndex] extended attribute is dropped) and the argument is now
mandatory.
This behavior is consistent with both IE10 and Firefox and since
recently Blink.
Test: fast/dom/nodelist-item-parameter.html
* dom/NodeList.idl:
2013-08-13 Anders Carlsson <andersca@apple.com>
Fix build.
......@@ -23,7 +23,7 @@
SkipVTableValidation
] interface NodeList {
getter Node item([IsIndex,Default=Undefined] optional unsigned long index);
getter Node item(unsigned long index);
getter (Node or unsigned long) (DOMString name);
readonly attribute unsigned long length;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment