summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Promise/promise-rejection-tracking-optimized.js
blob: c085b9dba87281f4f06202083bd1386182d7aa22 (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
// |reftest| skip-if(!xulRuntime.shell) -- needs setPromiseRejectionTrackerCallback

const UNHANDLED = 0;
const HANDLED   = 1;

let rejections = new Map();
function rejectionTracker(promise, state) {
  rejections.set(promise, state);
}
setPromiseRejectionTrackerCallback(rejectionTracker);

// If the return value of then is not used, the promise object is optimized
// away, but if a rejection happens, the rejection should be notified.
Promise.resolve().then(() => { throw 1; });
drainJobQueue();

assertEq(rejections.size, 1);

let [[promise, state]] = rejections;
assertEq(state, UNHANDLED);

let exc;
promise.catch(x => { exc = x; });
drainJobQueue();

// we handled it after all
assertEq(rejections.get(promise), HANDLED);

// the right exception was reported
assertEq(exc, 1);

if (this.reportCompare) {
  reportCompare(true,true);
}