tor-browser

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

Frame-onPop-generators-07.js (945B)


      1 // Completion values for generators report yields and initial yields.
      2 
      3 load(libdir + "asserts.js");
      4 load(libdir + 'match.js');
      5 load(libdir + 'match-debugger.js');
      6 const { Pattern } = Match;
      7 const { OBJECT_WITH_EXACTLY: X } = Pattern;
      8 
      9 const g = newGlobal({ newCompartment: true });
     10 g.eval(`
     11  function* f() {
     12    yield "yielding";
     13    return "returning";
     14  }
     15 `);
     16 
     17 const dbg = new Debugger(g);
     18 const completions = [];
     19 dbg.onEnterFrame = frame => {
     20  frame.onPop = completion => {
     21    completions.push(completion);
     22  };
     23 };
     24 
     25 assertDeepEq([... g.f()], ["yielding"]);
     26 print(JSON.stringify(completions));
     27 Pattern([
     28  X({
     29    return: new DebuggerObjectPattern("Generator", {}),
     30    yield: true,
     31    initial: true
     32  }),
     33  X({
     34    return: new DebuggerObjectPattern("Object", { value: "yielding", done: false }),
     35    yield: true
     36  }),
     37  X({
     38    return: new DebuggerObjectPattern("Object", { value: "returning", done: true })
     39  }),
     40 ]).assert(completions);