Test IsConstructor for all interfaces
Part of https://github.com/heycam/webidl/issues/698.
diff --git a/resources/idlharness.js b/resources/idlharness.js
index eda7325..f110993 100644
--- a/resources/idlharness.js
+++ b/resources/idlharness.js
@@ -101,6 +101,16 @@
return self;
}
+// https://esdiscuss.org/topic/isconstructor#content-11
+function isConstructor(o) {
+ try {
+ new (new Proxy(o, {construct: () => ({})}));
+ return true;
+ } catch(e) {
+ return false;
+ }
+}
+
function throwOrReject(a_test, operation, fn, obj, args, message, cb)
{
if (operation.idlType.generic !== "Promise") {
@@ -1430,8 +1440,6 @@
{
subsetTestByKey(this.name, test, function()
{
- // This function tests WebIDL as of 2015-01-13.
-
if (!this.should_have_interface_object()) {
return;
}
@@ -1473,8 +1481,6 @@
// "* Its [[Construct]] internal property is set as described in
// ECMA-262 section 19.2.2.3."
- // Tested below if no constructor is defined. TODO: test constructors
- // if defined.
// "* Its @@hasInstance property is set as described in ECMA-262
// section 19.2.3.8, unless otherwise specified."
@@ -1507,6 +1513,10 @@
"prototype of self's property " + format_value(this.name) + " is not Function.prototype");
}
+ // Always test for [[Construct]]:
+ // https://github.com/heycam/webidl/issues/698
+ assert_true(isConstructor(this.get_interface_object()), "interface object must pass IsConstructor check");
+
if (!this.constructors().length) {
// "If I was not declared with a constructor operation, then throw a TypeError."
var interface_object = this.get_interface_object();