tor-browser

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

Frame-onStep-generator-resumption-01.js (1139B)


      1 // The debugger can't force return from a generator before the initial yield.
      2 
      3 let g = newGlobal({newCompartment: true});
      4 g.eval(`
      5  function* f() {
      6    yield 1;
      7  }
      8 `);
      9 
     10 let dbg = new Debugger(g);
     11 let steps = 0;
     12 let uncaughtErrorsReported = 0;
     13 dbg.onEnterFrame = frame => {
     14  assertEq(frame.callee.name, "f");
     15  dbg.onEnterFrame = undefined;
     16  frame.onStep = () => {
     17    steps++;
     18 
     19    // This test case never resumes the generator after the initial
     20    // yield. Therefore the initial yield has not happened yet. So this
     21    // force-return will be an error.
     22    return {return: "ponies"};
     23  };
     24 
     25  // Having an onPop hook exercises some assertions that don't happen
     26  // otherwise.
     27  frame.onPop = completion => {};
     28 };
     29 
     30 dbg.uncaughtExceptionHook = (reason) => {
     31  // When onEnterFrame returns an invalid resumption value,
     32  // the error is reported here.
     33  assertEq(reason instanceof TypeError, true);
     34  uncaughtErrorsReported++;
     35  return undefined;  // Cancel the force-return. Let the debuggee continue.
     36 };
     37 
     38 let result = g.f();
     39 assertEq(result instanceof g.f, true);
     40 
     41 assertEq(steps > 0, true);
     42 assertEq(uncaughtErrorsReported, steps);