Title: [149126] trunk
Revision
149126
Author
[email protected]
Date
2013-04-25 11:32:06 -0700 (Thu, 25 Apr 2013)

Log Message

HTMLOptionsCollection's namedItem and name getter should return the first item
https://bugs.webkit.org/show_bug.cgi?id=115150

Reviewed by Andreas Kling.

Source/WebCore:

Following the resolution in http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-December/038355.html,
the spefication has been updated to only return the first item when there are multiple items of the same name
in HTMLOptionsCollection; this new behavior matches that of Firefox and Opera (Presto).

Implement this new behavior to remove the custom binding code and use the fast path in namedItem and name
getter of HTMLOptionsCollection. (Obtaining all items for a given name is expensive!).

Tests: fast/dom/HTMLSelectElement/named-options.html
       fast/dom/html-collections-named-getter.html

* bindings/js/JSHTMLOptionsCollectionCustom.cpp:
(WebCore): Removed the custom bindings for name getter and namedItem.
* html/HTMLOptionsCollection.idl:

LayoutTests:

Changed the expectations of the tests.

* fast/dom/HTMLSelectElement/named-options-expected.txt:
* fast/dom/HTMLSelectElement/script-tests/named-options.js:
* fast/dom/html-collections-named-getter-expected.txt:
* fast/dom/html-collections-named-getter.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (149125 => 149126)


--- trunk/LayoutTests/ChangeLog	2013-04-25 18:31:05 UTC (rev 149125)
+++ trunk/LayoutTests/ChangeLog	2013-04-25 18:32:06 UTC (rev 149126)
@@ -1,3 +1,17 @@
+2013-04-25  Ryosuke Niwa  <[email protected]>
+
+        HTMLOptionsCollection's namedItem and name getter should return the first item
+        https://bugs.webkit.org/show_bug.cgi?id=115150
+
+        Reviewed by Andreas Kling.
+
+        Changed the expectations of the tests.
+
+        * fast/dom/HTMLSelectElement/named-options-expected.txt:
+        * fast/dom/HTMLSelectElement/script-tests/named-options.js:
+        * fast/dom/html-collections-named-getter-expected.txt:
+        * fast/dom/html-collections-named-getter.html:
+
 2013-04-25  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: ConsoleMessage should include line and column number where possible

Modified: trunk/LayoutTests/fast/dom/HTMLSelectElement/named-options-expected.txt (149125 => 149126)


--- trunk/LayoutTests/fast/dom/HTMLSelectElement/named-options-expected.txt	2013-04-25 18:31:05 UTC (rev 149125)
+++ trunk/LayoutTests/fast/dom/HTMLSelectElement/named-options-expected.txt	2013-04-25 18:32:06 UTC (rev 149126)
@@ -9,15 +9,11 @@
 Confirm that the option named 'test' is accessible from the options collection
 PASS select1.options.namedItem('test').toString() is "[object HTMLOptionElement]"
 PASS select1.options.namedItem('test').value is "Value"
-Confirm that both options named 'test' are accessible from the options collection
-PASS select2.options.namedItem('test').length is 2
-PASS select2.options.namedItem('test').toString() is "[object NodeList]"
-PASS select2.options.namedItem('test')[0].value is "Value1"
-PASS select2.options.namedItem('test')[1].value is "Value2"
-PASS select2.options.test.length is 2
-PASS select2.options.test.toString() is "[object NodeList]"
-PASS select2.options.test[0].value is "Value1"
-PASS select2.options.test[1].value is "Value2"
+Confirm that the options collection returns the first option when there are multiple options named 'test'
+PASS select2.namedItem('test').toString() is "[object HTMLOptionElement]"
+PASS select2.namedItem('test').value is "Value1"
+PASS select2.options.test.toString() is "[object HTMLOptionElement]"
+PASS select2.options.test.value is "Value1"
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/dom/HTMLSelectElement/script-tests/named-options.js (149125 => 149126)


