Skip to content

Commit 161b3ec

Browse files
committed
Merge pull request w3c#40 from Ms2ger/idlharness-ctor-length
Update and improve the test for the length property of interface objects. r=jgraham
2 parents 91cef79 + 5d70149 commit 161b3ec

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

idlharness.js

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,41 +1142,46 @@ IdlInterface.prototype.test_self = function()
11421142
}
11431143
}.bind(this), this.name + " interface: existence and properties of interface object");
11441144

1145-
if (this.has_extended_attribute("Constructor"))
1146-
{
1147-
test(function()
1148-
{
1145+
if (!this.is_callback()) {
1146+
test(function() {
1147+
// This function tests WebIDL as of 2013-08-25.
1148+
// http://dev.w3.org/2006/webapi/WebIDL/#es-interface-call
1149+
11491150
assert_own_property(window, this.name,
11501151
"window does not have own property " + format_value(this.name));
11511152

1152-
// "Interface objects for interfaces declared with a [Constructor]
1153-
// extended attribute must have a property named “length” with
1154-
// attributes { [[Writable]]: false, [[Enumerable]]: false,
1155-
// [[Configurable]]: false } whose value is a Number determined as
1156-
// follows: . . .
1157-
// "Return the length of the shortest argument list of the entries
1158-
// in S."
1159-
// TODO: Variadic constructors. Should generalize this so that it
1160-
// works for testing operation length too (currently we just don't
1161-
// support multiple operations with the same identifier).
1162-
var expected_length = this.extAttrs
1163-
.filter(function(attr) { return attr.name == "Constructor"; })
1164-
.map(function(attr) {
1165-
return attr.arguments ? attr.arguments.filter(
1166-
function(arg) {
1167-
return !arg.optional;
1168-
}).length : 0;
1169-
})
1170-
.reduce(function(m, n) { return Math.min(m, n); });
1153+
// "Interface objects for non-callback interfaces MUST have a
1154+
// property named “length” with attributes { [[Writable]]: false,
1155+
// [[Enumerable]]: false, [[Configurable]]: false } whose value is
1156+
// a Number."
11711157
assert_own_property(window[this.name], "length");
1172-
assert_equals(window[this.name].length, expected_length, "wrong value for " + this.name + ".length");
11731158
var desc = Object.getOwnPropertyDescriptor(window[this.name], "length");
11741159
assert_false("get" in desc, this.name + ".length has getter");
11751160
assert_false("set" in desc, this.name + ".length has setter");
11761161
assert_false(desc.writable, this.name + ".length is writable");
11771162
assert_false(desc.enumerable, this.name + ".length is enumerable");
11781163
assert_false(desc.configurable, this.name + ".length is configurable");
1179-
}.bind(this), this.name + " interface constructor");
1164+
1165+
var constructors = this.extAttrs
1166+
.filter(function(attr) { return attr.name == "Constructor"; });
1167+
var expected_length;
1168+
if (!constructors.length) {
1169+
// "If the [Constructor] extended attribute, does not appear on
1170+
// the interface definition, then the value is 0."
1171+
expected_length = 0;
1172+
} else {
1173+
// "Otherwise, the value is determined as follows: . . .
1174+
// "Return the length of the shortest argument list of the
1175+
// entries in S."
1176+
expected_length = constructors.map(function(attr) {
1177+
return attr.arguments ? attr.arguments.filter(function(arg) {
1178+
return !arg.optional;
1179+
}).length : 0;
1180+
})
1181+
.reduce(function(m, n) { return Math.min(m, n); });
1182+
}
1183+
assert_equals(window[this.name].length, expected_length, "wrong value for " + this.name + ".length");
1184+
}.bind(this), this.name + " interface object length");
11801185
}
11811186

11821187
// TODO: Test named constructors if I find any interfaces that have them.

0 commit comments

Comments
 (0)