Title: [203728] trunk
Revision
203728
Author
[email protected]
Date
2016-07-26 11:00:57 -0700 (Tue, 26 Jul 2016)

Log Message

DOMTokenList should be iterable
https://bugs.webkit.org/show_bug.cgi?id=160183

Patch by Youenn Fablet <[email protected]> on 2016-07-26
Reviewed by Chris Dumez.

Source/WebCore:

DOMTokenList should be iterable as per https://dom.spec.whatwg.org/#interface-domtokenlist

Test: fast/dom/domTokenListIterator.html

* html/DOMTokenList.idl: Added iterable to the interface description.

LayoutTests:

* fast/dom/domTokenListIterator-expected.txt: Added.
* fast/dom/domTokenListIterator.html: Added.
* fast/dom/iterable-tests.js: Added.
* fast/dom/nodeListIterator-expected.txt:
* fast/dom/nodeListIterator.html: Making use of iterable-tests.js

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (203727 => 203728)


--- trunk/LayoutTests/ChangeLog	2016-07-26 17:26:28 UTC (rev 203727)
+++ trunk/LayoutTests/ChangeLog	2016-07-26 18:00:57 UTC (rev 203728)
@@ -1,3 +1,16 @@
+2016-07-26  Youenn Fablet  <[email protected]>
+
+        DOMTokenList should be iterable
+        https://bugs.webkit.org/show_bug.cgi?id=160183
+
+        Reviewed by Chris Dumez.
+
+        * fast/dom/domTokenListIterator-expected.txt: Added.
+        * fast/dom/domTokenListIterator.html: Added.
+        * fast/dom/iterable-tests.js: Added.
+        * fast/dom/nodeListIterator-expected.txt:
+        * fast/dom/nodeListIterator.html: Making use of iterable-tests.js
+
 2016-07-26  John Wilander  <[email protected]>
 
         Stop supporting compressed character sets BOCU-1 and SCSU

Added: trunk/LayoutTests/fast/dom/domTokenListIterator-expected.txt (0 => 203728)


--- trunk/LayoutTests/fast/dom/domTokenListIterator-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/domTokenListIterator-expected.txt	2016-07-26 18:00:57 UTC (rev 203728)
@@ -0,0 +1,76 @@
+Testing of DOMTokenList iterable capacities.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testedIterable.entries is entriesFunction
+PASS testedIterable.forEach is forEachFunction
+PASS testedIterable.keys is keysFunction
+PASS testedIterable.values is valuesFunction
+PASS testedIterable.length is 2
+PASS item is children[index++]
+PASS item is children[index++]
+PASS pair[0] is children[0]
+PASS pair[1] is children[1]
+PASS forEachContainer is testedIterable
+PASS forEachIndex is index
+PASS node is children[index++]
+PASS thisValue is window
+PASS forEachContainer is testedIterable
+PASS forEachIndex is index
+PASS node is children[index++]
+PASS thisValue is window
+PASS thisValue is window
+PASS thisValue is window
+PASS thisValue is givenThisValue
+PASS thisValue is givenThisValue
+PASS iterator.next().value is 0
+PASS iterator.next().value is 1
+PASS end.done is true
+PASS end.value is undefined.
+PASS iterator.next().value is children[0]
+PASS iterator.next().value is children[1]
+PASS end.done is true
+PASS end.value is undefined.
+PASS pair.length is 2
+PASS pair[0] is 0
+PASS pair[1] is children[0]
+PASS pair.length is 2
+PASS pair[0] is 1
+PASS pair[1] is children[1]
+PASS end.done is true
+PASS end.value is undefined.
+PASS end.done is true
+PASS end.value is undefined.
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS descriptor.enumerable is false
+PASS testedIterablePrototype[Symbol.iterator] = valuesFunction; did not throw exception.
+PASS checkItemType(a) is true
+PASS checkItemType(a) is true
+PASS checkItemType(a) is true
+PASS checkItemType(a) is true
+PASS counter is 4
+PASS checkItemType(v) is true
+PASS checkItemType(v) is true
+PASS checkItemType(v) is true
+PASS checkItemType(v) is true
+PASS counter is 4
+PASS typeof k is "number"
+PASS typeof k is "number"
+PASS typeof k is "number"
+PASS typeof k is "number"
+PASS counter is 4
+PASS typeof e[0] is "number"
+PASS e[1] is testedIterable[e[0]]
+PASS typeof e[0] is "number"
+PASS e[1] is testedIterable[e[0]]
+PASS typeof e[0] is "number"
+PASS e[1] is testedIterable[e[0]]
+PASS typeof e[0] is "number"
+PASS e[1] is testedIterable[e[0]]
+PASS counter is 4
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/domTokenListIterator.html (0 => 203728)


