summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/modules/failure-on-resume.js
blob: d0e716b0bb8a4c862c2bb78324021031c63d521d (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
const dbgGlobal = newGlobal({ newCompartment: true });
dbgGlobal.parent = this;
dbgGlobal.eval(`
var entered = 0;
var forceReturn = false;
Debugger(parent).onEnterFrame = function () {
  entered++;
  if (forceReturn) {
    return { return: "force return" };
  }
  return undefined;
};
`);

{
  function* f1() { yield 10; };

  dbgGlobal.entered = 0;
  let g = f1();
  assertEq(dbgGlobal.entered, 1);
  dbgGlobal.forceReturn = true;
  let ret = g.next();
  dbgGlobal.forceReturn = false;
  assertEq(dbgGlobal.entered, 2);

  assertEq(ret.value, "force return");
}

{
  async function f2() { await {}; }

  dbgGlobal.entered = 0;
  let p = f2();
  assertEq(dbgGlobal.entered, 1);
  dbgGlobal.forceReturn = true;
  drainJobQueue();
  dbgGlobal.forceReturn = false;
  assertEq(dbgGlobal.entered, 2);

  let ret = null;
  p.then(x => ret = x);
  drainJobQueue();
  assertEq(ret, "force return");
}

{
  async function* f3() { await {}; }

  dbgGlobal.entered = 0;
  let g = f3();
  assertEq(dbgGlobal.entered, 1);
  dbgGlobal.forceReturn = true;
  let p = g.next();
  dbgGlobal.forceReturn = false;
  assertEq(dbgGlobal.entered, 2);

  let ret = null;
  p.then(v => ret = v);
  drainJobQueue();
  assertEq(ret.value, "force return");
}

{
  let m = registerModule("1", parseModule("await {};"));
  moduleLink(m);

  dbgGlobal.entered = 0;
  let p = moduleEvaluate(m);
  assertEq(dbgGlobal.entered, 1);
  dbgGlobal.forceReturn = true;
  drainJobQueue();
  dbgGlobal.forceReturn = false;
  assertEq(dbgGlobal.entered, 2);

  let ret = null;
  p.then(x => ret = x);
  drainJobQueue();
  assertEq(ret, undefined);
}