Title: [203852] trunk
Revision
203852
Author
cdu...@apple.com
Date
2016-07-28 18:19:41 -0700 (Thu, 28 Jul 2016)

Log Message

Add support for Element.getAttributeNames()
https://bugs.webkit.org/show_bug.cgi?id=160327

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Rebaseline several W3C tests now that more checks are passing.

* web-platform-tests/dom/interfaces-expected.txt:
* web-platform-tests/dom/nodes/attributes-expected.txt:
* web-platform-tests/html/dom/interfaces-expected.txt:

Source/WebCore:

Add support for Element.getAttributeNames():
- https://dom.spec.whatwg.org/#dom-element-getattributenames

Firefox already supports this, Chrome 52 does not yet.

Test: fast/dom/Element/getAttributeNames.html

* bindings/js/JSDOMBinding.h:
(WebCore::JSValueTraits<AtomicString>::arrayJSValue):
* dom/Element.cpp:
(WebCore::Element::getAttributeNames):
* dom/Element.h:
* dom/Element.idl:

LayoutTests:

Add layout test coverage. I have verified that this test is passing in
Firefox 47.

* fast/dom/Element/getAttributeNames-expected.txt: Added.
* fast/dom/Element/getAttributeNames.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (203851 => 203852)


--- trunk/LayoutTests/ChangeLog	2016-07-29 00:30:32 UTC (rev 203851)
+++ trunk/LayoutTests/ChangeLog	2016-07-29 01:19:41 UTC (rev 203852)
@@ -1,5 +1,18 @@
 2016-07-28  Chris Dumez  <cdu...@apple.com>
 
+        Add support for Element.getAttributeNames()
+        https://bugs.webkit.org/show_bug.cgi?id=160327
+
+        Reviewed by Alex Christensen.
+
+        Add layout test coverage. I have verified that this test is passing in
+        Firefox 47.
+
+        * fast/dom/Element/getAttributeNames-expected.txt: Added.
+        * fast/dom/Element/getAttributeNames.html: Added.
+
+2016-07-28  Chris Dumez  <cdu...@apple.com>
+
         window.open.length should be 0
         https://bugs.webkit.org/show_bug.cgi?id=160323
 

Added: trunk/LayoutTests/fast/dom/Element/getAttributeNames-expected.txt (0 => 203852)


--- trunk/LayoutTests/fast/dom/Element/getAttributeNames-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/getAttributeNames-expected.txt	2016-07-29 01:19:41 UTC (rev 203852)
@@ -0,0 +1,30 @@
+Test the Element.getAttributeNames() API
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS element.getAttributeNames().length is 0
+PASS element.getAttributeNames().length is 1
+PASS element.getAttributeNames()[0] is element.attributes[0].name
+PASS element.getAttributeNames()[0] is "foo"
+PASS element.getAttributeNames().length is 0
+PASS element.getAttributeNames().length is 4
+PASS element.getAttributeNames()[0] is "foo"
+PASS element.getAttributeNames()[1] is "FOO"
+PASS element.getAttributeNames()[2] is "foo"
+PASS element.getAttributeNames()[3] is "dummy:foo"
+PASS element.getAttributeNames()[0] is element.attributes[0].name
+PASS element.getAttributeNames()[1] is element.attributes[1].name
+PASS element.getAttributeNames()[2] is element.attributes[2].name
+PASS element.getAttributeNames()[3] is element.attributes[3].name
+PASS element.getAttributeNames().length is 3
+PASS element.getAttributeNames()[0] is "foo"
+PASS element.getAttributeNames()[1] is "foo"
+PASS element.getAttributeNames()[2] is "dummy:foo"
+PASS element.getAttributeNames()[0] is element.attributes[0].name
+PASS element.getAttributeNames()[1] is element.attributes[1].name
+PASS element.getAttributeNames()[2] is element.attributes[2].name
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/Element/getAttributeNames.html (0 => 203852)


