summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/xpcshell/test_stepping-12.js
blob: de96faf59fefd1cd7f40ccc839b65dc3f9422664 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Check that step out stops at the parent and the parent's parent.
 * This checks for the failure found in bug 1530549.
 */

const sourceUrl = "test_stepping-10-test-code.js";

add_task(
  threadFrontTest(async args => {
    dumpn("Evaluating test code and waiting for first debugger statement");

    await testGenerator(args);
    await testAwait(args);
    await testInterleaving(args);
    await testMultipleSteps(args);
  })
);

async function testAwait({ threadFront, debuggee }) {
  function evaluateTestCode() {
    Cu.evalInSandbox(
      `
        (async function() {
          debugger;
          r = await Promise.resolve('yay');
          a = 4;
        })();
      `,
      debuggee,
      "1.8",
      sourceUrl,
      1
    );
  }

  await executeOnNextTickAndWaitForPause(evaluateTestCode, threadFront);

  dumpn("Step Over and land on line 5");
  const step1 = await stepOver(threadFront);
  equal(step1.frame.where.line, 4);
  equal(step1.frame.where.column, 10);

  const step2 = await stepOver(threadFront);
  equal(step2.frame.where.line, 5);
  equal(step2.frame.where.column, 10);
  equal(debuggee.r, "yay");
  await resume(threadFront);
}

async function testInterleaving({ threadFront, debuggee }) {
  function evaluateTestCode() {
    Cu.evalInSandbox(
      `
        (async function simpleRace() {
          debugger;
          this.result = await new Promise((r) => {
            Promise.resolve().then(() => { debugger });
            Promise.resolve().then(r('yay'))
          })
          var a = 2;
          debugger;
        })()
      `,
      debuggee,
      "1.8",
      sourceUrl,
      1
    );
  }

  await executeOnNextTickAndWaitForPause(evaluateTestCode, threadFront);

  dumpn("Step Over and land on line 5");
  const step1 = await stepOver(threadFront);
  equal(step1.frame.where.line, 4);

  const step2 = await stepOver(threadFront);
  equal(step2.frame.where.line, 5);
  equal(step2.frame.where.column, 43);

  const step3 = await resumeAndWaitForPause(threadFront);
  equal(step3.frame.where.line, 9);
  equal(debuggee.result, "yay");

  await resume(threadFront);
}

async function testMultipleSteps({ threadFront, debuggee }) {
  function evaluateTestCode() {
    Cu.evalInSandbox(
      `
        (async function simpleRace() {
          debugger;
          await Promise.resolve();
          var a = 2;
          await Promise.resolve();
          var b = 2;
          await Promise.resolve();
          debugger;
        })()
      `,
      debuggee,
      "1.8",
      sourceUrl,
      1
    );
  }

  await executeOnNextTickAndWaitForPause(evaluateTestCode, threadFront);

  const step1 = await stepOver(threadFront);
  equal(step1.frame.where.line, 4);

  const step2 = await stepOver(threadFront);
  equal(step2.frame.where.line, 5);

  const step3 = await stepOver(threadFront);
  equal(step3.frame.where.line, 6);
  resume(threadFront);
}

async function testGenerator({ threadFront, debuggee }) {
  function evaluateTestCode() {
    Cu.evalInSandbox(
      `
        (async function() {
          function* makeSteps() {
            debugger;
            yield 1;
            yield 2;
            return 3;
          }
          const s = makeSteps();
          s.next();
          s.next();
          s.next();
        })()
      `,
      debuggee,
      "1.8",
      sourceUrl,
      1
    );
  }

  await executeOnNextTickAndWaitForPause(evaluateTestCode, threadFront);

  const step1 = await stepOver(threadFront);
  equal(step1.frame.where.line, 5);

  const step2 = await stepOver(threadFront);
  equal(step2.frame.where.line, 6);

  const step3 = await stepOver(threadFront);
  equal(step3.frame.where.line, 7);
  await resume(threadFront);
}