--- trunk/LayoutTests/fast/dom/domTokenListIterator.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/domTokenListIterator.html	2016-07-26 18:00:57 UTC (rev 203728)
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <title class="a b">Testing of DOMTokenList iterable capacities</title>
+        <script src=""
+    </head>
+    <body>
+        <script>
+            description('Testing of DOMTokenList iterable capacities.');
+
+            var testingGround = document.getElementsByTagName('title')[0];
+            var classList = testingGround.classList;
+
+            function checkItemType(item) {
+                return typeof item === 'string';
+            }
+            function createIterable(items) {
+                items.push(classList[0]);
+                items.push(classList[1]);
+                return classList;
+            }
+            function updateIterable() {
+                testingGround.setAttribute("class", "a b c d");
+            }
+          </script>
+        <script src=""
+        <script src=""
+    </body>
+</html>

Added: trunk/LayoutTests/fast/dom/iterable-tests.js (0 => 203728)


--- trunk/LayoutTests/fast/dom/iterable-tests.js	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/iterable-tests.js	2016-07-26 18:00:57 UTC (rev 203728)
@@ -0,0 +1,136 @@
+// Modifying Array prototype to ensure this does not impact iterable methods.
+var entriesFunction = Array.prototype.entries;
+Array.prototype.entries = function() {
+    console.log("Array.prototype.entries called");
+  return entriesFunction.apply(this, arguments);
+}
+var forEachFunction = Array.prototype.forEach;
+Array.prototype.forEach = function() {
+    console.log("Array.prototype.forEach called");
+  return forEachFunction.apply(this, arguments);
+}
+var keysFunction = Array.prototype.keys;
+Array.prototype.keys = function() {
+    console.log("Array.prototype.keys called");
+  return keysFunction.apply(this, arguments);
+}
+var valuesFunction = Array.prototype.values;
+Array.prototype.values = function() {
+    console.log("Array.prototype.values called");
+  return valuesFunction.apply(this, arguments);
+}
+
+var end;
+function checkEndIterator(iteratorValue) {
+  end = iteratorValue;
+  shouldBeTrue('end.done');
+  shouldBeUndefined('end.value');
+}
+
+// Should create an iterable with two items, put in children array
+var children = [];
+var testedIterable = createIterable(children);
+
+shouldBe('testedIterable.entries', 'entriesFunction');
+shouldBe('testedIterable.forEach', 'forEachFunction');
+shouldBe('testedIterable.keys', 'keysFunction');
+shouldBe('testedIterable.values', 'valuesFunction');
+
+shouldBe("testedIterable.length", "2");
+
+var index = 0;
+for (var item of testedIterable)
+    shouldBe('item', 'children[index++]');
+
+pair = Array.from(testedIterable);
+shouldBe('pair[0]', 'children[0]');
+shouldBe('pair[1]', 'children[1]');
+
+index = 0;
+var node;
+var forEachIndex;
+var forEachContainer;
+var thisValue;
+testedIterable.forEach(function(n, i, c) {
+    node = n;
+    forEachIndex = i;
+    forEachContainer = c;
+    thisValue = this;
+    shouldBe('forEachContainer', 'testedIterable');
+    shouldBe('forEachIndex', 'index');
+    shouldBe('node', 'children[index++]');
+    shouldBe('thisValue', 'window');
+});
+
+testedIterable.forEach(function() {
+    thisValue = this;
+    shouldBe('thisValue', 'window');
+}, undefined);
+
+var givenThisValue = testedIterable;
+testedIterable.forEach(function() {
+    thisValue = this;
+    shouldBe('thisValue', 'givenThisValue');
+}, givenThisValue);
+
+var iterator = testedIterable.keys();
+shouldBe('iterator.next().value', '0');
+shouldBe('iterator.next().value', '1');
+checkEndIterator(iterator.next());
+
+var iterator = testedIterable.values();
+shouldBe('iterator.next().value', 'children[0]');
+shouldBe('iterator.next().value', 'children[1]');
+checkEndIterator(iterator.next());
+
+var iterator = testedIterable.entries();
+var pair = iterator.next().value;
+shouldBe('pair.length', '2');
+shouldBe('pair[0]', '0');
+shouldBe('pair[1]', 'children[0]');
+pair = iterator.next().value;
+shouldBe('pair.length', '2');
+shouldBe('pair[0]', '1');
+shouldBe('pair[1]', 'children[1]');
+checkEndIterator(iterator.next());
+
+// Should add 2 new items.
+updateIterable();
+
+checkEndIterator(iterator.next());
+
+var testedIterablePrototype = Object.getPrototypeOf(testedIterable)
+var descriptor = Object.getOwnPropertyDescriptor(testedIterablePrototype, Symbol.iterator);
+shouldBeTrue('descriptor.configurable');
+shouldBeTrue('descriptor.writable');
+shouldBeFalse('descriptor.enumerable');
+
+shouldNotThrow('testedIterablePrototype[Symbol.iterator] = valuesFunction;');
+var counter = 0;
+for (var a of testedIterable) {
+    shouldBeTrue('checkItemType(a)');
+    counter++;
+}
+shouldBe('counter', '4');
+counter = 0;
+for (var v of testedIterable.values()) {
+    shouldBeTrue('checkItemType(v)');
+    counter++;
+}
+shouldBe('counter', '4');
+
+counter = 0;
+for (var k of testedIterable.keys()) {
+    shouldBe('typeof k', '"number"');
+    counter++;
+}
+shouldBe('counter', '4');
+
+counter = 0;
+for (var e of testedIterable.entries()) {
+    shouldBe('typeof e[0]', '"number"');
+    shouldBe('e[1]', 'testedIterable[e[0]]');
+    counter++;
+}
+
+shouldBe('counter', '4');

