Bug 1523562 [wpt PR 14629] - Revamp how idlharness.js handles iterable declarations, a=testonly
authorPhilip Jägenstedt <philip@foolip.org>
Thu, 31 Jan 2019 18:55:32 +0000
changeset 457994 02b91f91e13e459202d230fbce1cf9a0a74f36bf
parent 457993 0a310f6d2f6431013e233e02e2db90e6f5c971f6
child 457995 1bb2906875dd5eb12151108bd3e6a66bc033069a
push id35518
push useropoprus@mozilla.com
push dateFri, 08 Feb 2019 09:55:14 +0000
treeherdermozilla-central@3a3e393396f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1523562, 14629
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1523562 [wpt PR 14629] - Revamp how idlharness.js handles iterable declarations, a=testonly Automatic update from web-platform-tests Revamp how idlharness.js handles iterable declarations (#14629) Instead of adding IDL interface members in `add_iterable_members` in the style of what webidl2.js would have added if the declaration were expanded, instead test directly for what effect a single `iterable<T>` or `iterable<T1,T2>` declaration should have. This is more along the lines of `test_member_stringifier`, where no `toString` is added as IDL members. Alternative to https://github.com/web-platform-tests/wpt/pull/9790. -- wpt-commits: 76bbe5aeb4e8f8fd050af8d7d4933a4a507bba27 wpt-pr: 14629
testing/web-platform/tests/interfaces/dom.idl
testing/web-platform/tests/resources/idlharness.js
--- a/testing/web-platform/tests/interfaces/dom.idl
+++ b/testing/web-platform/tests/interfaces/dom.idl
@@ -140,17 +140,17 @@ interface mixin Slotable {
 };
 Element includes Slotable;
 Text includes Slotable;
 
 [Exposed=Window]
 interface NodeList {
   getter Node? item(unsigned long index);
   readonly attribute unsigned long length;
-//  iterable<Node>;
+  iterable<Node>;
 };
 
 [Exposed=Window, LegacyUnenumerableNamedProperties]
 interface HTMLCollection {
   readonly attribute unsigned long length;
   getter Element? item(unsigned long index);
   getter Element? namedItem(DOMString name);
 };
@@ -543,10 +543,10 @@ interface DOMTokenList {
   getter DOMString? item(unsigned long index);
   boolean contains(DOMString token);
   [CEReactions] void add(DOMString... tokens);
   [CEReactions] void remove(DOMString... tokens);
   [CEReactions] boolean toggle(DOMString token, optional boolean force);
   [CEReactions] boolean replace(DOMString token, DOMString newToken);
   boolean supports(DOMString token);
   [CEReactions] stringifier attribute DOMString value;
-  //  iterable<DOMString>;
+  iterable<DOMString>;
 };
--- a/testing/web-platform/tests/resources/idlharness.js
+++ b/testing/web-platform/tests/resources/idlharness.js
@@ -2304,31 +2304,16 @@ IdlInterface.prototype.do_member_operati
         // interface.  (Have to be sure to get inheritance right.)
         throwOrReject(a_test, member, memberHolderObject[member.name], {}, args,
                       "calling operation with this = {} didn't throw TypeError", cb);
     } else {
         done();
     }
 }
 
