Backed out changeset 713114c0331a (bug 1938707) by developer request CLOSED TREE
[gecko.git] / js / xpconnect / tests / chrome / test_inlineScripts.html
blobcb5f5ed530f340e2acbe0812b9da53ffca69bacf
1 <!DOCTYPE html>
2 <html>
3 <meta charset=utf-8>
4 <title>Tests for nsIScriptError</title>
5 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
6 <div id="log"></div>
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>
10 <script>
11 function waitForError (expectedMessage){
12 return new Promise(resolve => {
13 const listener = {
14 QueryInterface: ChromeUtils.generateQI(["nsIConsoleListener"])
17 listener.observe = function(message) {
18 if (message.message.includes(expectedMessage)) {
19 message.QueryInterface(Ci.nsIScriptError);
20 resolve(message);
21 Services.console.unregisterListener(listener);
25 Services.console.registerListener(listener);
26 });
29 var onInlineScriptError = waitForError("doThrow");
30 var onModuleError = waitForError("doThrowInModule");
31 SimpleTest.expectUncaughtException();
32 </script>
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>
35 <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");
51 });
52 </script>
53 </html>