HTMLSelectElement.item() does not behave according to specification

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

Reviewed by Darin Adler.

Source/WebCore:

Make HTMLSelectElement.item() behave according to specification:
http://www.w3.org/TR/html51/forms.html#dom-select-item
http://dom.spec.whatwg.org/#dom-htmlcollection-item

Namely, we no longer throw if the offset argument is negative. Also,
the argument is now mandatory.

IE10, Firefox and Blink do not throw when HTMLSelectElement.item() is
called with a negative value (as per the specification).

The argument is mandatory in Firefox and Blink, but optional in IE10
(it returns null when called without argument). This looks like a bug
in IE because other item() getters' argument is usually mandatory in IE
(e.g. NodeList.item()).

Test: fast/dom/HTMLSelectElement/select-element-item-argument.html

* html/HTMLSelectElement.idl:

LayoutTests:

Add a new layout test to check that the HTMLSelectElement.item() indexed getter's
parameter is correctly validated.
Also update fast/dom/non-numeric-values-numeric-parameters.html now that the
argument is mandatory.

* fast/dom/HTMLSelectElement/select-element-item-argument-expected.txt: Added.
* fast/dom/HTMLSelectElement/select-element-item-argument.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@154005 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 205dab32
2013-08-13 Christophe Dumez <ch.dumez@sisa.samsung.com>
HTMLSelectElement.item() does not behave according to specification
https://bugs.webkit.org/show_bug.cgi?id=119738
Reviewed by Darin Adler.
Add a new layout test to check that the HTMLSelectElement.item() indexed getter's
parameter is correctly validated.
Also update fast/dom/non-numeric-values-numeric-parameters.html now that the
argument is mandatory.
* fast/dom/HTMLSelectElement/select-element-item-argument-expected.txt: Added.
* fast/dom/HTMLSelectElement/select-element-item-argument.html: Added.
* fast/dom/non-numeric-values-numeric-parameters-expected.txt:
* fast/dom/script-tests/non-numeric-values-numeric-parameters.js:
2013-08-13 Christophe Dumez <ch.dumez@sisa.samsung.com>
On request error, always fire events on the XMLHttpRequestUpload before the XMLHttpRequest
Tests that the HTMLSelectElement.item() argument is correctly validated.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS select.__proto__ is HTMLSelectElement.prototype
PASS select.item(0).value is "a"
PASS select.item(1).value is "b"
PASS select.item(2).value is "c"
PASS select.item(3).value is "d"
PASS select.item(4) is null
PASS select.item(-1) is null
PASS select.item(-4294967294).value is "c"
PASS select.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/html51/forms.html#dom-select-item">
<script src="../../js/resources/js-test-pre.js"></script>
</head>
<body>
<select id="target">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
</select>
<script>
description("Tests that the HTMLSelectElement.item() argument is correctly validated.");
var select = document.getElementById('target');
shouldBe("select.__proto__", "HTMLSelectElement.prototype");
// getter Node item(unsigned long index);
shouldBeEqualToString("select.item(0).value", "a");
shouldBeEqualToString("select.item(1).value", "b");
shouldBeEqualToString("select.item(2).value", "c");
shouldBeEqualToString("select.item(3).value", "d");
shouldBeNull("select.item(4)");
shouldBeNull("select.item(-1)"); // Offset is too large (after wrapping)
shouldBeEqualToString("select.item(-4294967294).value", "c"); // Wraps to 2, which is a valid offset.
shouldThrow("select.item()", "'TypeError: Not enough arguments'");
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
</html>
......@@ -31,7 +31,7 @@ PASS nonNumericPolicy('document.createElement("input").setSelectionRange(0, x)')
PASS nonNumericPolicy('createHTMLOptionsCollection().add(document.createElement("option"), x)') is 'any type allowed'
PASS nonNumericPolicy('createHTMLOptionsCollection().remove(x)') is 'any type allowed'
PASS nonNumericPolicy('createHTMLSelectElement().remove(x)') is 'any type allowed'
PASS nonNumericPolicy('createHTMLSelectElement().item(x)') is 'any type allowed'
PASS nonNumericPolicy('createHTMLSelectElement().item(x)') is 'any type allowed (but not omitted)'
PASS nonNumericPolicy('createHTMLTableElement().insertRow(x)') is 'any type allowed'
PASS nonNumericPolicy('createHTMLTableElement().deleteRow(x)') is 'any type allowed'
PASS nonNumericPolicy('createHTMLTableRowElement().insertCell(x)') is 'any type allowed'
......
......@@ -250,7 +250,7 @@ shouldBe("nonNumericPolicy('createHTMLOptionsCollection().remove(x)')", "'any ty
// HTMLSelectElement
shouldBe("nonNumericPolicy('createHTMLSelectElement().remove(x)')", "'any type allowed'");
shouldBe("nonNumericPolicy('createHTMLSelectElement().item(x)')", "'any type allowed'");
shouldBe("nonNumericPolicy('createHTMLSelectElement().item(x)')", "'any type allowed (but not omitted)'");
// HTMLTableElement
......
2013-08-13 Christophe Dumez <ch.dumez@sisa.samsung.com>
HTMLSelectElement.item() does not behave according to specification
https://bugs.webkit.org/show_bug.cgi?id=119738
Reviewed by Darin Adler.
Make HTMLSelectElement.item() behave according to specification:
http://www.w3.org/TR/html51/forms.html#dom-select-item
http://dom.spec.whatwg.org/#dom-htmlcollection-item
Namely, we no longer throw if the offset argument is negative. Also,
the argument is now mandatory.
IE10, Firefox and Blink do not throw when HTMLSelectElement.item() is
called with a negative value (as per the specification).
The argument is mandatory in Firefox and Blink, but optional in IE10
(it returns null when called without argument). This looks like a bug
in IE because other item() getters' argument is usually mandatory in IE
(e.g. NodeList.item()).
Test: fast/dom/HTMLSelectElement/select-element-item-argument.html
* html/HTMLSelectElement.idl:
2013-08-13 Christophe Dumez <ch.dumez@sisa.samsung.com>
On request error, always fire events on the XMLHttpRequestUpload before the XMLHttpRequest
......@@ -39,7 +39,7 @@
#else
[SetterRaisesException] attribute unsigned long length;
#endif
getter Node item([IsIndex,Default=Undefined] optional unsigned long index);
getter Node item(unsigned long index);
Node namedItem([Default=Undefined] optional DOMString name);
[ObjCLegacyUnnamedParameters, RaisesException] void add([Default=Undefined] optional HTMLElement element,
[Default=Undefined] optional HTMLElement before);
......
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