Modified: trunk/LayoutTests/fast/dom/nodeListIterator-expected.txt (203727 => 203728)


--- trunk/LayoutTests/fast/dom/nodeListIterator-expected.txt	2016-07-26 17:26:28 UTC (rev 203727)
+++ trunk/LayoutTests/fast/dom/nodeListIterator-expected.txt	2016-07-26 18:00:57 UTC (rev 203728)
@@ -3,20 +3,20 @@
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS nodeList.entries === entriesFunction is true
-PASS nodeList.forEach === forEachFunction is true
-PASS nodeList.keys === keysFunction is true
-PASS nodeList.values === valuesFunction is true
-PASS nodeList.length is 2
+PASS testedIterable.entries is entriesFunction
+PASS testedIterable.forEach is forEachFunction
+PASS testedIterable.keys is keysFunction
+PASS testedIterable.values is valuesFunction
+PASS testedIterable.length is 2
 PASS item is children[index++]
 PASS item is children[index++]
 PASS pair[0] is children[0]
 PASS pair[1] is children[1]
-PASS forEachContainer is nodeList
+PASS forEachContainer is testedIterable
 PASS forEachIndex is index
 PASS node is children[index++]
 PASS thisValue is window
-PASS forEachContainer is nodeList
+PASS forEachContainer is testedIterable
 PASS forEachIndex is index
 PASS node is children[index++]
 PASS thisValue is window
@@ -27,11 +27,11 @@
 PASS iterator.next().value is 0
 PASS iterator.next().value is 1
 PASS end.done is true
-PASS end.value is undefined
+PASS end.value is undefined.
 PASS iterator.next().value is children[0]
 PASS iterator.next().value is children[1]
 PASS end.done is true
-PASS end.value is undefined
+PASS end.value is undefined.
 PASS pair.length is 2
 PASS pair[0] is 0
 PASS pair[1] is children[0]
@@ -39,18 +39,37 @@
 PASS pair[0] is 1
 PASS pair[1] is children[1]
 PASS end.done is true
-PASS end.value is undefined
+PASS end.value is undefined.
 PASS end.done is true
