diff --git a/webidl/ecmascript-binding/es-exceptions/DOMException-constructor-behavior.any.js b/webidl/ecmascript-binding/es-exceptions/DOMException-constructor-behavior.any.js index e9917af2287490..597ae861e48568 100644 --- a/webidl/ecmascript-binding/es-exceptions/DOMException-constructor-behavior.any.js +++ b/webidl/ecmascript-binding/es-exceptions/DOMException-constructor-behavior.any.js @@ -6,6 +6,8 @@ test(function() { "Not passing a name should end up with 'Error' as the name"); assert_equals(ex.message, "", "Not passing a message should end up with empty string as the message"); + assert_equals(ex.cause, undefined, + "Not passing a cause should end up with undefined as the cause"); }, 'new DOMException()'); test(function() { @@ -14,6 +16,8 @@ test(function() { "The name property should be inherited"); assert_false(ex.hasOwnProperty("message"), "The message property should be inherited"); + assert_false(ex.hasOwnProperty("cause"), + "The cause property should be inherited"); }, 'new DOMException(): inherited-ness'); test(function() { @@ -22,6 +26,8 @@ test(function() { "Not passing a name should end up with 'Error' as the name"); assert_equals(ex.message, "null", "Passing null as message should end up with stringified 'null' as the message"); + assert_equals(ex.cause, undefined, + "Not passing a cause should end up with undefined as the cause"); }, 'new DOMException(null)'); test(function() { @@ -30,6 +36,8 @@ test(function() { "Not passing a name should end up with 'Error' as the name"); assert_equals(ex.message, "", "Not passing a message should end up with empty string as the message"); + assert_equals(ex.cause, undefined, + "Not passing a cause should end up with undefined as the cause"); }, 'new DOMException(undefined)'); test(function() { @@ -38,6 +46,8 @@ test(function() { "The name property should be inherited"); assert_false(ex.hasOwnProperty("message"), "The message property should be inherited"); + assert_false(ex.hasOwnProperty("cause"), + "The cause property should be inherited"); }, 'new DOMException(undefined): inherited-ness'); test(function() { @@ -45,6 +55,8 @@ test(function() { assert_equals(ex.name, "Error", "Not passing a name should still end up with 'Error' as the name"); assert_equals(ex.message, "foo", "Should be using passed-in message"); + assert_equals(ex.cause, undefined, + "Not passing a cause should end up with undefined as the cause"); }, 'new DOMException("foo")'); test(function() { @@ -53,6 +65,8 @@ test(function() { "The name property should be inherited"); assert_false(ex.hasOwnProperty("message"), "The message property should be inherited"); + assert_false(ex.hasOwnProperty("cause"), + "The cause property should be inherited"); }, 'new DOMException("foo"): inherited-ness'); test(function() { @@ -60,6 +74,8 @@ test(function() { assert_equals(ex.name, "Error", "Passing undefined for name should end up with 'Error' as the name"); assert_equals(ex.message, "bar", "Should still be using passed-in message"); + assert_equals(ex.cause, undefined, + "Not passing a cause should end up with undefined as the cause"); }, 'new DOMException("bar", undefined)'); test(function() { @@ -68,6 +84,8 @@ test(function() { assert_equals(ex.message, "bar", "Should still be using passed-in message"); assert_equals(ex.code, DOMException.NOT_SUPPORTED_ERR, "Should have the right exception code"); + assert_equals(ex.cause, undefined, + "Not passing a cause should end up with undefined as the cause"); }, 'new DOMException("bar", "NotSupportedError")'); test(function() { @@ -76,6 +94,8 @@ test(function() { "The name property should be inherited"); assert_false(ex.hasOwnProperty("message"), "The message property should be inherited"); + assert_false(ex.hasOwnProperty("cause"), + "The cause property should be inherited"); }, 'new DOMException("bar", "NotSupportedError"): inherited-ness'); test(function() { @@ -84,8 +104,86 @@ test(function() { assert_equals(ex.message, "bar", "Should still be using passed-in message"); assert_equals(ex.code, 0, "Should have 0 for code for a name not in the exception names table"); + assert_equals(ex.cause, undefined, + "Not passing a cause should end up with undefined as the cause"); }, 'new DOMException("bar", "foo")'); +test(function() { + var ex = new DOMException("bar", {}); + assert_equals(ex.name, "Error", + "Passing empty dictionary for options should end up with 'Error' as the name"); + assert_equals(ex.message, "bar", "Should still be using passed-in message"); + assert_equals(ex.cause, undefined, + "Not passing a cause should end up with undefined as the cause"); +}, 'new DOMException("bar", {})'); + +test(function() { + var ex = new DOMException("bar", {}); + assert_false(ex.hasOwnProperty("name"), + "The name property should be inherited"); + assert_false(ex.hasOwnProperty("message"), + "The message property should be inherited"); + assert_false(ex.hasOwnProperty("cause"), + "The cause property should be inherited"); +}, 'new DOMException("bar", {}): inherited-ness'); + +test(function() { + var ex = new DOMException("bar", { name: "NotSupportedError" }); + assert_equals(ex.name, "NotSupportedError", "Should be using the passed-in name"); + assert_equals(ex.message, "bar", "Should still be using passed-in message"); + assert_equals(ex.code, DOMException.NOT_SUPPORTED_ERR, + "Should have the right exception code"); + assert_equals(ex.cause, undefined, + "Not passing a cause should end up with undefined as the cause"); +}, 'new DOMException("bar", { name: "NotSupportedError" })'); + +test(function() { + var ex = new DOMException("bar", { name: "NotSupportedError" }); + assert_false(ex.hasOwnProperty("name"), + "The name property should be inherited"); + assert_false(ex.hasOwnProperty("message"), + "The message property should be inherited"); + assert_false(ex.hasOwnProperty("cause"), + "The cause property should be inherited"); +}, 'new DOMException("bar", { name: "NotSupportedError" }): inherited-ness'); + +test(function() { + var ex = new DOMException("bar", { cause: "foo" }); + assert_equals(ex.name, "Error", + "Not passing a name should end up with 'Error' as the name"); + assert_equals(ex.message, "bar", "Should still be using passed-in message"); + assert_equals(ex.cause, "foo", "Should be using the passed-in cause"); +}, 'new DOMException("bar", { cause: "foo" })'); + +test(function() { + var ex = new DOMException("bar", { cause: "foo" }); + assert_false(ex.hasOwnProperty("name"), + "The name property should be inherited"); + assert_false(ex.hasOwnProperty("message"), + "The message property should be inherited"); + assert_false(ex.hasOwnProperty("cause"), + "The cause property should be inherited"); +}, 'new DOMException("bar", { cause: "foo" }): inherited-ness'); + +test(function() { + var ex = new DOMException("bar", { name: "NotSupportedError", cause: "foo" }); + assert_equals(ex.name, "NotSupportedError", "Should be using the passed-in name"); + assert_equals(ex.message, "bar", "Should still be using passed-in message"); + assert_equals(ex.code, DOMException.NOT_SUPPORTED_ERR, + "Should have the right exception code"); + assert_equals(ex.cause, "foo", "Should be using the passed-in cause"); +}, 'new DOMException("bar", { name: "NotSupportedError", cause: "foo" })'); + +test(function() { + var ex = new DOMException("bar", { name: "NotSupportedError", cause: "foo" }); + assert_false(ex.hasOwnProperty("name"), + "The name property should be inherited"); + assert_false(ex.hasOwnProperty("message"), + "The message property should be inherited"); + assert_false(ex.hasOwnProperty("cause"), + "The cause property should be inherited"); +}, 'new DOMException("bar", { name: "NotSupportedError", cause: "foo" }): inherited-ness'); + [ {name: "IndexSizeError", code: 1}, {name: "HierarchyRequestError", code: 3}, diff --git a/webidl/ecmascript-binding/es-exceptions/DOMException-custom-bindings.any.js b/webidl/ecmascript-binding/es-exceptions/DOMException-custom-bindings.any.js index cd4e5b6341948c..13cfaa35ea8f9a 100644 --- a/webidl/ecmascript-binding/es-exceptions/DOMException-custom-bindings.any.js +++ b/webidl/ecmascript-binding/es-exceptions/DOMException-custom-bindings.any.js @@ -46,6 +46,23 @@ test(() => { assert_throws_js(TypeError, () => getter.apply({})); }, "name getter performs brand checks (i.e. is not [LegacyLenientThis])"); +test(() => { + const e = new DOMException("message", { cause: "cause" }); + assert_false(e.hasOwnProperty("cause"), "property is not own"); + + const propDesc = Object.getOwnPropertyDescriptor(DOMException.prototype, "cause"); + assert_equals(typeof propDesc.get, "function", "property descriptor is a getter"); + assert_equals(propDesc.set, undefined, "property descriptor is not a setter"); + assert_true(propDesc.enumerable, "property descriptor enumerable"); + assert_true(propDesc.configurable, "property descriptor configurable"); +}, "cause property descriptor"); + +test(() => { + const getter = Object.getOwnPropertyDescriptor(DOMException.prototype, "cause").get; + + assert_throws_js(TypeError, () => getter.apply({})); +}, "cause getter performs brand checks (i.e. is not [LegacyLenientThis])"); + test(() => { const e = new DOMException("message", "name"); assert_false(e.hasOwnProperty("code"), "property is not own"); diff --git a/webidl/idlharness.any.js b/webidl/idlharness.any.js index 3c662ba8e63f2f..b361f76f0103f9 100644 --- a/webidl/idlharness.any.js +++ b/webidl/idlharness.any.js @@ -10,7 +10,11 @@ idl_test( idl_array.add_objects({ DOMException: ['new DOMException()', 'new DOMException("my message")', - 'new DOMException("my message", "myName")'] + 'new DOMException("my message", "myName")', + 'new DOMException("my message", {})', + 'new DOMException("my message", { name: "myName" })', + 'new DOMException("my message", { cause: "myCause" })', + 'new DOMException("my message", { name: "myName", cause: "myCause" })'] }); } );