HTMLFormElement's named property getter does not return a RadioNodelist
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Mar 2016 07:44:00 +0000 (07:44 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Mar 2016 07:44:00 +0000 (07:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=154949

Reviewed by Ryosuke Niwa.

Source/WebCore:

HTMLFormElement's named property getter should return a RadioNodeList
when there are several matches:
https://html.spec.whatwg.org/multipage/forms.html#the-form-element

Previously, WebKit returned a generic NodeList. As a result, users
cannot create a white-and-gold hat in the MAKE A HAT GREAT AGAIN
section at:
https://www.washingtonpost.com/news/the-fix/wp/2015/10/06/hey-lets-all-make-our-own-donald-trump-hats/

Chrome and Firefox already match the specification. Edge will soon.

Test: fast/dom/HTMLFormElement/named-property-getter-radionodelist.html

* bindings/js/JSHTMLFormElementCustom.cpp:
(WebCore::JSHTMLFormElement::nameGetter):

LayoutTests:

Add layout test to confirm that HTMLFormElement's named property getter
does indeed return a RadioNodeList when there are several matches.

* fast/dom/HTMLFormElement/named-property-getter-radionodelist-expected.txt: Added.
* fast/dom/HTMLFormElement/named-property-getter-radionodelist.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197497 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/HTMLFormElement/named-property-getter-radionodelist-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLFormElement/named-property-getter-radionodelist.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSHTMLFormElementCustom.cpp

index 64a9962..b5fd387 100644 (file)
@@ -1,5 +1,18 @@
 2016-03-02  Chris Dumez  <cdumez@apple.com>
 
+        HTMLFormElement's named property getter does not return a RadioNodelist
+        https://bugs.webkit.org/show_bug.cgi?id=154949
+
+        Reviewed by Ryosuke Niwa.
+
+        Add layout test to confirm that HTMLFormElement's named property getter
+        does indeed return a RadioNodeList when there are several matches.
+
+        * fast/dom/HTMLFormElement/named-property-getter-radionodelist-expected.txt: Added.
+        * fast/dom/HTMLFormElement/named-property-getter-radionodelist.html: Added.
+
+2016-03-02  Chris Dumez  <cdumez@apple.com>
+
         Drop [TreatNullAs=LegacyNullString] from HTMLBaseElement.href
         https://bugs.webkit.org/show_bug.cgi?id=154952
 
diff --git a/LayoutTests/fast/dom/HTMLFormElement/named-property-getter-radionodelist-expected.txt b/LayoutTests/fast/dom/HTMLFormElement/named-property-getter-radionodelist-expected.txt
new file mode 100644 (file)
index 0000000..4b3a200
--- /dev/null
@@ -0,0 +1,15 @@
+Tests that HTMLFormElement's named property getter returns a RadioNodeList if there are several matching elements.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS radioNodeList.__proto__ is RadioNodeList.prototype
+PASS radioNodeList.length is 3
+PASS radioNodeList[0] is radio1
+PASS radioNodeList[1] is radio2
+PASS radioNodeList[2] is radio3
+PASS radioNodeList.value is "value2"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+    
diff --git a/LayoutTests/fast/dom/HTMLFormElement/named-property-getter-radionodelist.html b/LayoutTests/fast/dom/HTMLFormElement/named-property-getter-radionodelist.html
new file mode 100644 (file)
index 0000000..ff7c8de
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<form name="f">
+ <input type="radio" id="radio1" name="r" value="value1" />
+ <input type="radio" id="radio2" name="r" value="value2" checked />
+ <input type="radio" id="radio3" name="r" value="value3" />
+</form>
+<script>
+description("Tests that HTMLFormElement's named property getter returns a RadioNodeList if there are several matching elements.");
+
+var radio1 = document.getElementById("radio1");
+var radio2 = document.getElementById("radio2");
+var radio3 = document.getElementById("radio3");
+
+var radioNodeList = document.f.r;
+shouldBe("radioNodeList.__proto__", "RadioNodeList.prototype");
+shouldBe("radioNodeList.length", "3");
+shouldBe("radioNodeList[0]", "radio1");
+shouldBe("radioNodeList[1]", "radio2");
+shouldBe("radioNodeList[2]", "radio3");
+shouldBeEqualToString("radioNodeList.value", "value2");
+</script>
+<script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
index ebae37e..ece40f1 100644 (file)
@@ -1,5 +1,28 @@
 2016-03-02  Chris Dumez  <cdumez@apple.com>
 
+        HTMLFormElement's named property getter does not return a RadioNodelist
+        https://bugs.webkit.org/show_bug.cgi?id=154949
+
+        Reviewed by Ryosuke Niwa.
+
+        HTMLFormElement's named property getter should return a RadioNodeList
+        when there are several matches:
+        https://html.spec.whatwg.org/multipage/forms.html#the-form-element
+
+        Previously, WebKit returned a generic NodeList. As a result, users
+        cannot create a white-and-gold hat in the MAKE A HAT GREAT AGAIN
+        section at:
+        https://www.washingtonpost.com/news/the-fix/wp/2015/10/06/hey-lets-all-make-our-own-donald-trump-hats/
+
+        Chrome and Firefox already match the specification. Edge will soon.
+
+        Test: fast/dom/HTMLFormElement/named-property-getter-radionodelist.html
+
+        * bindings/js/JSHTMLFormElementCustom.cpp:
+        (WebCore::JSHTMLFormElement::nameGetter):
+
+2016-03-02  Chris Dumez  <cdumez@apple.com>
+
         Drop [TreatNullAs=LegacyNullString] from HTMLBaseElement.href
         https://bugs.webkit.org/show_bug.cgi?id=154952
 
index 3aed705..cb2119b 100644 (file)
@@ -30,8 +30,7 @@
 #include "HTMLCollection.h"
 #include "HTMLFormElement.h"
 #include "JSDOMWindowCustom.h"
-#include "JSNodeList.h"
-#include "StaticNodeList.h"
+#include "JSRadioNodeList.h"
 
 using namespace JSC;
 
@@ -48,8 +47,7 @@ bool JSHTMLFormElement::nameGetter(ExecState* exec, PropertyName propertyName, J
         return true;
     }
 
-    // FIXME: HTML5 specifies that this should be a RadioNodeList.
-    value = toJS(exec, globalObject(), StaticElementList::adopt(namedItems).get());
+    value = toJS(exec, globalObject(), wrapped().radioNodeList(propertyNameToAtomicString(propertyName)).get());
     return true;
 }