summaryrefslogtreecommitdiffstats
path: root/dom/bindings/test/test_exception_options_from_jsimplemented.html
blob: 8a98a8fb63d5cd6fcb0e81a6ae449719b03685ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1107592
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1107592</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script type="application/javascript">

  /** Test for Bug 1107592 **/

  SimpleTest.waitForExplicitFinish();

  function doTest() {
    var file = location.href;
    var asyncFrame;
    /* Async parent frames from pushPrefEnv don't show up in e10s.  */
    var isE10S = !SpecialPowers.isMainProcess();
    if (!isE10S && SpecialPowers.getBoolPref("javascript.options.asyncstack")) {
      asyncFrame = `Async*@${file}:153:3
`;
    } else {
      asyncFrame = "";
    }

    var t = new TestInterfaceJS();
    try {
      t.testThrowError();
    } catch (e) {
      ok(e instanceof Error, "Should have an Error here");
      ok(!(e instanceof DOMException), "Should not have DOMException here");
      ok(!("code" in e), "Should not have a 'code' property");
      is(e.name, "Error", "Should not have an interesting name here");
      is(e.message, "We are an Error", "Should have the right message");
      is(e.stack,
         `doTest@${file}:31:7
${asyncFrame}`,
         "Exception stack should still only show our code");
      is(e.fileName,
         file,
         "Should have the right file name");
      is(e.lineNumber, 31, "Should have the right line number");
      is(e.columnNumber, 7, "Should have the right column number");
    }

    try {
      t.testThrowDOMException();
    } catch (e) {
      ok(e instanceof Error, "Should also have an Error here");
      ok(e instanceof DOMException, "Should have DOMException here");
      is(e.name, "NotSupportedError", "Should have the right name here");
      is(e.message, "We are a DOMException",
         "Should also have the right message");
      is(e.code, DOMException.NOT_SUPPORTED_ERR,
         "Should have the right 'code'");
      is(e.stack,
         `doTest@${file}:50:7
${asyncFrame}`,
         "Exception stack should still only show our code");
      is(e.filename,
         file,
         "Should still have the right file name");
      is(e.lineNumber, 50, "Should still have the right line number");
      todo_isnot(e.columnNumber, 0,
                 "No column number support for DOMException yet");
    }

    try {
      t.testThrowTypeError();
    } catch (e) {
      ok(e instanceof TypeError, "Should have a TypeError here");
      ok(!(e instanceof DOMException), "Should not have DOMException here (2)");
      ok(!("code" in e), "Should not have a 'code' property (2)");
      is(e.name, "TypeError", "Should be named TypeError");
      is(e.message, "We are a TypeError",
         "Should also have the right message (2)");
      is(e.stack,
         `doTest@${file}:72:7
${asyncFrame}`,
         "Exception stack for TypeError should only show our code");
      is(e.fileName,
         file,
         "Should still have the right file name for TypeError");
      is(e.lineNumber, 72, "Should still have the right line number for TypeError");
      is(e.columnNumber, 7, "Should have the right column number for TypeError");
    }

    try {
      t.testThrowCallbackError(function() { Array.indexOf() });
    } catch (e) {
      ok(e instanceof TypeError, "Should have a TypeError here (3)");
      ok(!(e instanceof DOMException), "Should not have DOMException here (3)");
      ok(!("code" in e), "Should not have a 'code' property (3)");
      is(e.name, "TypeError", "Should be named TypeError (3)");
      is(e.message, "missing argument 0 when calling function Array.indexOf",
         "Should also have the right message (3)");
      is(e.stack,
         `doTest/<@${file}:92:45
doTest@${file}:92:7
${asyncFrame}`,
         "Exception stack for TypeError should only show our code (3)");
      is(e.fileName,
         file,
         "Should still have the right file name for TypeError (3)");
      is(e.lineNumber, 92, "Should still have the right line number for TypeError (3)");
      is(e.columnNumber, 45, "Should have the right column number for TypeError (3)");
    }

    try {
      t.testThrowXraySelfHosted();
    } catch (e) {
      ok(!(e instanceof Error), "Should have an Exception here (4)");
      ok(!(e instanceof DOMException), "Should not have DOMException here (4)");
      ok(!("code" in e), "Should not have a 'code' property (4)");
      is(e.name, "NS_ERROR_UNEXPECTED", "Name should be sanitized (4)");
      is(e.message, "", "Message should be sanitized (5)");
      is(e.stack,
         `doTest@${file}:113:7
${asyncFrame}`,
         "Exception stack for sanitized exception should only show our code (4)");
      is(e.filename,
         file,
         "Should still have the right file name for sanitized exception (4)");
      is(e.lineNumber, 113, "Should still have the right line number for sanitized exception (4)");
      todo_isnot(e.columnNumber, 0, "Should have the right column number for sanitized exception (4)");
    }

    try {
      t.testThrowSelfHosted();
    } catch (e) {
      ok(!(e instanceof Error), "Should have an Exception here (5)");
      ok(!(e instanceof DOMException), "Should not have DOMException here (5)");
      ok(!("code" in e), "Should not have a 'code' property (5)");
      is(e.name, "NS_ERROR_UNEXPECTED", "Name should be sanitized (5)");
      is(e.message, "", "Message should be sanitized (5)");
      is(e.stack,
         `doTest@${file}:132:7
${asyncFrame}`,
         "Exception stack for sanitized exception should only show our code (5)");
      is(e.filename,
         file,
         "Should still have the right file name for sanitized exception (5)");
      is(e.lineNumber, 132, "Should still have the right line number for sanitized exception (5)");
      todo_isnot(e.columnNumber, 0, "Should have the right column number for sanitized exception (5)");
    }

    SimpleTest.finish();
  }

  SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]},
                            doTest);
  </script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1107592">Mozilla Bug 1107592</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
</pre>
</body>
</html>