--- trunk/LayoutTests/fast/dom/HTMLSelectElement/script-tests/named-options.js	2013-04-25 18:31:05 UTC (rev 149125)
+++ trunk/LayoutTests/fast/dom/HTMLSelectElement/script-tests/named-options.js	2013-04-25 18:32:06 UTC (rev 149126)
@@ -16,16 +16,12 @@
 shouldBeEqualToString("select1.options.namedItem('test').toString()", "[object HTMLOptionElement]");
 shouldBeEqualToString("select1.options.namedItem('test').value", "Value");
 
-debug("Confirm that both options named 'test' are accessible from the options collection");
-shouldBe("select2.options.namedItem('test').length", "2");
-shouldBeEqualToString("select2.options.namedItem('test').toString()", "[object NodeList]");
-shouldBeEqualToString("select2.options.namedItem('test')[0].value", "Value1");
-shouldBeEqualToString("select2.options.namedItem('test')[1].value", "Value2");
+debug("Confirm that the options collection returns the first option when there are multiple options named 'test'");
+shouldBeEqualToString("select2.namedItem('test').toString()", "[object HTMLOptionElement]");
+shouldBeEqualToString("select2.namedItem('test').value", "Value1");
 
-shouldBe("select2.options.test.length", "2");
-shouldBeEqualToString("select2.options.test.toString()", "[object NodeList]");
-shouldBeEqualToString("select2.options.test[0].value", "Value1");
-shouldBeEqualToString("select2.options.test[1].value", "Value2");
+shouldBeEqualToString("select2.options.test.toString()", "[object HTMLOptionElement]");
+shouldBeEqualToString("select2.options.test.value", "Value1");
 
 // Clean up after ourselves
 document.body.removeChild(select1);

Modified: trunk/LayoutTests/fast/dom/html-collections-named-getter-expected.txt (149125 => 149126)


--- trunk/LayoutTests/fast/dom/html-collections-named-getter-expected.txt	2013-04-25 18:31:05 UTC (rev 149125)
+++ trunk/LayoutTests/fast/dom/html-collections-named-getter-expected.txt	2013-04-25 18:32:06 UTC (rev 149126)
@@ -37,10 +37,7 @@
      select.appendChild(elements[0]); select.options.length is 1
 PASS select.options['foo'] is elements[0]
 PASS select.appendChild(elements[1]); select.options.length is 2
-PASS select.options['foo'].toString() is '[object NodeList]'
-PASS select.options['foo'].length is 2
-PASS select.options['foo'][0] is elements[0]
-PASS select.options['foo'][1] is elements[1]
+PASS select.options['foo'] is elements[0]
 PASS select.removeChild(elements[0]); select.options['foo'] is elements[1]
 PASS select.innerHTML = ''; select.options.length is 0
 PASS removeTestElements(); form.elements.length is 0

Modified: trunk/LayoutTests/fast/dom/html-collections-named-getter.html (149125 => 149126)


--- trunk/LayoutTests/fast/dom/html-collections-named-getter.html	2013-04-25 18:31:05 UTC (rev 149125)
+++ trunk/LayoutTests/fast/dom/html-collections-named-getter.html	2013-04-25 18:32:06 UTC (rev 149126)
@@ -65,10 +65,7 @@
     + "     select.appendChild(elements[0]); select.options.length", "1");
 shouldBe("select.options['foo']", "elements[0]");
 shouldBe("select.appendChild(elements[1]); select.options.length", "2");
-shouldBe("select.options['foo'].toString()", "'[object NodeList]'");
-shouldBe("select.options['foo'].length", "2");
-shouldBe("select.options['foo'][0]", "elements[0]");
-shouldBe("select.options['foo'][1]", "elements[1]");
+shouldBe("select.options['foo']", "elements[0]");
 shouldBe("select.removeChild(elements[0]); select.options['foo']", "elements[1]");
 shouldBe("select.innerHTML = ''; select.options.length", "0");
 shouldBe("removeTestElements(); form.elements.length", "0");

Modified: trunk/Source/WebCore/ChangeLog (149125 => 149126)


