Debian Codegraph @

js/src/jit-test/tests/debug/onEnterFrame-generator-02.js

raw
1 // onEnterFrame fires after the [[GeneratorState]] is set to "executing".
2 //
3 // This test checks that Debugger doesn't accidentally make it possible to
4 // reenter a generator frame that's already on the stack. (Also tests a fun
5 // corner case in baseline debug-mode OSR.)
6
7 load(libdir + "asserts.js");
8
9 let g = newGlobal({newCompartment: true});
10 g.eval('function* f() { yield 1; yield 2; }');
11 let dbg = Debugger(g);
12 let genObj = null;
13 let hits = 0;
14 dbg.onEnterFrame = frame => {
15 // The first time onEnterFrame fires, there is no generator object, so
16 // there's nothing to test. The generator object doesn't exist until
17 // JSOP_GENERATOR is reached, right before the initial yield.
18 if (genObj !== null) {
19 dbg.removeDebuggee(g); // avoid the DebuggeeWouldRun exception
20 assertThrowsInstanceOf(() => genObj.next(), g.TypeError);
21 dbg.addDebuggee(g);
22 hits++;
23 }
24 };
25 genObj = g.f();
26 for (let x of genObj) {}
27 assertEq(hits, 3);