Test all Web IDL constructors throw if called as regular functions
diff --git a/resources/idlharness.js b/resources/idlharness.js
index b5eed06..b3fe803 100644
--- a/resources/idlharness.js
+++ b/resources/idlharness.js
@@ -1529,12 +1529,12 @@
// https://github.com/heycam/webidl/issues/698
assert_true(isConstructor(this.get_interface_object()), "interface object must pass IsConstructor check");
+ var interface_object = this.get_interface_object();
+ assert_throws_js(globalOf(interface_object).TypeError, function() {
+ interface_object();
+ }, "interface object didn't throw TypeError when called as a function");
+
if (!this.constructors().length) {
- // "If I was not declared with a constructor operation, then throw a TypeError."
- var interface_object = this.get_interface_object();
- assert_throws_js(globalOf(interface_object).TypeError, function() {
- interface_object();
- }, "interface object didn't throw TypeError when called as a function");
assert_throws_js(globalOf(interface_object).TypeError, function() {
new interface_object();
}, "interface object didn't throw TypeError when called as a constructor");
diff --git a/resources/test/tests/functional/idlharness/IdlInterface/test_exposed_wildcard.html b/resources/test/tests/functional/idlharness/IdlInterface/test_exposed_wildcard.html
index 82e6dc6..addc0eb 100644
--- a/resources/test/tests/functional/idlharness/IdlInterface/test_exposed_wildcard.html
+++ b/resources/test/tests/functional/idlharness/IdlInterface/test_exposed_wildcard.html
@@ -90,7 +90,7 @@
{
"name": "A interface: existence and properties of interface object",
"properties": {},
- "message": "assert_throws_js: interface object didn't throw TypeError when called as a function function \"function() {\n interface_object();\n }\" did not throw",
+ "message": "assert_throws_js: interface object didn't throw TypeError when called as a function function \"function() {\n interface_object();\n }\" did not throw",
"status_string": "FAIL"
},
{
@@ -132,7 +132,7 @@
{
"name": "C interface: existence and properties of interface object",
"properties": {},
- "message": "assert_throws_js: interface object didn't throw TypeError when called as a function function \"function() {\n interface_object();\n }\" did not throw",
+ "message": "assert_throws_js: interface object didn't throw TypeError when called as a function function \"function() {\n interface_object();\n }\" did not throw",
"status_string": "FAIL"
},
{
@@ -168,7 +168,7 @@
{
"name": "D interface: existence and properties of interface object",
"properties": {},
- "message": "assert_throws_js: interface object didn't throw TypeError when called as a function function \"function() {\n interface_object();\n }\" did not throw",
+ "message": "assert_throws_js: interface object didn't throw TypeError when called as a function function \"function() {\n interface_object();\n }\" did not throw",
"status_string": "FAIL"
},
{
diff --git a/resources/test/tests/functional/idlharness/IdlInterface/test_immutable_prototype.html b/resources/test/tests/functional/idlharness/IdlInterface/test_immutable_prototype.html
index 2c87e9b..5fe0591 100644
--- a/resources/test/tests/functional/idlharness/IdlInterface/test_immutable_prototype.html
+++ b/resources/test/tests/functional/idlharness/IdlInterface/test_immutable_prototype.html
@@ -16,7 +16,11 @@
enumerable: false,
writable: true,
configurable: true,
- value: function Foo() {}
+ value: function Foo() {
+ if (!new.target) {
+ throw new TypeError('Foo() must be called with new');
+ }
+ }
});
Object.defineProperty(window.Foo, "prototype", {
writable: false,
diff --git a/resources/test/tests/functional/idlharness/IdlInterface/test_primary_interface_of.html b/resources/test/tests/functional/idlharness/IdlInterface/test_primary_interface_of.html
index 6dc2b04..309de60 100644
--- a/resources/test/tests/functional/idlharness/IdlInterface/test_primary_interface_of.html
+++ b/resources/test/tests/functional/idlharness/IdlInterface/test_primary_interface_of.html
@@ -14,12 +14,20 @@
<script>
"use strict";
-function FooParent() {}
+function FooParent() {
+ if (!new.target) {
+ throw new TypeError('FooParent() must be called with new');
+ }
+}
Object.defineProperty(window, "Foo", {
enumerable: false,
writable: true,
configurable: true,
- value: function Foo() {}
+ value: function Foo() {
+ if (!new.target) {
+ throw new TypeError('Foo() must be called with new');
+ }
+ }
});
Object.defineProperty(window.Foo, "prototype", {
writable: false,