Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / js / xpconnect / tests / chrome / test_scripterror.html
blob38cb3164677b01698a1697a0d8777ccbbebb28b2
1 <!DOCTYPE html>
2 <meta charset=utf-8>
3 <title>Tests for nsIScriptError</title>
4 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
5 <div id="log"></div>
6 <script>
7 function awaitScriptError(fun) {
8 // Use setTimeout in order to prevent throwing from test frame
9 // and to have a clean stack frame.
10 setTimeout(fun, 0)
12 return new Promise(resolve => {
13 const observer = {
14 QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
15 observe(message) {
16 if (!(message instanceof Ci.nsIScriptError)) {
17 return;
20 Services.console.unregisterListener(observer);
21 resolve(message);
25 Services.console.registerListener(observer);
26 });
29 function hasExpectedProperties(message, exception) {
30 is(message.hasException, true, "has exception");
31 is(message.exception, exception, "has correct exception");
33 ok(message.stack != null, "has stack");
34 is(message.stack?.source, location.href, "correct stack source")
36 is(message.sourceName, location.href, "has correct sourceName/filename");
37 ok(message.lineNumber > 0, "has lineNumber");
39 is(message.innerWindowID, window.windowGlobalChild.innerWindowId,
40 "correct innerWindowID");
43 add_task(async () => {
44 await SpecialPowers.pushPrefEnv({"set": [
45 ["javascript.options.asyncstack_capture_debuggee_only", false],
46 ]});
48 const TESTS = [
49 "abc",
50 new Error("foobar"),
51 {foo: "bar"}
54 for (let test of TESTS) {
55 // First test as regular throw
56 SimpleTest.expectUncaughtException();
57 let message = await awaitScriptError(function testName() {
58 throw test;
59 });
60 hasExpectedProperties(message, test);
61 is(message.isPromiseRejection, false, "not a rejected promise");
63 // Now test as uncaught promise rejection
64 message = await awaitScriptError(function testName() {
65 Promise.reject(test);
66 });
67 hasExpectedProperties(message, test);
68 is(message.isPromiseRejection, true, "is a rejected promise");
70 // Uncaught rejection from async function
71 message = await awaitScriptError(async function testName() {
72 throw test;
73 });
74 hasExpectedProperties(message, test);
75 is(message.isPromiseRejection, true, "is a rejected promise");
77 // Uncaught rejection from then callback
78 message = await awaitScriptError(async function testName() {
79 Promise.resolve().then(() => {
80 throw test;
81 });
82 });
83 hasExpectedProperties(message, test);
84 is(message.isPromiseRejection, true, "is a rejected promise");
86 });
87 </script>