-PASS end.value is undefined
+PASS end.value is undefined.
 PASS descriptor.configurable is true
 PASS descriptor.writable is true
 PASS descriptor.enumerable is false
-PASS NodeList.prototype[Symbol.iterator] = valuesFunction; did not throw exception.
-PASS a instanceof Node is true
-PASS a instanceof Node is true
-PASS a instanceof Node is true
-PASS a instanceof Node is true
+PASS testedIterablePrototype[Symbol.iterator] = valuesFunction; did not throw exception.
+PASS checkItemType(a) is true
+PASS checkItemType(a) is true
+PASS checkItemType(a) is true
+PASS checkItemType(a) is true
 PASS counter is 4
+PASS checkItemType(v) is true
+PASS checkItemType(v) is true
+PASS checkItemType(v) is true
+PASS checkItemType(v) is true
+PASS counter is 4
+PASS typeof k is "number"
+PASS typeof k is "number"
+PASS typeof k is "number"
+PASS typeof k is "number"
+PASS counter is 4
+PASS typeof e[0] is "number"
+PASS e[1] is testedIterable[e[0]]
+PASS typeof e[0] is "number"
+PASS e[1] is testedIterable[e[0]]
+PASS typeof e[0] is "number"
+PASS e[1] is testedIterable[e[0]]
+PASS typeof e[0] is "number"
+PASS e[1] is testedIterable[e[0]]
+PASS counter is 4
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/dom/nodeListIterator.html (203727 => 203728)


--- trunk/LayoutTests/fast/dom/nodeListIterator.html	2016-07-26 17:26:28 UTC (rev 203727)
+++ trunk/LayoutTests/fast/dom/nodeListIterator.html	2016-07-26 18:00:57 UTC (rev 203728)
@@ -1,4 +1,4 @@
-<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<!DOCTYPE html>
 <html>
     <head>
         <script src=""
@@ -7,126 +7,28 @@
         <script>
             description('Testing of NodeList iterable capacities.');
 
-            // Modifying Array prototype to ensure this does not impact NodeList iterable methods.
-            var entriesFunction = Array.prototype.entries;
-            Array.prototype.entries = function() {
-                console.log("Array.prototype.entries called");
-              return entriesFunction.apply(this, arguments);
-            }
-            var forEachFunction = Array.prototype.forEach;
-            Array.prototype.forEach = function() {
-                console.log("Array.prototype.forEach called");
-              return forEachFunction.apply(this, arguments);
-            }
-            var keysFunction = Array.prototype.keys;
-            Array.prototype.keys = function() {
-                console.log("Array.prototype.keys called");
-              return keysFunction.apply(this, arguments);
-            }
-            var valuesFunction = Array.prototype.values;
-            Array.prototype.values = function() {
-                console.log("Array.prototype.values called");
-              return valuesFunction.apply(this, arguments);
-            }
-
-            if (window.testRunner)
-                testRunner.dumpAsText();
-
-            var end;
-            function checkEndIterator(iteratorValue) {
-              end = iteratorValue;
-              shouldBe('end.done', 'true');
-              shouldBe('end.value', 'undefined');
-            }
-
             var testingGround = document.createElement('div');
-            var children = [document.createElement('div'), document.createElement('ol')];
-            testingGround.appendChild(children[0]);
-            testingGround.appendChild(children[1]);
+            var nodes = [document.createElement('div'), document.createElement('ol')];
+            testingGround.appendChild(nodes[0]);
+            testingGround.appendChild(nodes[1]);
             document.body.appendChild(testingGround);
 
             var nodeList = testingGround.childNodes;
 
