- Revision
- 105870
- Author
- [email protected]
- Date
- 2012-01-25 05:04:24 -0800 (Wed, 25 Jan 2012)
Log Message
Fix incorrect behavior in HTMLCollection.prototype.item().
https://bugs.webkit.org/show_bug.cgi?id=74468
Patch by Pablo Flouret <[email protected]> on 2012-01-25
Reviewed by Adam Barth.
HTMLCollection.prototype.item("someString") was falling back to
.namedItem("someString"), which is wrong per spec. Also align the
handling of various other types of objects passed as the argument with
the spec and the rest of the browsers.
Source/WebCore:
Test: fast/dom/collection-item.html
* bindings/js/JSHTMLCollectionCustom.cpp: Remove custom implementation of item().
* bindings/v8/custom/V8HTMLCollectionCustom.cpp: Ditto.
* html/HTMLCollection.idl: Remove [Custom] in item(), it's not needed.
LayoutTests:
* fast/dom/collection-item-expected.txt: Added.
* fast/dom/collection-item.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (105869 => 105870)
--- trunk/LayoutTests/ChangeLog 2012-01-25 12:39:03 UTC (rev 105869)
+++ trunk/LayoutTests/ChangeLog 2012-01-25 13:04:24 UTC (rev 105870)
@@ -1,3 +1,18 @@
+2012-01-25 Pablo Flouret <[email protected]>
+
+ Fix incorrect behavior in HTMLCollection.prototype.item().
+ https://bugs.webkit.org/show_bug.cgi?id=74468
+
+ Reviewed by Adam Barth.
+
+ HTMLCollection.prototype.item("someString") was falling back to
+ .namedItem("someString"), which is wrong per spec. Also align the
+ handling of various other types of objects passed as the argument with
+ the spec and the rest of the browsers.
+
+ * fast/dom/collection-item-expected.txt: Added.
+ * fast/dom/collection-item.html: Added.
+
2012-01-25 Mike Lawther <[email protected]>
table border spacing test for CSS3 calc
Added: trunk/LayoutTests/fast/dom/collection-item-expected.txt (0 => 105870)
--- trunk/LayoutTests/fast/dom/collection-item-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/collection-item-expected.txt 2012-01-25 13:04:24 UTC (rev 105870)
@@ -0,0 +1,56 @@
+HTMLCollection.item() shouldn't fallback to namedItem().
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.forms.item(0) is document.getElementById('a')
+PASS document.forms.item('0') is document.getElementById('a')
+PASS document.forms.item('z') is document.getElementById('a')
+PASS document.forms.item(undefined) is document.getElementById('a')
+PASS document.forms.item(null) is document.getElementById('a')
+PASS document.forms.item({a: 'blah'}) is document.getElementById('a')
+PASS document.forms.item(false) is document.getElementById('a')
+PASS document.forms.item(true) is document.forms.item(1)
+PASS document.forms.item(4294967297) is document.forms.item(1)
+PASS document.forms.item(10000) is null
+PASS document.forms.item(-1) is null
+PASS document.forms[0].elements.item(0) is document.getElementById('x')
+PASS document.forms[0].elements.item('0') is document.getElementById('x')
+PASS document.forms[0].elements.item('z') is document.getElementById('x')
+PASS document.forms[0].elements.item(undefined) is document.getElementById('x')
+PASS document.forms[0].elements.item(null) is document.getElementById('x')
+PASS document.forms[0].elements.item({a: 'blah'}) is document.getElementById('x')
+PASS document.forms[0].elements.item(false) is document.getElementById('x')
+PASS document.forms[0].elements.item(true) is document.forms[0].elements.item(1)
+PASS document.forms[0].elements.item(4294967297) is document.forms[0].elements.item(1)
+PASS document.forms[0].elements.item(10000) is null
+PASS document.forms[0].elements.item(-1) is null
+PASS document.forms[1].elements[2].options.item(0) is document.getElementById('o')
+PASS document.forms[1].elements[2].options.item('0') is document.getElementById('o')
+PASS document.forms[1].elements[2].options.item('z') is document.getElementById('o')
+PASS document.forms[1].elements[2].options.item(undefined) is document.getElementById('o')
+PASS document.forms[1].elements[2].options.item(null) is document.getElementById('o')
+PASS document.forms[1].elements[2].options.item({a: 'blah'}) is document.getElementById('o')
+PASS document.forms[1].elements[2].options.item(false) is document.getElementById('o')
+PASS document.forms[1].elements[2].options.item(true) is document.forms[1].elements[2].options.item(1)
+PASS document.forms[1].elements[2].options.item(4294967297) is document.forms[1].elements[2].options.item(1)
+PASS document.forms[1].elements[2].options.item(10000) is null
+PASS document.forms[1].elements[2].options.item(-1) is null
+PASS document.anchors.item(0) is document.getElementById('c')
+PASS document.anchors.item('0') is document.getElementById('c')
+PASS document.anchors.item('z') is document.getElementById('c')
+PASS document.anchors.item(undefined) is document.getElementById('c')
+PASS document.anchors.item(null) is document.getElementById('c')
+PASS document.anchors.item({a: 'blah'}) is document.getElementById('c')
+PASS document.anchors.item(false) is document.getElementById('c')
+PASS document.anchors.item(true) is document.anchors.item(1)
+PASS document.anchors.item(4294967297) is document.anchors.item(1)
+PASS document.anchors.item(10000) is null
+PASS document.anchors.item(-1) is null
+PASS document.all.item('z')[0] is document.forms[0].elements.namedItem('z')
+PASS document.all.item('z')[1] is document.forms.namedItem('z')
+PASS document.all.item('z')[2] is document.forms.namedItem('z').elements.namedItem('z')
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/collection-item.html (0 => 105870)
--- trunk/LayoutTests/fast/dom/collection-item.html (rev 0)
+++ trunk/LayoutTests/fast/dom/collection-item.html 2012-01-25 13:04:24 UTC (rev 105870)
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+</head>
+<body>
+<div style="display: none">
+ <form id=a>
+ <input id=x>
+ <input name=z>
+ </form>
+ <form name=z>
+ <input id=x>
+ <input name=z>
+ <select>
+ <option id=o>a</option>
+ <option name=z>b</option>
+ <option>c</option>
+ </select>
+ </form>
+ <a href="" id=c name=cc></a>
+ <a href="" name=z></a>
+</div>
+<script>
+
+description("HTMLCollection.item() shouldn't fallback to namedItem().");
+
+function runTests(collection, expectedElement) {
+ shouldBe(collection + ".item(0)", expectedElement);
+ shouldBe(collection + ".item('0')", expectedElement);
+ shouldBe(collection + ".item('z')", expectedElement);
+ shouldBe(collection + ".item(undefined)", expectedElement);
+ shouldBe(collection + ".item(null)", expectedElement);
+ shouldBe(collection + ".item({a: 'blah'})", expectedElement);
+ shouldBe(collection + ".item(false)", expectedElement);
+ shouldBe(collection + ".item(true)", collection + ".item(1)");
+ shouldBe(collection + ".item(4294967297)", collection + ".item(1)");
+ shouldBeNull(collection + ".item(10000)");
+ shouldBeNull(collection + ".item(-1)");
+}
+
+runTests("document.forms", "document.getElementById('a')");
+runTests("document.forms[0].elements", "document.getElementById('x')");
+runTests("document.forms[1].elements[2].options", "document.getElementById('o')");
+runTests("document.anchors", "document.getElementById('c')");
+
+// document.all is an ugly mutant (i.e. not an HTMLCollection).
+
+if ("all" in document) {
+ shouldBe("document.all.item('z')[0]", "document.forms[0].elements.namedItem('z')");
+ shouldBe("document.all.item('z')[1]", "document.forms.namedItem('z')");
+ shouldBe("document.all.item('z')[2]", "document.forms.namedItem('z').elements.namedItem('z')");
+}
+
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (105869 => 105870)
--- trunk/Source/WebCore/ChangeLog 2012-01-25 12:39:03 UTC (rev 105869)
+++ trunk/Source/WebCore/ChangeLog 2012-01-25 13:04:24 UTC (rev 105870)
@@ -1,3 +1,21 @@
+2012-01-25 Pablo Flouret <[email protected]>
+
+ Fix incorrect behavior in HTMLCollection.prototype.item().
+ https://bugs.webkit.org/show_bug.cgi?id=74468
+
+ Reviewed by Adam Barth.
+
+ HTMLCollection.prototype.item("someString") was falling back to
+ .namedItem("someString"), which is wrong per spec. Also align the
+ handling of various other types of objects passed as the argument with
+ the spec and the rest of the browsers.
+
+ Test: fast/dom/collection-item.html
+
+ * bindings/js/JSHTMLCollectionCustom.cpp: Remove custom implementation of item().
+ * bindings/v8/custom/V8HTMLCollectionCustom.cpp: Ditto.
+ * html/HTMLCollection.idl: Remove [Custom] in item(), it's not needed.
+
2012-01-25 Sheriff Bot <[email protected]>
Unreviewed, rolling out r105858.
Modified: trunk/Source/WebCore/bindings/js/JSHTMLCollectionCustom.cpp (105869 => 105870)
--- trunk/Source/WebCore/bindings/js/JSHTMLCollectionCustom.cpp 2012-01-25 12:39:03 UTC (rev 105869)
+++ trunk/Source/WebCore/bindings/js/JSHTMLCollectionCustom.cpp 2012-01-25 13:04:24 UTC (rev 105870)
@@ -69,15 +69,6 @@
return getNamedItems(exec, thisObj, propertyName);
}
-JSValue JSHTMLCollection::item(ExecState* exec)
-{
- bool ok;
- uint32_t index = Identifier::toUInt32(exec->argument(0).toString(exec)->value(exec), ok);
- if (ok)
- return toJS(exec, globalObject(), impl()->item(index));
- return getNamedItems(exec, this, Identifier(exec, exec->argument(0).toString(exec)->value(exec)));
-}
-
JSValue JSHTMLCollection::namedItem(ExecState* exec)
{
return getNamedItems(exec, this, Identifier(exec, exec->argument(0).toString(exec)->value(exec)));
Modified: trunk/Source/WebCore/bindings/v8/custom/V8HTMLCollectionCustom.cpp (105869 => 105870)
--- trunk/Source/WebCore/bindings/v8/custom/V8HTMLCollectionCustom.cpp 2012-01-25 12:39:03 UTC (rev 105869)
+++ trunk/Source/WebCore/bindings/v8/custom/V8HTMLCollectionCustom.cpp 2012-01-25 13:04:24 UTC (rev 105870)
@@ -55,25 +55,6 @@
return toV8(V8NamedNodesCollection::create(namedItems));
}
-static v8::Handle<v8::Value> getItem(HTMLCollection* collection, v8::Handle<v8::Value> argument)
-{
- v8::Local<v8::Uint32> index = argument->ToArrayIndex();
- if (index.IsEmpty()) {
- v8::Local<v8::String> asString = argument->ToString();
- if (asString.IsEmpty())
- return v8::Handle<v8::Value>();
- v8::Handle<v8::Value> result = getNamedItems(collection, toWebCoreString(asString));
-
- if (result.IsEmpty())
- return v8::Undefined();
-
- return result;
- }
-
- RefPtr<Node> result = collection->item(index->Uint32Value());
- return toV8(result.release());
-}
-
v8::Handle<v8::Value> V8HTMLCollection::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
INC_STATS("DOM.HTMLCollection.NamedPropertyGetter");
@@ -87,13 +68,6 @@
return getNamedItems(imp, v8StringToAtomicWebCoreString(name));
}
-v8::Handle<v8::Value> V8HTMLCollection::itemCallback(const v8::Arguments& args)
-{
- INC_STATS("DOM.HTMLCollection.item()");
- HTMLCollection* imp = V8HTMLCollection::toNative(args.Holder());
- return getItem(imp, args[0]);
-}
-
v8::Handle<v8::Value> V8HTMLCollection::namedItemCallback(const v8::Arguments& args)
{
INC_STATS("DOM.HTMLCollection.namedItem()");
Modified: trunk/Source/WebCore/html/HTMLCollection.idl (105869 => 105870)
--- trunk/Source/WebCore/html/HTMLCollection.idl 2012-01-25 12:39:03 UTC (rev 105869)
+++ trunk/Source/WebCore/html/HTMLCollection.idl 2012-01-25 13:04:24 UTC (rev 105870)
@@ -28,7 +28,7 @@
Polymorphic
] HTMLCollection {
readonly attribute unsigned long length;
- [Custom] Node item(in [Optional=CallWithDefaultValue] unsigned long index);
+ Node item(in [Optional=CallWithDefaultValue] unsigned long index);
[Custom] Node namedItem(in [Optional=CallWithDefaultValue] DOMString name);
#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C