Skip to content

Commit

Permalink
Test IsConstructor for all interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Apr 26, 2021
1 parent be3b9ca commit 943bb28
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions resources/idlharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ function globalOf(func)
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") {
Expand Down Expand Up @@ -1430,8 +1440,6 @@ IdlInterface.prototype.test_self = function()
{
subsetTestByKey(this.name, test, function()
{
// This function tests WebIDL as of 2015-01-13.

if (!this.should_have_interface_object()) {
return;
}
Expand Down Expand Up @@ -1473,8 +1481,6 @@ IdlInterface.prototype.test_self = function()

// "* 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."
Expand Down Expand Up @@ -1507,6 +1513,10 @@ IdlInterface.prototype.test_self = function()
"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();
Expand Down

0 comments on commit 943bb28

Please sign in to comment.