Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DOMException cause #40881

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -38,13 +46,17 @@ 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() {
var ex = new DOMException("foo");
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() {
Expand All @@ -53,13 +65,17 @@ 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() {
var ex = new DOMException("bar", undefined);
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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 5 additions & 1 deletion webidl/idlharness.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" })']
});
}
);