summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Promise/dependent-promises.js
blob: d0e2bfa8e88ba7d60a02399b49b92ef507637dfb (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
// |reftest| skip-if(!xulRuntime.shell) -- needs Debugger

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

g.eval(`
var p = new Promise(() => {});
p.name = "p";
var q = p.then();
q.name = "q";
var r = p.then(null, () => {});
r.name = "r";
var s = Promise.all([p, q]);
s.name = "s";
var t = Promise.race([r, s]);
t.name = "t";
`);

function getDependentNames(promise) {
    return gw.makeDebuggeeValue(promise).promiseDependentPromises.map((p) => p.getOwnPropertyDescriptor('name').value);
}

function arraysEqual(arr1, arr2, msg) {
    assertEq(arr1.length, arr2.length, msg + ": length");
    for (var i = 0; i < arr1.length; ++i) {
        assertEq(arr1[i], arr2[i], msg + ": [" + i + "]");
    }
}

arraysEqual(getDependentNames(g.p), ["q", "r", "s"], "deps for p");
arraysEqual(getDependentNames(g.q), ["s"], "deps for q");
arraysEqual(getDependentNames(g.r), ["t"], "deps for r");
arraysEqual(getDependentNames(g.s), ["t"], "deps for s");

this.reportCompare && reportCompare(true,true);