Debian Codegraph @

js/src/jit-test/tests/debug/onEnterFrame-generator-resumption-03.js

raw
1 // Returning {throw:} from onEnterFrame when resuming inside a try block in a
2 // generator causes control to jump to the catch block.
3
4 let g = newGlobal({newCompartment: true});
5 g.eval(`
6 function* gen() {
7 try {
8 yield 0;
9 return "fail";
10 } catch (exc) {
11 assertEq(exc, "fit");
12 return "ok";
13 }
14 }
15 `)
16
17 let dbg = new Debugger(g);
18 let hits = 0;
19 dbg.onEnterFrame = frame => {
20 assertEq(frame.callee.name, "gen");
21 if (++hits == 3) {
22 // First hit is when calling gen();
23 // second hit is resuming at the implicit initial yield;
24 // third hit is resuming inside the try block.
25 return {throw: "fit"};
26 }
27 };
28
29 let it = g.gen();
30 let result = it.next();
31 assertEq(result.done, false);
32 assertEq(result.value, 0);
33 result = it.next();
34 assertEq(result.done, true);
35 assertEq(result.value, "ok");