Skip to content

Commit

Permalink
Correct the expected length of overloaded operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger committed May 10, 2015
1 parent d4fb16e commit e76f07a
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions idlharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ function constValue (cnt) {
return cnt.value;
}

function minOverloadLength(overloads) {
if (!overloads.length) {
return 0;
}

return overloads.map(function(attr) {
return attr.arguments ? attr.arguments.filter(function(arg) {
return !arg.optional && !arg.variadic;
}).length : 0;
})
.reduce(function(m, n) { return Math.min(m, n); });
}

/// IdlArray ///
// Entry point
self.IdlArray = function()
Expand Down Expand Up @@ -754,22 +767,7 @@ IdlInterface.prototype.test_self = function()

var constructors = this.extAttrs
.filter(function(attr) { return attr.name == "Constructor"; });
var expected_length;
if (!constructors.length) {
// "If the [Constructor] extended attribute, does not appear on
// the interface definition, then the value is 0."
expected_length = 0;
} else {
// "Otherwise, the value is determined as follows: . . .
// "Return the length of the shortest argument list of the
// entries in S."
expected_length = constructors.map(function(attr) {
return attr.arguments ? attr.arguments.filter(function(arg) {
return !arg.optional;
}).length : 0;
})
.reduce(function(m, n) { return Math.min(m, n); });
}
var expected_length = minOverloadLength(constructors);
assert_equals(self[this.name].length, expected_length, "wrong value for " + this.name + ".length");
}.bind(this), this.name + " interface object length");
}
Expand Down Expand Up @@ -1122,12 +1120,10 @@ IdlInterface.prototype.do_member_operation_asserts = function(memberHolderObject
// ". . .
// "Return the length of the shortest argument list of the
// entries in S."
//
// TODO: Doesn't handle overloading or variadic arguments.
assert_equals(memberHolderObject[member.name].length,
member.arguments.filter(function(arg) {
return !arg.optional;
}).length,
minOverloadLength(this.members.filter(function(m) {
return m.type == "operation" && m.name == member.name;
})),
"property has wrong .length");

// Make some suitable arguments
Expand Down

0 comments on commit e76f07a

Please sign in to comment.