--- trunk/LayoutTests/fast/dom/Element/getAttributeNames.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/getAttributeNames.html	2016-07-29 01:19:41 UTC (rev 203852)
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+description("Test the Element.getAttributeNames() API");
+
+var element = document.createElement("div");
+shouldBe("element.getAttributeNames().length", "0");
+
+element.setAttribute("foo", "bar");
+shouldBe("element.getAttributeNames().length", "1");
+shouldBe("element.getAttributeNames()[0]", "element.attributes[0].name");
+shouldBeEqualToString("element.getAttributeNames()[0]", "foo");
+
+element.removeAttribute("foo");
+shouldBe("element.getAttributeNames().length", "0");
+
+element.setAttribute("foo", "bar");
+element.setAttributeNS("", "FOO", "bar");
+element.setAttributeNS("dummy1", "foo", "bar");
+element.setAttributeNS("dummy2", "dummy:foo", "bar");
+shouldBe("element.getAttributeNames().length", "4");
+shouldBeEqualToString("element.getAttributeNames()[0]", "foo");
+shouldBeEqualToString("element.getAttributeNames()[1]", "FOO");
+shouldBeEqualToString("element.getAttributeNames()[2]", "foo");
+shouldBeEqualToString("element.getAttributeNames()[3]", "dummy:foo");
+shouldBe("element.getAttributeNames()[0]", "element.attributes[0].name");
+shouldBe("element.getAttributeNames()[1]", "element.attributes[1].name");
+shouldBe("element.getAttributeNames()[2]", "element.attributes[2].name");
+shouldBe("element.getAttributeNames()[3]", "element.attributes[3].name");
+
+element.removeAttributeNS("", "FOO");
+shouldBe("element.getAttributeNames().length", "3");
+shouldBeEqualToString("element.getAttributeNames()[0]", "foo");
+shouldBeEqualToString("element.getAttributeNames()[1]", "foo");
+shouldBeEqualToString("element.getAttributeNames()[2]", "dummy:foo");
+shouldBe("element.getAttributeNames()[0]", "element.attributes[0].name");
+shouldBe("element.getAttributeNames()[1]", "element.attributes[1].name");
+shouldBe("element.getAttributeNames()[2]", "element.attributes[2].name");
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (203851 => 203852)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-07-29 00:30:32 UTC (rev 203851)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-07-29 01:19:41 UTC (rev 203852)
@@ -1,5 +1,18 @@
 2016-07-28  Chris Dumez  <cdu...@apple.com>
 
+        Add support for Element.getAttributeNames()
+        https://bugs.webkit.org/show_bug.cgi?id=160327
+
+        Reviewed by Alex Christensen.
+
+        Rebaseline several W3C tests now that more checks are passing.
+
+        * web-platform-tests/dom/interfaces-expected.txt:
+        * web-platform-tests/dom/nodes/attributes-expected.txt:
+        * web-platform-tests/html/dom/interfaces-expected.txt:
+
+2016-07-28  Chris Dumez  <cdu...@apple.com>
+
         window.open.length should be 0
         https://bugs.webkit.org/show_bug.cgi?id=160323
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/interfaces-expected.txt (203851 => 203852)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/interfaces-expected.txt	2016-07-29 00:30:32 UTC (rev 203851)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/interfaces-expected.txt	2016-07-29 01:19:41 UTC (rev 203852)
@@ -742,7 +742,7 @@
 PASS Element interface: attribute slot 
 PASS Element interface: operation hasAttributes() 
 PASS Element interface: attribute attributes 
-FAIL Element interface: operation getAttributeNames() assert_own_property: interface prototype object missing non-static operation expected property "getAttributeNames" missing
+PASS Element interface: operation getAttributeNames() 
 PASS Element interface: operation getAttribute(DOMString) 
 PASS Element interface: operation getAttributeNS(DOMString,DOMString) 
 PASS Element interface: operation setAttribute(DOMString,DOMString) 
@@ -793,7 +793,7 @@
 PASS Element interface: element must inherit property "slot" with the proper type (7) 
 PASS Element interface: element must inherit property "hasAttributes" with the proper type (8) 
 PASS Element interface: element must inherit property "attributes" with the proper type (9) 
-FAIL Element interface: element must inherit property "getAttributeNames" with the proper type (10) assert_inherits: property "getAttributeNames" not found in prototype chain
+PASS Element interface: element must inherit property "getAttributeNames" with the proper type (10) 
 PASS Element interface: element must inherit property "getAttribute" with the proper type (11) 
 PASS Element interface: calling getAttribute(DOMString) on element with too few arguments must throw TypeError 
 PASS Element interface: element must inherit property "getAttributeNS" with the proper type (12) 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/attributes-expected.txt (203851 => 203852)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/attributes-expected.txt	2016-07-29 00:30:32 UTC (rev 203851)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/attributes-expected.txt	2016-07-29 01:19:41 UTC (rev 203852)
@@ -48,7 +48,7 @@
 PASS setAttributeNode, if it fires mutation events, should fire one with the new node when resetting an existing attribute 
 PASS setAttributeNode, if it fires mutation events, should fire one with the new node when resetting an existing attribute (outer shell) 
 PASS setAttributeNode called with an Attr that has the same name as an existing one should not change attribute order 