-IdlInterface.prototype.add_iterable_members = function(member)
-{
-    this.members.push(new IdlInterfaceMember(
-        { type: "operation", name: "entries", idlType: "iterator", arguments: []}));
-    this.members.push(new IdlInterfaceMember(
-        { type: "operation", name: "keys", idlType: "iterator", arguments: []}));
-    this.members.push(new IdlInterfaceMember(
-        { type: "operation", name: "values", idlType: "iterator", arguments: []}));
-    this.members.push(new IdlInterfaceMember(
-        { type: "operation", name: "forEach", idlType: "void",
-          arguments:
-          [{ name: "callback", idlType: {idlType: "function"}},
-           { name: "thisValue", idlType: {idlType: "any"}, optional: true}]}));
-};
-
 IdlInterface.prototype.test_to_json_operation = function(memberHolderObject, member) {
     var instanceName = memberHolderObject && memberHolderObject.constructor.name
         || member.name + " object";
     if (member.has_extended_attribute("Default")) {
         subsetTestByKey(this.name, test, function() {
             var map = this.default_to_json_operation();
             var json = memberHolderObject.toJSON();
             map.forEach(function(type, k) {
@@ -2346,37 +2331,39 @@ IdlInterface.prototype.test_to_json_oper
             assert_true(this.array.is_json_type(member.idlType), JSON.stringify(member.idlType) + " is not an appropriate return value for the toJSON operation of " + instanceName);
             this.array.assert_type_is(memberHolderObject.toJSON(), member.idlType);
         }.bind(this), "Test toJSON operation of " + instanceName);
     }
 };
 
 IdlInterface.prototype.test_member_iterable = function(member)
 {
-    var isPairIterator = member.idlType.length === 2;
     subsetTestByKey(this.name, test, function()
     {
-        var descriptor = Object.getOwnPropertyDescriptor(this.get_interface_object().prototype, Symbol.iterator);
-        assert_true(descriptor.writable, "property should be writable");
-        assert_true(descriptor.configurable, "property should be configurable");
-        assert_false(descriptor.enumerable, "property should not be enumerable");
-        assert_equals(this.get_interface_object().prototype[Symbol.iterator].name, isPairIterator ? "entries" : "values", "@@iterator function does not have the right name");
-    }.bind(this), "Testing Symbol.iterator property of iterable interface " + this.name);
-
-    if (isPairIterator) {
-        subsetTestByKey(this.name, test, function() {
-            assert_equals(this.get_interface_object().prototype[Symbol.iterator], this.get_interface_object().prototype["entries"], "entries method is not the same as @@iterator");
-        }.bind(this), "Testing pair iterable interface " + this.name);
-    } else {
-        subsetTestByKey(this.name, test, function() {
-            ["entries", "keys", "values", "forEach", Symbol.Iterator].forEach(function(property) {
-                assert_equals(this.get_interface_object().prototype[property], Array.prototype[property], property + " function is not the same as Array one");
+        var isPairIterator = member.idlType.length === 2;
+        var proto = this.get_interface_object().prototype;
+        var descriptor = Object.getOwnPropertyDescriptor(proto, Symbol.iterator);
+
+        assert_true(descriptor.writable, "@@iterator property should be writable");
+        assert_true(descriptor.configurable, "@@iterator property should be configurable");
+        assert_false(descriptor.enumerable, "@@iterator property should not be enumerable");
+        assert_equals(typeof descriptor.value, "function", "@@iterator property should be a function");
+        assert_equals(descriptor.value.length, 0, "@@iterator function object length should be 0");
+        assert_equals(descriptor.value.name, isPairIterator ? "entries" : "values", "@@iterator function object should have the right name");
+
+        if (isPairIterator) {
+            assert_equals(proto["entries"], proto[Symbol.iterator], "entries method should be the same as @@iterator method");
+        } else {
+            assert_equals(proto[Symbol.iterator], Array.prototype[Symbol.iterator], "@@iterator method should be the same as Array prototype's");
+            ["entries", "keys", "values", "forEach", Symbol.iterator].forEach(function(property) {
+                var propertyName = property === Symbol.iterator ? "@@iterator" : property;
+                assert_equals(proto[property], Array.prototype[property], propertyName + " method should be the same as Array prototype's");
             }.bind(this));
-        }.bind(this), "Testing value iterable interface " + this.name);
-    }
+        }
+    }.bind(this), this.name + " interface: iterable<" + member.idlType.map(function(t) { return t.idlType; }).join(", ") + ">");
 };
 
 IdlInterface.prototype.test_member_stringifier = function(member)
 {
     subsetTestByKey(this.name, test, function()
     {
         if (this.is_callback() && !this.has_constants()) {
             return;
@@ -2435,29 +2422,16 @@ IdlInterface.prototype.test_member_strin
     }.bind(this), this.name + " interface: stringifier");
 };
 
 IdlInterface.prototype.test_members = function()
 {
     for (var i = 0; i < this.members.length; i++)
     {
         var member = this.members[i];
-        switch (member.type) {
-        case "iterable":
-            this.add_iterable_members(member);
-            break;
-        // TODO: add setlike and maplike handling.
-        default:
-            break;
-        }
-    }
-
-    for (var i = 0; i < this.members.length; i++)
-    {
-        var member = this.members[i];
         if (member.untested) {
             continue;
         }
 
         if (!exposed_in(exposure_set(member, this.exposureSet))) {
             subsetTestByKey(this.name, test, function() {
                 // It's not exposed, so we shouldn't find it anywhere.
                 assert_false(member.name in this.get_interface_object(),