-            shouldBeTrue('nodeList.entries === entriesFunction');
-            shouldBeTrue('nodeList.forEach === forEachFunction');
-            shouldBeTrue('nodeList.keys === keysFunction');
-            shouldBeTrue('nodeList.values === valuesFunction');
-
-            shouldBe("nodeList.length", "2");
-
-            var index = 0;
-            for (var item of nodeList)
-                shouldBe('item', 'children[index++]');
-
-            pair = Array.from(nodeList);
-            shouldBe('pair[0]', 'children[0]');
-            shouldBe('pair[1]', 'children[1]');
-
-            index = 0;
-            var node;
-            var forEachIndex;
-            var forEachContainer;
-            var thisValue;
-            nodeList.forEach(function(n, i, c) {
-                node = n;
-                forEachIndex = i;
-                forEachContainer = c;
-                thisValue = this;
-                shouldBe('forEachContainer', 'nodeList');
-                shouldBe('forEachIndex', 'index');
-                shouldBe('node', 'children[index++]');
-                shouldBe('thisValue', 'window');
-            });
-
-            nodeList.forEach(function() {
-                thisValue = this;
-                shouldBe('thisValue', 'window');
-            }, undefined);
-
-            var givenThisValue = nodeList;
-            nodeList.forEach(function() {
-                thisValue = this;
-                shouldBe('thisValue', 'givenThisValue');
-            }, givenThisValue);
-
-            var iterator = nodeList.keys();
-            shouldBe('iterator.next().value', '0');
-            shouldBe('iterator.next().value', '1');
-            checkEndIterator(iterator.next());
-
-            var iterator = nodeList.values();
-            shouldBe('iterator.next().value', 'children[0]');
-            shouldBe('iterator.next().value', 'children[1]');
-            checkEndIterator(iterator.next());
-
-            var iterator = nodeList.entries();
-            var pair = iterator.next().value;
-            shouldBe('pair.length', '2');
-            shouldBe('pair[0]', '0');
-            shouldBe('pair[1]', 'children[0]');
-            pair = iterator.next().value;
-            shouldBe('pair.length', '2');
-            shouldBe('pair[0]', '1');
-            shouldBe('pair[1]', 'children[1]');
-            checkEndIterator(iterator.next());
-
-            testingGround.appendChild(document.createElement('ul'));
-            testingGround.appendChild(document.createElement('p'));
-            checkEndIterator(iterator.next());
-
-            var descriptor = Object.getOwnPropertyDescriptor(NodeList.prototype, Symbol.iterator);
-            shouldBeTrue('descriptor.configurable');
-            shouldBeTrue('descriptor.writable');
-            shouldBeFalse('descriptor.enumerable');
-
-            shouldNotThrow('NodeList.prototype[Symbol.iterator] = valuesFunction;');
-            var counter = 0;
-            for (var a of nodeList) {
-                shouldBeTrue('a instanceof Node');
-                counter++;
+            function checkItemType(item) {
+                return item instanceof Node;
             }
-            shouldBe('counter', '4');
+            function createIterable(items) {
+                items.push(nodes[0]);
+                items.push(nodes[1]);
+                return nodeList;
+            }
+            function updateIterable() {
+                testingGround.appendChild(document.createElement('ul'));
+                testingGround.appendChild(document.createElement('p'));
+            }
         </script>
+        <script src=""
         <script src=""
     </body>
 </html>

Modified: trunk/Source/WebCore/ChangeLog (203727 => 203728)


--- trunk/Source/WebCore/ChangeLog	2016-07-26 17:26:28 UTC (rev 203727)
+++ trunk/Source/WebCore/ChangeLog	2016-07-26 18:00:57 UTC (rev 203728)
@@ -1,3 +1,16 @@
+2016-07-26  Youenn Fablet  <[email protected]>
+
+        DOMTokenList should be iterable
+        https://bugs.webkit.org/show_bug.cgi?id=160183
+
+        Reviewed by Chris Dumez.
+
+        DOMTokenList should be iterable as per https://dom.spec.whatwg.org/#interface-domtokenlist
+
+        Test: fast/dom/domTokenListIterator.html
+
+        * html/DOMTokenList.idl: Added iterable to the interface description.
+
 2016-07-26  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r203719.

Modified: trunk/Source/WebCore/html/DOMTokenList.idl (203727 => 203728)


--- trunk/Source/WebCore/html/DOMTokenList.idl	2016-07-26 17:26:28 UTC (rev 203727)
+++ trunk/Source/WebCore/html/DOMTokenList.idl	2016-07-26 18:00:57 UTC (rev 203728)
@@ -34,6 +34,8 @@
     [RaisesException] void remove(DOMString... tokens);
     [RaisesException] boolean toggle(DOMString token, optional boolean force);
 
+    iterable<DOMString>;
+
     attribute DOMString value;
 
 #if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to