-FAIL getAttributeNames tests el.getAttributeNames is not a function. (In 'el.getAttributeNames()', 'el.getAttributeNames' is undefined)
+PASS getAttributeNames tests 
 FAIL Own property correctness with basic attributes assert_array_equals: lengths differ, expected 4 got 2
 FAIL Own property correctness with non-namespaced attribute before same-name namespaced one assert_array_equals: lengths differ, expected 5 got 3
 FAIL Own property correctness with namespaced attribute before same-name non-namespaced one assert_array_equals: lengths differ, expected 5 got 3

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt (203851 => 203852)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt	2016-07-29 00:30:32 UTC (rev 203851)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt	2016-07-29 01:19:41 UTC (rev 203852)
@@ -1149,7 +1149,7 @@
 PASS Element interface: document.createElement("noscript") must inherit property "classList" with the proper type (6) 
 PASS Element interface: document.createElement("noscript") must inherit property "hasAttributes" with the proper type (7) 
 PASS Element interface: document.createElement("noscript") must inherit property "attributes" with the proper type (8) 
-FAIL Element interface: document.createElement("noscript") must inherit property "getAttributeNames" with the proper type (9) assert_inherits: property "getAttributeNames" not found in prototype chain
+PASS Element interface: document.createElement("noscript") must inherit property "getAttributeNames" with the proper type (9) 
 PASS Element interface: document.createElement("noscript") must inherit property "getAttribute" with the proper type (10) 
 PASS Element interface: calling getAttribute(DOMString) on document.createElement("noscript") with too few arguments must throw TypeError 
 PASS Element interface: document.createElement("noscript") must inherit property "getAttributeNS" with the proper type (11) 

Modified: trunk/Source/WebCore/ChangeLog (203851 => 203852)


--- trunk/Source/WebCore/ChangeLog	2016-07-29 00:30:32 UTC (rev 203851)
+++ trunk/Source/WebCore/ChangeLog	2016-07-29 01:19:41 UTC (rev 203852)
@@ -1,5 +1,26 @@
 2016-07-28  Chris Dumez  <cdu...@apple.com>
 
+        Add support for Element.getAttributeNames()
+        https://bugs.webkit.org/show_bug.cgi?id=160327
+
+        Reviewed by Alex Christensen.
+
+        Add support for Element.getAttributeNames():
+        - https://dom.spec.whatwg.org/#dom-element-getattributenames
+
+        Firefox already supports this, Chrome 52 does not yet.
+
+        Test: fast/dom/Element/getAttributeNames.html
+
+        * bindings/js/JSDOMBinding.h:
+        (WebCore::JSValueTraits<AtomicString>::arrayJSValue):
+        * dom/Element.cpp:
+        (WebCore::Element::getAttributeNames):
+        * dom/Element.h:
+        * dom/Element.idl:
+
+2016-07-28  Chris Dumez  <cdu...@apple.com>
+
         window.open.length should be 0
         https://bugs.webkit.org/show_bug.cgi?id=160323
 

Modified: trunk/Source/WebCore/dom/Element.cpp (203851 => 203852)


--- trunk/Source/WebCore/dom/Element.cpp	2016-07-29 00:30:32 UTC (rev 203851)
+++ trunk/Source/WebCore/dom/Element.cpp	2016-07-29 01:19:41 UTC (rev 203852)
@@ -498,6 +498,19 @@
     return nullAtom;
 }
 
+Vector<String> Element::getAttributeNames() const
+{
+    Vector<String> attributesVector;
+    if (!hasAttributes())
+        return attributesVector;
+
+    auto attributes = attributesIterator();
+    attributesVector.reserveInitialCapacity(attributes.attributeCount());
+    for (auto& attribute : attributes)
+        attributesVector.uncheckedAppend(attribute.name().toString());
+    return attributesVector;
+}
+
 bool Element::isFocusable() const
 {
     if (!inDocument() || !supportsFocus())

Modified: trunk/Source/WebCore/dom/Element.h (203851 => 203852)


--- trunk/Source/WebCore/dom/Element.h	2016-07-29 00:30:32 UTC (rev 203851)
+++ trunk/Source/WebCore/dom/Element.h	2016-07-29 01:19:41 UTC (rev 203852)
@@ -77,6 +77,7 @@
     WEBCORE_EXPORT void setAttributeWithoutSynchronization(const QualifiedName&, const AtomicString& value);
     void setSynchronizedLazyAttribute(const QualifiedName&, const AtomicString& value);
     bool removeAttribute(const QualifiedName&);
+    Vector<String> getAttributeNames() const;
 
     // Typed getters and setters for language bindings.
     int getIntegralAttribute(const QualifiedName& attributeName) const;

Modified: trunk/Source/WebCore/dom/Element.idl (203851 => 203852)


--- trunk/Source/WebCore/dom/Element.idl	2016-07-29 00:30:32 UTC (rev 203851)
+++ trunk/Source/WebCore/dom/Element.idl	2016-07-29 01:19:41 UTC (rev 203852)
@@ -118,6 +118,8 @@
 
     void scrollIntoView(optional boolean alignWithTop = true);
 
+    sequence<DOMString> getAttributeNames();
+
     // WebKit extensions
 
     void scrollIntoViewIfNeeded(optional boolean centerIfNeeded = true);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to