4 <title>Tests for nsIScriptError
</title>
5 <script src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
8 <!-- Verify that column is correct, even for inline scripts with HTML on the same line -->
9 <span>some html
</span> <script>var inlineScriptStack
= new Error().stack
;</script>
11 function waitForError (expectedMessage
){
12 return new Promise(resolve
=> {
14 QueryInterface
: ChromeUtils
.generateQI(["nsIConsoleListener"])
17 listener
.observe = function(message
) {
18 if (message
.message
.includes(expectedMessage
)) {
19 message
.QueryInterface(Ci
.nsIScriptError
);
21 Services
.console
.unregisterListener(listener
);
25 Services
.console
.registerListener(listener
);
29 var onInlineScriptError
= waitForError("doThrow");
30 var onModuleError
= waitForError("doThrowInModule");
31 SimpleTest
.expectUncaughtException();
33 <span>some more html
</span><script>doThrow() // eslint-disable-line no-undef</script>
34 <script
>var b
;</script><hr><script type=
"module">SimpleTest.expectUncaughtException();doThrowInModule() // eslint-disable-line no-undef
</script>
36 add_task(async () => {
37 info("Check line and column information in Error#stack");
38 const { groups
} = inlineScriptStack
.match(/(?<line>\d+):(?<column>\d+)/);
39 is(groups
.line
, "9", "line of Error#stack in inline script is correct");
40 is(groups
.column
, "58", "column of Error#stack in inline script is correct");
42 info("Check line and column information Error message in inline script");
43 const errorMessage
= await onInlineScriptError
;
44 is(errorMessage
.lineNumber
, 33, "The exception line is correct");
45 is(errorMessage
.columnNumber
, 38, "The exception column is correct");
47 info("Check line and column information Error message in inline module");
48 const errorMessageInModule
= await onModuleError
;
49 is(errorMessageInModule
.lineNumber
, 34, "The module exception line is correct");
50 is(errorMessageInModule
.columnNumber
, 89, "The module exception column is correct");