| OLD | NEW |
| 1 /* | 1 /* |
| 2 Distributed under both the W3C Test Suite License [1] and the W3C | 2 Distributed under both the W3C Test Suite License [1] and the W3C |
| 3 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the | 3 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the |
| 4 policies and contribution forms [3]. | 4 policies and contribution forms [3]. |
| 5 | 5 |
| 6 [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license | 6 [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license |
| 7 [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license | 7 [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license |
| 8 [3] http://www.w3.org/2004/10/27-testcases | 8 [3] http://www.w3.org/2004/10/27-testcases |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 (function(){ | 49 (function(){ |
| 50 "use strict"; | 50 "use strict"; |
| 51 /// Helpers /// | 51 /// Helpers /// |
| 52 function constValue (cnt) { | 52 function constValue (cnt) { |
| 53 if (cnt.type === "null") return null; | 53 if (cnt.type === "null") return null; |
| 54 if (cnt.type === "NaN") return NaN; | 54 if (cnt.type === "NaN") return NaN; |
| 55 if (cnt.type === "Infinity") return cnt.negative ? -Infinity : Infinity; | 55 if (cnt.type === "Infinity") return cnt.negative ? -Infinity : Infinity; |
| 56 return cnt.value; | 56 return cnt.value; |
| 57 } | 57 } |
| 58 | 58 |
| 59 function minOverloadLength(overloads) { |
| 60 if (!overloads.length) { |
| 61 return 0; |
| 62 } |
| 63 |
| 64 return overloads.map(function(attr) { |
| 65 return attr.arguments ? attr.arguments.filter(function(arg) { |
| 66 return !arg.optional && !arg.variadic; |
| 67 }).length : 0; |
| 68 }) |
| 69 .reduce(function(m, n) { return Math.min(m, n); }); |
| 70 } |
| 71 |
| 59 /// IdlArray /// | 72 /// IdlArray /// |
| 60 // Entry point | 73 // Entry point |
| 61 self.IdlArray = function() | 74 self.IdlArray = function() |
| 62 //@{ | 75 //@{ |
| 63 { | 76 { |
| 64 /** | 77 /** |
| 65 * A map from strings to the corresponding named IdlObject, such as | 78 * A map from strings to the corresponding named IdlObject, such as |
| 66 * IdlInterface or IdlException. These are the things that test() will run | 79 * IdlInterface or IdlException. These are the things that test() will run |
| 67 * tests on. | 80 * tests on. |
| 68 */ | 81 */ |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 assert_own_property(self[this.name], "length"); | 760 assert_own_property(self[this.name], "length"); |
| 748 var desc = Object.getOwnPropertyDescriptor(self[this.name], "length"
); | 761 var desc = Object.getOwnPropertyDescriptor(self[this.name], "length"
); |
| 749 assert_false("get" in desc, this.name + ".length has getter"); | 762 assert_false("get" in desc, this.name + ".length has getter"); |
| 750 assert_false("set" in desc, this.name + ".length has setter"); | 763 assert_false("set" in desc, this.name + ".length has setter"); |
| 751 assert_false(desc.writable, this.name + ".length is writable"); | 764 assert_false(desc.writable, this.name + ".length is writable"); |
| 752 assert_false(desc.enumerable, this.name + ".length is enumerable"); | 765 assert_false(desc.enumerable, this.name + ".length is enumerable"); |
| 753 assert_true(desc.configurable, this.name + ".length is not configura
ble"); | 766 assert_true(desc.configurable, this.name + ".length is not configura
ble"); |
| 754 | 767 |
| 755 var constructors = this.extAttrs | 768 var constructors = this.extAttrs |
| 756 .filter(function(attr) { return attr.name == "Constructor"; }); | 769 .filter(function(attr) { return attr.name == "Constructor"; }); |
| 757 var expected_length; | 770 var expected_length = minOverloadLength(constructors); |
| 758 if (!constructors.length) { | |
| 759 // "If the [Constructor] extended attribute, does not appear on | |
| 760 // the interface definition, then the value is 0." | |
| 761 expected_length = 0; | |
| 762 } else { | |
| 763 // "Otherwise, the value is determined as follows: . . . | |
| 764 // "Return the length of the shortest argument list of the | |
| 765 // entries in S." | |
| 766 expected_length = constructors.map(function(attr) { | |
| 767 return attr.arguments ? attr.arguments.filter(function(arg)
{ | |
| 768 return !arg.optional; | |
| 769 }).length : 0; | |
| 770 }) | |
| 771 .reduce(function(m, n) { return Math.min(m, n); }); | |
| 772 } | |
| 773 assert_equals(self[this.name].length, expected_length, "wrong value
for " + this.name + ".length"); | 771 assert_equals(self[this.name].length, expected_length, "wrong value
for " + this.name + ".length"); |
| 774 }.bind(this), this.name + " interface object length"); | 772 }.bind(this), this.name + " interface object length"); |
| 775 } | 773 } |
| 776 | 774 |
| 777 // TODO: Test named constructors if I find any interfaces that have them. | 775 // TODO: Test named constructors if I find any interfaces that have them. |
| 778 | 776 |
| 779 test(function() | 777 test(function() |
| 780 { | 778 { |
| 781 // This function tests WebIDL as of 2015-01-21. | 779 // This function tests WebIDL as of 2015-01-21. |
| 782 // https://heycam.github.io/webidl/#interface-object | 780 // https://heycam.github.io/webidl/#interface-object |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 "property should be configurable if and only if not unforgeabl
e"); | 1113 "property should be configurable if and only if not unforgeabl
e"); |
| 1116 // "The value of the property is a Function object whose | 1114 // "The value of the property is a Function object whose |
| 1117 // behavior is as follows . . ." | 1115 // behavior is as follows . . ." |
| 1118 assert_equals(typeof memberHolderObject[member.name], "function", | 1116 assert_equals(typeof memberHolderObject[member.name], "function", |
| 1119 "property must be a function"); | 1117 "property must be a function"); |
| 1120 // "The value of the Function object’s “length” property is | 1118 // "The value of the Function object’s “length” property is |
| 1121 // a Number determined as follows: | 1119 // a Number determined as follows: |
| 1122 // ". . . | 1120 // ". . . |
| 1123 // "Return the length of the shortest argument list of the | 1121 // "Return the length of the shortest argument list of the |
| 1124 // entries in S." | 1122 // entries in S." |
| 1125 // | |
| 1126 // TODO: Doesn't handle overloading or variadic arguments. | |
| 1127 assert_equals(memberHolderObject[member.name].length, | 1123 assert_equals(memberHolderObject[member.name].length, |
| 1128 member.arguments.filter(function(arg) { | 1124 minOverloadLength(this.members.filter(function(m) { |
| 1129 return !arg.optional; | 1125 return m.type == "operation" && m.name == member.name; |
| 1130 }).length, | 1126 })), |
| 1131 "property has wrong .length"); | 1127 "property has wrong .length"); |
| 1132 | 1128 |
| 1133 // Make some suitable arguments | 1129 // Make some suitable arguments |
| 1134 var args = member.arguments.map(function(arg) { | 1130 var args = member.arguments.map(function(arg) { |
| 1135 return create_suitable_object(arg.idlType); | 1131 return create_suitable_object(arg.idlType); |
| 1136 }); | 1132 }); |
| 1137 | 1133 |
| 1138 // "Let O be a value determined as follows: | 1134 // "Let O be a value determined as follows: |
| 1139 // ". . . | 1135 // ". . . |
| 1140 // "Otherwise, throw a TypeError." | 1136 // "Otherwise, throw a TypeError." |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 if (!this.is_global() && !member.isUnforgeable) { | 1449 if (!this.is_global() && !member.isUnforgeable) { |
| 1454 assert_inherits(obj, member.name); | 1450 assert_inherits(obj, member.name); |
| 1455 } else { | 1451 } else { |
| 1456 assert_own_property(obj, member.name); | 1452 assert_own_property(obj, member.name); |
| 1457 } | 1453 } |
| 1458 } | 1454 } |
| 1459 else | 1455 else |
| 1460 { | 1456 { |
| 1461 assert_false(member.name in obj); | 1457 assert_false(member.name in obj); |
| 1462 } | 1458 } |
| 1459 |
| 1460 var minLength = minOverloadLength(this.members.filter(function(m
) { |
| 1461 return m.type == "operation" && m.name == member.name; |
| 1462 })); |
| 1463 var args = []; | 1463 var args = []; |
| 1464 for (var i = 0; i < member.arguments.length; i++) | 1464 for (var i = 0; i < minLength; i++) { |
| 1465 { | |
| 1466 if (member.arguments[i].optional) | |
| 1467 { | |
| 1468 break; | |
| 1469 } | |
| 1470 assert_throws(new TypeError(), function() | 1465 assert_throws(new TypeError(), function() |
| 1471 { | 1466 { |
| 1472 obj[member.name].apply(obj, args); | 1467 obj[member.name].apply(obj, args); |
| 1473 }.bind(this), "Called with " + i + " arguments"); | 1468 }.bind(this), "Called with " + i + " arguments"); |
| 1474 | 1469 |
| 1475 args.push(create_suitable_object(member.arguments[i].idlType
)); | 1470 args.push(create_suitable_object(member.arguments[i].idlType
)); |
| 1476 } | 1471 } |
| 1477 }.bind(this), this.name + " interface: calling " + member.name + | 1472 }.bind(this), this.name + " interface: calling " + member.name + |
| 1478 "(" + member.arguments.map(function(m) { return m.idlType.idlType; }
) + | 1473 "(" + member.arguments.map(function(m) { return m.idlType.idlType; }
) + |
| 1479 ") on " + desc + " with too few arguments must throw TypeError"); | 1474 ") on " + desc + " with too few arguments must throw TypeError"); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 /** An array of values produced by the "typedef" production. */ | 1697 /** An array of values produced by the "typedef" production. */ |
| 1703 this.values = obj.values; | 1698 this.values = obj.values; |
| 1704 | 1699 |
| 1705 } | 1700 } |
| 1706 //@} | 1701 //@} |
| 1707 | 1702 |
| 1708 IdlTypedef.prototype = Object.create(IdlObject.prototype); | 1703 IdlTypedef.prototype = Object.create(IdlObject.prototype); |
| 1709 | 1704 |
| 1710 }()); | 1705 }()); |
| 1711 // vim: set expandtab shiftwidth=4 tabstop=4 foldmarker=@{,@} foldmethod=marker: | 1706 // vim: set expandtab shiftwidth=4 tabstop=4 foldmarker=@{,@} foldmethod=marker: |
| OLD | NEW |