tor-browser

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

onEnterFrame-generator-resumption-04.js (900B)


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