Debian Codegraph @

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

raw
1 // Don't crash on {return:} from onStep in a generator, before the initial suspend.
2
3 // This test tries to force-return from each bytecode instruction in a
4 // generator, up to the initial suspend.
5
6 load(libdir + "asserts.js");
7
8 let g = newGlobal({newCompartment: true});
9 g.values = [1, 2, 3];
10 g.eval(`function* f(arr=values) { yield* arr; }`);
11
12 let dbg = Debugger(g);
13
14 function test(ttl) {
15 let hits = 0;
16 dbg.onEnterFrame = frame => {
17 assertEq(frame.callee.name, "f");
18 frame.onStep = () => {
19 if (--ttl === 0)
20 return {return: 123};
21 };
22 };
23 dbg.uncaughtExceptionHook = exc => {
24 return {throw: "debugger error: " + exc};
25 };
26
27 let val = undefined;
28 let caught = undefined;
29 try {
30 val = g.f();
31 } catch (exc) {
32 caught = exc;
33 }
34
35 if (val === undefined) {
36 // Tried to force-return before the initial suspend.
37 assertEq(caught, "debugger error: TypeError: can't force return from a generator before the initial yield");
38 assertEq(ttl, 0);
39 return "pass";
40 } else {
41 // Reached the initial suspend without forcing a return.
42 assertEq(typeof val, "object");
43 assertEq(val instanceof g.f, true);
44 assertEq(ttl, 1);
45 return "done";
46 }
47 }
48
49 for (let i = 1; test(i) === "pass"; i++) {}