3 <title>Tests for nsIScriptError
</title>
4 <script src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
7 function awaitScriptError(fun
) {
8 // Use setTimeout in order to prevent throwing from test frame
9 // and to have a clean stack frame.
12 return new Promise(resolve
=> {
14 QueryInterface
: ChromeUtils
.generateQI(["nsIObserver"]),
16 if (!(message
instanceof Ci
.nsIScriptError
)) {
20 Services
.console
.unregisterListener(observer
);
25 Services
.console
.registerListener(observer
);
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],
54 for (let test
of TESTS
) {
55 // First test as regular throw
56 SimpleTest
.expectUncaughtException();
57 let message
= await
awaitScriptError(function testName() {
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() {
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() {
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(() => {
83 hasExpectedProperties(message
, test
);
84 is(message
.isPromiseRejection
, true, "is a rejected promise");