From 8230e56cbb0076cefa4c31c607e16278c171b1e5 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 26 Jan 2015 18:42:19 +0100 Subject: [PATCH 1/2] Remove IDLException. WebIDL no longer has support for arbitrary exception types. --- idlharness.js | 333 -------------------------------------------------- 1 file changed, 333 deletions(-) diff --git a/idlharness.js b/idlharness.js index fc2209b1472575..76a00df28be8ea 100644 --- a/idlharness.js +++ b/idlharness.js @@ -170,10 +170,6 @@ IdlArray.prototype.internal_add_idls = function(parsed_idls) new IdlInterface(parsed_idl, /* is_callback = */ false); break; - case "exception": - this.members[parsed_idl.name] = new IdlException(parsed_idl); - break; - case "dictionary": // Nothing to test, but we need the dictionary info around for type // checks @@ -599,335 +595,6 @@ IdlExceptionOrInterface.prototype.test = function() //@} -/// IdlException /// -function IdlException(obj) { IdlExceptionOrInterface.call(this, obj); } -IdlException.prototype = Object.create(IdlExceptionOrInterface.prototype); -IdlException.prototype.test_self = function() -//@{ -{ - test(function() - { - // "For every exception that is not declared with the - // [NoInterfaceObject] extended attribute, a corresponding property - // must exist on the exception’s relevant namespace object. The name of - // the property is the identifier of the exception, and its value is an - // object called the exception interface object, which provides access - // to any constants that have been associated with the exception. The - // property has the attributes { [[Writable]]: true, [[Enumerable]]: - // false, [[Configurable]]: true }." - assert_own_property(self, this.name, - "self does not have own property " + format_value(this.name)); - var desc = Object.getOwnPropertyDescriptor(self, this.name); - assert_false("get" in desc, "self's property " + format_value(this.name) + " has getter"); - assert_false("set" in desc, "self's property " + format_value(this.name) + " has setter"); - assert_true(desc.writable, "self's property " + format_value(this.name) + " is not writable"); - assert_false(desc.enumerable, "self's property " + format_value(this.name) + " is enumerable"); - assert_true(desc.configurable, "self's property " + format_value(this.name) + " is not configurable"); - - // "The exception interface object for a given exception must be a - // function object." - // "If an object is defined to be a function object, then it has - // characteristics as follows:" - // "Its [[Prototype]] internal property is the Function prototype - // object." - // Note: This doesn't match browsers as of December 2011, see - // http://www.w3.org/Bugs/Public/show_bug.cgi?id=14813 - assert_equals(Object.getPrototypeOf(self[this.name]), Function.prototype, - "prototype of self's property " + format_value(this.name) + " is not Function.prototype"); - // "Its [[Get]] internal property is set as described in ECMA-262 - // section 15.3.5.4." - // Not much to test for this. - // "Its [[Construct]] internal property is set as described in ECMA-262 - // section 13.2.2." - // Tested below. - // "Its [[HasInstance]] internal property is set as described in - // ECMA-262 section 15.3.5.3, unless otherwise specified." - // TODO - // "Its [[Class]] internal property is “Function”." - // String() returns something implementation-dependent, because it - // calls Function#toString. - assert_class_string(self[this.name], "Function", - "class string of " + this.name); - - // TODO: Test 4.9.1.1. Exception interface object [[Call]] method - // (which does not match browsers: - // http://www.w3.org/Bugs/Public/show_bug.cgi?id=14885) - }.bind(this), this.name + " exception: existence and properties of exception interface object"); - - test(function() - { - assert_own_property(self, this.name, - "self does not have own property " + format_value(this.name)); - - // "The exception interface object must also have a property named - // “prototype” with attributes { [[Writable]]: false, [[Enumerable]]: - // false, [[Configurable]]: false } whose value is an object called the - // exception interface prototype object. This object also provides - // access to the constants that are declared on the exception." - assert_own_property(self[this.name], "prototype", - 'exception "' + this.name + '" does not have own property "prototype"'); - var desc = Object.getOwnPropertyDescriptor(self[this.name], "prototype"); - assert_false("get" in desc, this.name + ".prototype has getter"); - assert_false("set" in desc, this.name + ".prototype has setter"); - assert_false(desc.writable, this.name + ".prototype is writable"); - assert_false(desc.enumerable, this.name + ".prototype is enumerable"); - assert_false(desc.configurable, this.name + ".prototype is configurable"); - - // "The exception interface prototype object for a given exception must - // have an internal [[Prototype]] property whose value is as follows: - // - // "If the exception is declared to inherit from another exception, - // then the value of the internal [[Prototype]] property is the - // exception interface prototype object for the inherited exception. - // "Otherwise, the exception is not declared to inherit from another - // exception. The value of the internal [[Prototype]] property is the - // Error prototype object ([ECMA-262], section 15.11.3.1)." - // - // Note: This doesn't match browsers as of December 2011, see - // https://www.w3.org/Bugs/Public/show_bug.cgi?id=14887. - var inherit_exception = this.base ? this.base : "Error"; - assert_own_property(self, inherit_exception, - 'should inherit from ' + inherit_exception + ', but self has no such property'); - assert_own_property(self[inherit_exception], "prototype", - 'should inherit from ' + inherit_exception + ', but that object has no "prototype" property'); - assert_equals(Object.getPrototypeOf(self[this.name].prototype), - self[inherit_exception].prototype, - 'prototype of ' + this.name + '.prototype is not ' + inherit_exception + '.prototype'); - - // "The class string of an exception interface prototype object is the - // concatenation of the exception’s identifier and the string - // “Prototype”." - assert_class_string(self[this.name].prototype, this.name + "Prototype", - "class string of " + this.name + ".prototype"); - // TODO: Test String(), based on ES definition of - // Error.prototype.toString? - }.bind(this), this.name + " exception: existence and properties of exception interface prototype object"); - - test(function() - { - assert_own_property(self, this.name, - "self does not have own property " + format_value(this.name)); - assert_own_property(self[this.name], "prototype", - 'interface "' + this.name + '" does not have own property "prototype"'); - - // "There must be a property named “name” on the exception interface - // prototype object with attributes { [[Writable]]: true, - // [[Enumerable]]: false, [[Configurable]]: true } and whose value is - // the identifier of the exception." - assert_own_property(self[this.name].prototype, "name", - 'prototype object does not have own property "name"'); - var desc = Object.getOwnPropertyDescriptor(self[this.name].prototype, "name"); - assert_false("get" in desc, this.name + ".prototype.name has getter"); - assert_false("set" in desc, this.name + ".prototype.name has setter"); - assert_true(desc.writable, this.name + ".prototype.name is not writable"); - assert_false(desc.enumerable, this.name + ".prototype.name is enumerable"); - assert_true(desc.configurable, this.name + ".prototype.name is not configurable"); - assert_equals(desc.value, this.name, this.name + ".prototype.name has incorrect value"); - }.bind(this), this.name + " exception: existence and properties of exception interface prototype object's \"name\" property"); - - test(function() - { - assert_own_property(self, this.name, - "self does not have own property " + format_value(this.name)); - assert_own_property(self[this.name], "prototype", - 'interface "' + this.name + '" does not have own property "prototype"'); - - // "If the [NoInterfaceObject] extended attribute was not specified on - // the exception, then there must also be a property named - // “constructor” on the exception interface prototype object with - // attributes { [[Writable]]: true, [[Enumerable]]: false, - // [[Configurable]]: true } and whose value is a reference to the - // exception interface object for the exception." - assert_own_property(self[this.name].prototype, "constructor", - this.name + '.prototype does not have own property "constructor"'); - var desc = Object.getOwnPropertyDescriptor(self[this.name].prototype, "constructor"); - assert_false("get" in desc, this.name + ".prototype.constructor has getter"); - assert_false("set" in desc, this.name + ".prototype.constructor has setter"); - assert_true(desc.writable, this.name + ".prototype.constructor is not writable"); - assert_false(desc.enumerable, this.name + ".prototype.constructor is enumerable"); - assert_true(desc.configurable, this.name + ".prototype.constructor in not configurable"); - assert_equals(self[this.name].prototype.constructor, self[this.name], - this.name + '.prototype.constructor is not the same object as ' + this.name); - }.bind(this), this.name + " exception: existence and properties of exception interface prototype object's \"constructor\" property"); -}; - -//@} -IdlException.prototype.test_members = function() -//@{ -{ - for (var i = 0; i < this.members.length; i++) - { - var member = this.members[i]; - if (member.untested) - { - continue; - } - if (member.type == "const" && member.name != "prototype") - { - test(function() - { - assert_own_property(self, this.name, - "self does not have own property " + format_value(this.name)); - - // "For each constant defined on the exception, there must be a - // corresponding property on the exception interface object, if - // it exists, if the identifier of the constant is not - // “prototype”." - assert_own_property(self[this.name], member.name); - // "The value of the property is the ECMAScript value that is - // equivalent to the constant’s IDL value, according to the - // rules in section 4.2 above." - assert_equals(self[this.name][member.name], constValue(member.value), - "property has wrong value"); - // "The property has attributes { [[Writable]]: false, - // [[Enumerable]]: true, [[Configurable]]: false }." - var desc = Object.getOwnPropertyDescriptor(self[this.name], member.name); - assert_false("get" in desc, "property has getter"); - assert_false("set" in desc, "property has setter"); - assert_false(desc.writable, "property is writable"); - assert_true(desc.enumerable, "property is not enumerable"); - assert_false(desc.configurable, "property is configurable"); - }.bind(this), this.name + " exception: constant " + member.name + " on exception interface object"); - // "In addition, a property with the same characteristics must - // exist on the exception interface prototype object." - test(function() - { - assert_own_property(self, this.name, - "self does not have own property " + format_value(this.name)); - assert_own_property(self[this.name], "prototype", - 'exception "' + this.name + '" does not have own property "prototype"'); - - assert_own_property(self[this.name].prototype, member.name); - assert_equals(self[this.name].prototype[member.name], constValue(member.value), - "property has wrong value"); - var desc = Object.getOwnPropertyDescriptor(self[this.name].prototype, member.name); - assert_false("get" in desc, "property has getter"); - assert_false("set" in desc, "property has setter"); - assert_false(desc.writable, "property is writable"); - assert_true(desc.enumerable, "property is not enumerable"); - assert_false(desc.configurable, "property is configurable"); - }.bind(this), this.name + " exception: constant " + member.name + " on exception interface prototype object"); - } - else if (member.type == "field") - { - test(function() - { - assert_own_property(self, this.name, - "self does not have own property " + format_value(this.name)); - assert_own_property(self[this.name], "prototype", - 'exception "' + this.name + '" does not have own property "prototype"'); - - // "For each exception field, there must be a corresponding - // property on the exception interface prototype object, whose - // characteristics are as follows: - // "The name of the property is the identifier of the exception - // field." - assert_own_property(self[this.name].prototype, member.name); - // "The property has attributes { [[Get]]: G, [[Enumerable]]: - // true, [[Configurable]]: true }, where G is the exception - // field getter, defined below." - var desc = Object.getOwnPropertyDescriptor(self[this.name].prototype, member.name); - assert_false("value" in desc, "property descriptor has value but is supposed to be accessor"); - assert_false("writable" in desc, 'property descriptor has "writable" field but is supposed to be accessor'); - // TODO: ES5 doesn't seem to say whether desc should have a - // .set property. - assert_true(desc.enumerable, "property is not enumerable"); - assert_true(desc.configurable, "property is not configurable"); - // "The exception field getter is a Function object whose - // behavior when invoked is as follows:" - assert_equals(typeof desc.get, "function", "typeof getter"); - // "The value of the Function object’s “length” property is the - // Number value 0." - // This test is before the TypeError tests so that it's easiest - // to see that Firefox 11a1 only fails one assert in this test. - assert_equals(desc.get.length, 0, "getter length"); - // "Let O be the result of calling ToObject on the this value. - // "If O is not a platform object representing an exception for - // the exception on which the exception field was declared, - // then throw a TypeError." - // TODO: Test on a platform object representing an exception. - assert_throws(new TypeError(), function() - { - self[this.name].prototype[member.name]; - }.bind(this), "getting property on prototype object must throw TypeError"); - assert_throws(new TypeError(), function() - { - desc.get.call({}); - }.bind(this), "calling getter on wrong object type must throw TypeError"); - }.bind(this), this.name + " exception: field " + member.name + " on exception interface prototype object"); - } - } -}; - -//@} -IdlException.prototype.test_object = function(desc) -//@{ -{ - var obj, exception = null; - try - { - obj = eval(desc); - } - catch(e) - { - exception = e; - } - - test(function() - { - assert_equals(exception, null, "Unexpected exception when evaluating object"); - assert_equals(typeof obj, "object", "wrong typeof object"); - - // We can't easily test that its prototype is correct if there's no - // interface object, or the object is from a different global - // environment (not instanceof Object). TODO: test in this case that - // its prototype at least looks correct, even if we can't test that - // it's actually correct. - if (!this.has_extended_attribute("NoInterfaceObject") - && (typeof obj != "object" || obj instanceof Object)) - { - assert_own_property(self, this.name, - "self does not have own property " + format_value(this.name)); - assert_own_property(self[this.name], "prototype", - 'exception "' + this.name + '" does not have own property "prototype"'); - - // "The value of the internal [[Prototype]] property of the - // exception object must be the exception interface prototype - // object from the global environment the exception object is - // associated with." - assert_equals(Object.getPrototypeOf(obj), - self[this.name].prototype, - desc + "'s prototype is not " + this.name + ".prototype"); - } - - // "The class string of the exception object must be the identifier of - // the exception." - assert_class_string(obj, this.name, "class string of " + desc); - // Stringifier is not defined for DOMExceptions, because message isn't - // defined. - }.bind(this), this.name + " must be represented by " + desc); - - for (var i = 0; i < this.members.length; i++) - { - var member = this.members[i]; - test(function() - { - assert_equals(exception, null, "Unexpected exception when evaluating object"); - assert_equals(typeof obj, "object", "wrong typeof object"); - assert_inherits(obj, member.name); - if (member.type == "const") - { - assert_equals(obj[member.name], constValue(member.value)); - } - if (member.type == "field") - { - this.array.assert_type_is(obj[member.name], member.idlType); - } - }.bind(this), this.name + " exception: " + desc + ' must inherit property "' + member.name + '" with the proper type'); - } -}; -//@} - /// IdlInterface /// function IdlInterface(obj, is_callback) { IdlExceptionOrInterface.call(this, obj); From 78eaec52f2b551e920264ab6cacc7db7ee542048 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 23 Feb 2015 14:29:39 +0100 Subject: [PATCH 2/2] Collapse IdlExceptionOrInterface and IdlInterface. --- idlharness.js | 73 ++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/idlharness.js b/idlharness.js index 76a00df28be8ea..884daeae21616e 100644 --- a/idlharness.js +++ b/idlharness.js @@ -528,11 +528,8 @@ function IdlDictionary(obj) //@} IdlDictionary.prototype = Object.create(IdlObject.prototype); -/// IdlExceptionOrInterface /// -// Code sharing! -function IdlExceptionOrInterface(obj) -//@{ -{ +/// IdlInterface /// +function IdlInterface(obj, is_callback) { /** * obj is an object produced by the WebIDLParser.js "exception" or * "interface" production, as appropriate. @@ -562,46 +559,10 @@ function IdlExceptionOrInterface(obj) * none. */ this.base = obj.inheritance; -} - -//@} -IdlExceptionOrInterface.prototype = Object.create(IdlObject.prototype); -IdlExceptionOrInterface.prototype.test = function() -//@{ -{ - if (this.has_extended_attribute("NoInterfaceObject")) - { - // No tests to do without an instance. TODO: We should still be able - // to run tests on the prototype object, if we obtain one through some - // other means. - return; - } - - if (!this.untested) - { - // First test things to do with the exception/interface object and - // exception/interface prototype object. - this.test_self(); - } - // Then test things to do with its members (constants, fields, attributes, - // operations, . . .). These are run even if .untested is true, because - // members might themselves be marked as .untested. This might happen to - // interfaces if the interface itself is untested but a partial interface - // that extends it is tested -- then the interface itself and its initial - // members will be marked as untested, but the members added by the partial - // interface are still tested. - this.test_members(); -}; - -//@} - -/// IdlInterface /// -function IdlInterface(obj, is_callback) { - IdlExceptionOrInterface.call(this, obj); this._is_callback = is_callback; } -IdlInterface.prototype = Object.create(IdlExceptionOrInterface.prototype); +IdlInterface.prototype = Object.create(IdlObject.prototype); IdlInterface.prototype.is_callback = function() //@{ { @@ -628,6 +589,34 @@ IdlInterface.prototype.is_global = function() }; //@} +IdlInterface.prototype.test = function() +//@{ +{ + if (this.has_extended_attribute("NoInterfaceObject")) + { + // No tests to do without an instance. TODO: We should still be able + // to run tests on the prototype object, if we obtain one through some + // other means. + return; + } + + if (!this.untested) + { + // First test things to do with the exception/interface object and + // exception/interface prototype object. + this.test_self(); + } + // Then test things to do with its members (constants, fields, attributes, + // operations, . . .). These are run even if .untested is true, because + // members might themselves be marked as .untested. This might happen to + // interfaces if the interface itself is untested but a partial interface + // that extends it is tested -- then the interface itself and its initial + // members will be marked as untested, but the members added by the partial + // interface are still tested. + this.test_members(); +}; +//@} + IdlInterface.prototype.test_self = function() //@{ {