• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"use strict";
2
3test(() => {
4  assert_throws_js(TypeError, () => DOMException());
5}, "Cannot construct without new");
6
7test(() => {
8  assert_equals(Object.getPrototypeOf(DOMException.prototype), Error.prototype);
9}, "inherits from Error: prototype-side");
10
11test(() => {
12  assert_equals(Object.getPrototypeOf(DOMException), Function.prototype);
13}, "does not inherit from Error: class-side");
14
15test(() => {
16  const e = new DOMException("message", "name");
17  assert_false(e.hasOwnProperty("message"), "property is not own");
18
19  const propDesc = Object.getOwnPropertyDescriptor(DOMException.prototype, "message");
20  assert_equals(typeof propDesc.get, "function", "property descriptor is a getter");
21  assert_equals(propDesc.set, undefined, "property descriptor is not a setter");
22  assert_true(propDesc.enumerable, "property descriptor enumerable");
23  assert_true(propDesc.configurable, "property descriptor configurable");
24}, "message property descriptor");
25
26test(() => {
27  const getter = Object.getOwnPropertyDescriptor(DOMException.prototype, "message").get;
28
29  assert_throws_js(TypeError, () => getter.apply({}));
30}, "message getter performs brand checks (i.e. is not [LegacyLenientThis])");
31
32test(() => {
33  const e = new DOMException("message", "name");
34  assert_false(e.hasOwnProperty("name"), "property is not own");
35
36  const propDesc = Object.getOwnPropertyDescriptor(DOMException.prototype, "name");
37  assert_equals(typeof propDesc.get, "function", "property descriptor is a getter");
38  assert_equals(propDesc.set, undefined, "property descriptor is not a setter");
39  assert_true(propDesc.enumerable, "property descriptor enumerable");
40  assert_true(propDesc.configurable, "property descriptor configurable");
41}, "name property descriptor");
42
43test(() => {
44  const getter = Object.getOwnPropertyDescriptor(DOMException.prototype, "name").get;
45
46  assert_throws_js(TypeError, () => getter.apply({}));
47}, "name getter performs brand checks (i.e. is not [LegacyLenientThis])");
48
49test(() => {
50  const e = new DOMException("message", "name");
51  assert_false(e.hasOwnProperty("code"), "property is not own");
52
53  const propDesc = Object.getOwnPropertyDescriptor(DOMException.prototype, "code");
54  assert_equals(typeof propDesc.get, "function", "property descriptor is a getter");
55  assert_equals(propDesc.set, undefined, "property descriptor is not a setter");
56  assert_true(propDesc.enumerable, "property descriptor enumerable");
57  assert_true(propDesc.configurable, "property descriptor configurable");
58}, "code property descriptor");
59
60test(() => {
61  const getter = Object.getOwnPropertyDescriptor(DOMException.prototype, "code").get;
62
63  assert_throws_js(TypeError, () => getter.apply({}));
64}, "code getter performs brand checks (i.e. is not [LegacyLenientThis])");
65
66test(() => {
67  const e = new DOMException("message", "InvalidCharacterError");
68  assert_equals(e.code, 5, "Initially the code is set to 5");
69
70  Object.defineProperty(e, "name", {
71    value: "WrongDocumentError"
72  });
73
74  assert_equals(e.code, 5, "The code is still set to 5");
75}, "code property is not affected by shadowing the name property");
76
77test(() => {
78  const e = new DOMException("message", "name");
79  assert_equals(Object.prototype.toString.call(e), "[object DOMException]");
80}, "Object.prototype.toString behavior is like other interfaces");
81
82test(() => {
83  const e = new DOMException("message", "name");
84  assert_false(e.hasOwnProperty("toString"), "toString must not exist on the instance");
85  assert_false(DOMException.prototype.hasOwnProperty("toString"), "toString must not exist on DOMException.prototype");
86  assert_equals(typeof e.toString, "function", "toString must still exist (via Error.prototype)");
87}, "Inherits its toString() from Error.prototype");
88
89test(() => {
90  const e = new DOMException("message", "name");
91  assert_equals(e.toString(), "name: message",
92    "The default Error.prototype.toString() behavior must work on supplied name and message");
93
94  Object.defineProperty(e, "name", { value: "new name" });
95  Object.defineProperty(e, "message", { value: "new message" });
96  assert_equals(e.toString(), "new name: new message",
97    "The default Error.prototype.toString() behavior must work on shadowed names and messages");
98}, "toString() behavior from Error.prototype applies as expected");
99
100test(() => {
101  assert_throws_js(TypeError, () => DOMException.prototype.toString());
102}, "DOMException.prototype.toString() applied to DOMException.prototype throws because of name/message brand checks");
103
104test(() => {
105  let stackOnNormalErrors;
106  try {
107    throw new Error("normal error");
108  } catch (e) {
109    stackOnNormalErrors = e.stack;
110  }
111
112  let stackOnDOMException;
113  try {
114    throw new DOMException("message", "name");
115  } catch (e) {
116    stackOnDOMException = e.stack;
117  }
118
119  assert_equals(typeof stackOnDOMException, typeof stackOnNormalErrors, "The typeof values must match");
120}, "If the implementation has a stack property on normal errors, it also does on DOMExceptions");
121