tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

onEnterFrame-generator-04.js (1175B)


      1 // When a generator frame is resumed, the onEnterFrame fires again.
      2 // The same Frame object is passed.
      3 
      4 let g = newGlobal({newCompartment: true});
      5 g.eval(`
      6    function* easyMode() {}
      7 
      8    function* f() { yield* "XYZ"; }
      9    function* hardMode() {
     10        for (let c1 of "AB")
     11            for (let c2 of f())
     12                yield c1 + c2;
     13    }
     14 `);
     15 
     16 function test(mode, expected) {
     17    let dbg = new Debugger(g);
     18    let nextid = 1;
     19    dbg.onEnterFrame = frame => {
     20        if (frame.type == "call") {
     21            if (!("id" in frame))
     22                frame.id = nextid++;
     23            g.log += frame.id + "(";
     24 
     25            frame.onPop = rv => {
     26                g.log += ")";
     27            };
     28        }
     29    };
     30 
     31    g.log = "";
     32    g.eval(`
     33        for (let x of ${mode}())
     34            log += x;
     35    `);
     36    assertEq(g.log, expected);
     37    dbg.removeDebuggee(g);
     38 }
     39 
     40 // We fire onEnterFrame for the initial activation when a generator is first
     41 // called, even though the initial yield happens before any body code. This is
     42 // weird but at least it's consistent.
     43 test("easyMode", "1()1()");
     44 test("hardMode", "1()1(2()2())AX1(2())AY1(2())AZ1(2()3()3())BX1(3())BY1(3())BZ1(3())");