summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Promise/any-stack.js
blob: dacb9e7f736011e1cf7793d2b150877882fe3997 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// |reftest| skip-if(!xulRuntime.shell) -- needs async stack capture

function toMessage(stack) {
  // Provide the stack string in the error message for debugging.
  return `[stack: ${stack.replace(/\n/g, "\\n")}]`;
}

// Test when AggregateError isn't created from a Promise Job.
{
  let p = Promise.any([]); // line 10

  p.then(v => {
    reportCompare(0, 1, "expected error");
  }, e => {
    assertEq(e.name, "AggregateError");
    var {stack} = e;

    assertEq(/^@.+any-stack.js:10/m.test(stack), true, toMessage(stack));
  });
}

// Same as above, but now with surrounding function context.
function testNoJobQueue() {
  let p = Promise.any([]); // line 24

  p.then(v => {
    reportCompare(0, 1, "expected error");
  }, e => {
    assertEq(e.name, "AggregateError");
    var {stack} = e;

    assertEq(/^testNoJobQueue@.+any-stack.js:24/m.test(stack), true, toMessage(stack));
  });
}
testNoJobQueue();

// Test when AggregateError is created from a Promise Job.
{
  let rejected = Promise.reject(0);
  let p = Promise.any([rejected]); // line 40

  p.then(v => {
    reportCompare(0, 1, "expected error");
  }, e => {
    assertEq(e.name, "AggregateError");
    var {stack} = e;

    assertEq(/^Promise.any\*@.+any-stack.js:40/m.test(stack), true, toMessage(stack));
  });
}

// Same as above, but now with surrounding function context.
function testFromJobQueue() {
  let rejected = Promise.reject(0);
  let p = Promise.any([rejected]); // line 55

  p.then(v => {
    reportCompare(0, 1, "expected error");
  }, e => {
    assertEq(e.name, "AggregateError");
    var {stack} = e;

    assertEq(/^Promise.any\*testFromJobQueue@.+any-stack.js:55/m.test(stack), true, toMessage(stack));
  });
}
testFromJobQueue();

if (typeof reportCompare === "function")
  reportCompare(0, 0);