From d9ac520941e79fec9e3cb9537c70005f166685ee Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 25 Dec 2015 02:54:44 +0100 Subject: [PATCH 1/3] Ignore static operations in test_interface_of Static operations aren't supposed to appear on platform interface instances, so there are no reason to have a "Foo interface: bar() must inherit property Qux" for them. --- idlharness.js | 54 +++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/idlharness.js b/idlharness.js index 02304ca..553a5ed 100644 --- a/idlharness.js +++ b/idlharness.js @@ -1410,7 +1410,7 @@ IdlInterface.prototype.test_interface_of = function(desc, obj, exception, expect }.bind(this), this.name + " interface: " + desc + ' must have own property "' + member.name + '"'); } else if ((member.type == "const" - || member.type == "attribute" + || member.type == "attribute" && !member["static"] || member.type == "operation") && member.name) { @@ -1418,41 +1418,39 @@ IdlInterface.prototype.test_interface_of = function(desc, obj, exception, expect { assert_equals(exception, null, "Unexpected exception when evaluating object"); assert_equals(typeof obj, expected_typeof, "wrong typeof object"); - if (!member["static"]) { - if (!this.is_global()) { - assert_inherits(obj, member.name); - } else { - assert_own_property(obj, member.name); - } + if (!this.is_global()) { + assert_inherits(obj, member.name); + } else { + assert_own_property(obj, member.name); + } - if (member.type == "const") + if (member.type == "const") + { + assert_equals(obj[member.name], constValue(member.value)); + } + if (member.type == "attribute") + { + // Attributes are accessor properties, so they might + // legitimately throw an exception rather than returning + // anything. + var property, thrown = false; + try { - assert_equals(obj[member.name], constValue(member.value)); + property = obj[member.name]; } - if (member.type == "attribute") + catch (e) { - // Attributes are accessor properties, so they might - // legitimately throw an exception rather than returning - // anything. - var property, thrown = false; - try - { - property = obj[member.name]; - } - catch (e) - { - thrown = true; - } - if (!thrown) - { - this.array.assert_type_is(property, member.idlType); - } + thrown = true; } - if (member.type == "operation") + if (!thrown) { - assert_equals(typeof obj[member.name], "function"); + this.array.assert_type_is(property, member.idlType); } } + if (member.type == "operation") + { + assert_equals(typeof obj[member.name], "function"); + } }.bind(this), this.name + " interface: " + desc + ' must inherit property "' + member.name + '" with the proper type (' + i + ')'); } // TODO: This is wrong if there are multiple operations with the same From 223ed19949a8aefbf627967125ccdb49113d5585 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 25 Dec 2015 03:05:07 +0100 Subject: [PATCH 2/3] Just check the absence of static operations on instances --- idlharness.js | 52 ++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/idlharness.js b/idlharness.js index 553a5ed..b15c755 100644 --- a/idlharness.js +++ b/idlharness.js @@ -1458,37 +1458,39 @@ IdlInterface.prototype.test_interface_of = function(desc, obj, exception, expect // TODO: Test passing arguments of the wrong type. if (member.type == "operation" && member.name && member.arguments.length) { - test(function() - { - assert_equals(exception, null, "Unexpected exception when evaluating object"); - assert_equals(typeof obj, expected_typeof, "wrong typeof object"); - if (!member["static"]) { + if (member["static"]) { + test(function() + { + assert_equals(exception, null, "Unexpected exception when evaluating object"); + assert_equals(typeof obj, expected_typeof, "wrong typeof object"); if (!this.is_global() && !member.isUnforgeable) { assert_inherits(obj, member.name); } else { assert_own_property(obj, member.name); } - } - else - { - assert_false(member.name in obj); - } - - var minLength = minOverloadLength(this.members.filter(function(m) { - return m.type == "operation" && m.name == member.name; - })); - var args = []; - for (var i = 0; i < minLength; i++) { - assert_throws(new TypeError(), function() - { - obj[member.name].apply(obj, args); - }.bind(this), "Called with " + i + " arguments"); - args.push(create_suitable_object(member.arguments[i].idlType)); - } - }.bind(this), this.name + " interface: calling " + member.name + - "(" + member.arguments.map(function(m) { return m.idlType.idlType; }) + - ") on " + desc + " with too few arguments must throw TypeError"); + var minLength = minOverloadLength(this.members.filter(function(m) { + return m.type == "operation" && m.name == member.name; + })); + var args = []; + for (var i = 0; i < minLength; i++) { + assert_throws(new TypeError(), function() + { + obj[member.name].apply(obj, args); + }.bind(this), "Called with " + i + " arguments"); + + args.push(create_suitable_object(member.arguments[i].idlType)); + } + }.bind(this), this.name + " interface: calling " + member.name + + "(" + member.arguments.map(function(m) { return m.idlType.idlType; }) + + ") on " + desc + " with too few arguments must throw TypeError"); + } else { + test(function() { + assert_equals(exception, null, "Unexpected exception when evaluating object"); + assert_equals(typeof obj, expected_typeof, "wrong typeof object"); + assert_false(member.name in obj); + }.bind(this), this.name + " interface: static operation " + member.name + " must not be a property on " + desc); + } } } }; From b4f83c818895adde3c8ce59a1011bb1e9e5bb08a Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 25 Dec 2015 03:29:57 +0100 Subject: [PATCH 3/3] Properly test instance properties for operations They might be overloaded and thus we should test them only once, instead of including the member's index in the test name to avoid dupes. --- idlharness.js | 124 +++++++++++++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 51 deletions(-) diff --git a/idlharness.js b/idlharness.js index b15c755..0c91d45 100644 --- a/idlharness.js +++ b/idlharness.js @@ -1381,6 +1381,10 @@ IdlInterface.prototype.test_primary_interface_of = function(desc, obj, exception IdlInterface.prototype.test_interface_of = function(desc, obj, exception, expected_typeof) //@{ { + // A map from operations' names to members, for tests that are only related to the + // instances' properties' descriptors. + var operations = {}; + // TODO: Indexed and named properties, more checks on interface members this.already_tested = true; @@ -1396,21 +1400,21 @@ IdlInterface.prototype.test_interface_of = function(desc, obj, exception, expect this.do_interface_attribute_asserts(obj, member); }.bind(this), this.name + " interface: " + desc + ' must have own property "' + member.name + '"'); } - else if (member.type == "operation" && - member.name && - member.isUnforgeable) - { - test(function() - { - assert_equals(exception, null, "Unexpected exception when evaluating object"); - assert_equals(typeof obj, expected_typeof, "wrong typeof object"); - assert_own_property(obj, member.name, - "Doesn't have the unforgeable operation property"); - this.do_member_operation_asserts(obj, member); - }.bind(this), this.name + " interface: " + desc + ' must have own property "' + member.name + '"'); + else if (member.type == "operation" && member.name) { + if (member.name in operations) { + if (operations[member.name].isUnforgeable != member.isUnforgeable) { + throw "All overloads of " + this.name + "." + member.name + " should be unforgeable or none of them."; + } + if (operations[member.name]["static"] != member["static"]) { + throw "All overloads of " + this.name + "." + member.name + "should be static or none of them."; + } + } else { + // We just take the first we find. This is safe because only their name, forgeableness + // and staticness are later used. + operations[member.name] = member; + } } else if ((member.type == "const" - || member.type == "attribute" && !member["static"] || member.type == "operation") && member.name) { @@ -1447,50 +1451,68 @@ IdlInterface.prototype.test_interface_of = function(desc, obj, exception, expect this.array.assert_type_is(property, member.idlType); } } - if (member.type == "operation") - { - assert_equals(typeof obj[member.name], "function"); - } - }.bind(this), this.name + " interface: " + desc + ' must inherit property "' + member.name + '" with the proper type (' + i + ')'); + }.bind(this), this.name + " interface: " + desc + ' must inherit property "' + member.name + '" with the proper type'); } // TODO: This is wrong if there are multiple operations with the same // identifier. // TODO: Test passing arguments of the wrong type. - if (member.type == "operation" && member.name && member.arguments.length) + if (member.type == "operation" && + !member["static"] && member.name && member.arguments.length) { - if (member["static"]) { - test(function() - { - assert_equals(exception, null, "Unexpected exception when evaluating object"); - assert_equals(typeof obj, expected_typeof, "wrong typeof object"); - if (!this.is_global() && !member.isUnforgeable) { - assert_inherits(obj, member.name); - } else { - assert_own_property(obj, member.name); - } + test(function() + { + assert_equals(exception, null, "Unexpected exception when evaluating object"); + assert_equals(typeof obj, expected_typeof, "wrong typeof object"); + if (!this.is_global() && !member.isUnforgeable) { + assert_inherits(obj, member.name); + } else { + assert_own_property(obj, member.name); + } - var minLength = minOverloadLength(this.members.filter(function(m) { - return m.type == "operation" && m.name == member.name; - })); - var args = []; - for (var i = 0; i < minLength; i++) { - assert_throws(new TypeError(), function() - { - obj[member.name].apply(obj, args); - }.bind(this), "Called with " + i + " arguments"); - - args.push(create_suitable_object(member.arguments[i].idlType)); - } - }.bind(this), this.name + " interface: calling " + member.name + - "(" + member.arguments.map(function(m) { return m.idlType.idlType; }) + - ") on " + desc + " with too few arguments must throw TypeError"); - } else { - test(function() { - assert_equals(exception, null, "Unexpected exception when evaluating object"); - assert_equals(typeof obj, expected_typeof, "wrong typeof object"); - assert_false(member.name in obj); - }.bind(this), this.name + " interface: static operation " + member.name + " must not be a property on " + desc); - } + var minLength = minOverloadLength(this.members.filter(function(m) { + return m.type == "operation" && m.name == member.name; + })); + var args = []; + for (var i = 0; i < minLength; i++) { + assert_throws(new TypeError(), function() + { + obj[member.name].apply(obj, args); + }.bind(this), "Called with " + i + " arguments"); + + args.push(create_suitable_object(member.arguments[i].idlType)); + } + }.bind(this), this.name + " interface: calling " + member.name + + "(" + member.arguments.map(function(m) { return m.idlType.idlType; }) + + ") on " + desc + " with too few arguments must throw TypeError"); + } + } + + for (var name in operations) { + if (operations[name].isUnforgeable) { + test(function() { + assert_equals(exception, null, "Unexpected exception when evaluating object"); + assert_equals(typeof obj, expected_typeof, "wrong typeof object"); + assert_own_property(obj, name, + "Doesn't have the unforgeable operation property"); + this.do_member_operation_asserts(obj, operations[name]); + }.bind(this), this.name + " interface: " + desc + ' must have own property "' + name + '"'); + } else if (operations[name]["static"]) { + test(function() { + assert_equals(exception, null, "Unexpected exception when evaluating object"); + assert_equals(typeof obj, expected_typeof, "wrong typeof object"); + assert_false(name in obj); + }.bind(this), this.name + " interface: static operation " + name + " must not be a property on " + desc); + } else { + test(function() { + assert_equals(exception, null, "Unexpected exception when evaluating object"); + assert_equals(typeof obj, expected_typeof, "wrong typeof object"); + if (!this.is_global()) { + assert_inherits(obj, member.name); + } else { + assert_own_property(obj, member.name); + } + assert_equals(typeof obj[member.name], "function"); + }.bind(this), this.name + " interface: " + desc + ' must inherit property "' + name + '" with the proper type'); } } };