--- trunk/Source/WebCore/ChangeLog	2013-04-25 18:31:05 UTC (rev 149125)
+++ trunk/Source/WebCore/ChangeLog	2013-04-25 18:32:06 UTC (rev 149126)
@@ -1,3 +1,24 @@
+2013-04-25  Ryosuke Niwa  <[email protected]>
+
+        HTMLOptionsCollection's namedItem and name getter should return the first item
+        https://bugs.webkit.org/show_bug.cgi?id=115150
+
+        Reviewed by Andreas Kling.
+
+        Following the resolution in http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-December/038355.html,
+        the spefication has been updated to only return the first item when there are multiple items of the same name
+        in HTMLOptionsCollection; this new behavior matches that of Firefox and Opera (Presto).
+
+        Implement this new behavior to remove the custom binding code and use the fast path in namedItem and name
+        getter of HTMLOptionsCollection. (Obtaining all items for a given name is expensive!).
+
+        Tests: fast/dom/HTMLSelectElement/named-options.html
+               fast/dom/html-collections-named-getter.html
+
+        * bindings/js/JSHTMLOptionsCollectionCustom.cpp:
+        (WebCore): Removed the custom bindings for name getter and namedItem.
+        * html/HTMLOptionsCollection.idl:
+
 2013-04-25  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: ConsoleMessage should include line and column number where possible

Modified: trunk/Source/WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp (149125 => 149126)


--- trunk/Source/WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp	2013-04-25 18:31:05 UTC (rev 149125)
+++ trunk/Source/WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp	2013-04-25 18:32:06 UTC (rev 149126)
@@ -37,38 +37,6 @@
 
 namespace WebCore {
 
-static JSValue getNamedItems(ExecState* exec, JSHTMLOptionsCollection* collection, PropertyName propertyName)
-{
-    Vector<RefPtr<Node> > namedItems;
-    const AtomicString& name = propertyNameToAtomicString(propertyName);
-    collection->impl()->namedItems(name, namedItems);
-
-    if (namedItems.isEmpty())
-        return jsUndefined();
-    if (namedItems.size() == 1)
-        return toJS(exec, collection->globalObject(), namedItems[0].get());
-
-    // FIXME: HTML5 specifies that this should be a LiveNodeList.
-    return toJS(exec, collection->globalObject(), StaticNodeList::adopt(namedItems).get());
-}
-
-bool JSHTMLOptionsCollection::canGetItemsForName(ExecState*, HTMLOptionsCollection* collection, PropertyName propertyName)
-{
-    return collection->hasNamedItem(propertyNameToAtomicString(propertyName));
-}
-
-JSValue JSHTMLOptionsCollection::nameGetter(ExecState* exec, JSValue slotBase, PropertyName propertyName)
-{
-    JSHTMLOptionsCollection* thisObj = jsCast<JSHTMLOptionsCollection*>(asObject(slotBase));
-    return getNamedItems(exec, thisObj, propertyName);
-}
-
-JSValue JSHTMLOptionsCollection::namedItem(ExecState* exec)
-{
-    JSValue value = getNamedItems(exec, this, Identifier(exec, exec->argument(0).toString(exec)->value(exec)));
-    return value.isUndefined() ? jsNull() : value;
-}
-
 void JSHTMLOptionsCollection::setLength(ExecState* exec, JSValue value)
 {
     HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl());

Modified: trunk/Source/WebCore/html/HTMLOptionsCollection.idl (149125 => 149126)


--- trunk/Source/WebCore/html/HTMLOptionsCollection.idl	2013-04-25 18:31:05 UTC (rev 149125)
+++ trunk/Source/WebCore/html/HTMLOptionsCollection.idl	2013-04-25 18:32:06 UTC (rev 149126)
@@ -21,14 +21,13 @@
 [
     JSGenerateToNativeObject,
     CustomIndexedSetter,
-    NamedGetter,
     GenerateIsReachable=ImplOwnerNodeRoot,
 ] interface HTMLOptionsCollection : HTMLCollection {
     attribute long selectedIndex;
     [CustomSetter] attribute unsigned long length
         setter raises (DOMException);
 
-    [Custom] Node namedItem(in [Optional=DefaultIsUndefined] DOMString name);
+    Node namedItem(in [Optional=DefaultIsUndefined] DOMString name);
 
     [Custom] void add(in [Optional=DefaultIsUndefined] HTMLOptionElement option, 
                       in [Optional] unsigned long index)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to