summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Object-getPromiseReactions-02.js
blob: 9922dd33892ee0be3cbd7686f305f401980a9ccc (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Debugger.Object.protoype.getPromiseReactions reports directly resolved promises.

load(libdir + 'array-compare.js');

var g = newGlobal({ newCompartment: true });
var dbg = new Debugger;
var DOg = dbg.addDebuggee(g);

g.eval(`
    var pResolve, pReject;
    var p = new Promise((resolve, reject) => { pResolve = resolve; pReject = reject });
    var p2 = new Promise((resolve, reject) => { resolve(p); });
    var p3 = new Promise((resolve, reject) => { resolve(p); });
    var p4 = new Promise((resolve, reject) => { resolve(p2); });
`);

var [DOp, DOp2, DOp3, DOp4] = [g.p, g.p2, g.p3, g.p4].map(p => DOg.makeDebuggeeValue(p));

// Since the standard resolving functions enqueue a job to do the `then` call,
// none of the reactions should be visible yet.
assertEq(true, arraysEqual(DOp.getPromiseReactions(), []));
assertEq(true, arraysEqual(DOp2.getPromiseReactions(), []));
assertEq(true, arraysEqual(DOp3.getPromiseReactions(), []));
assertEq(true, arraysEqual(DOp4.getPromiseReactions(), []));

// This should let them all appear in place.
drainJobQueue();

assertEq(true, arraysEqual(DOp.getPromiseReactions(), [DOp2, DOp3]));
assertEq(true, arraysEqual(DOp2.getPromiseReactions(), [DOp4]));
assertEq(true, arraysEqual(DOp3.getPromiseReactions(), []));
assertEq(true, arraysEqual(DOp4.getPromiseReactions(), []));

// Resolving the initial promise should kick off its reactions, but propagating
// that the rest of the way requires microtasks.
g.pResolve(42);

assertEq(true, arraysEqual(DOp.getPromiseReactions(), []));
assertEq(true, arraysEqual(DOp2.getPromiseReactions(), [DOp4]));
assertEq(true, arraysEqual(DOp3.getPromiseReactions(), []));
assertEq(true, arraysEqual(DOp4.getPromiseReactions(), []));

// Let the propagation complete.
drainJobQueue();

assertEq(true, arraysEqual(DOp.getPromiseReactions(), []));
assertEq(true, arraysEqual(DOp2.getPromiseReactions(), []));
assertEq(true, arraysEqual(DOp3.getPromiseReactions(), []));
assertEq(true, arraysEqual(DOp4.getPromiseReactions(), []));