tor-browser

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

onEnterFrame-generator-resumption-02.js (1215B)


      1 // A Debugger can {return:} from onEnterFrame at any resume point in a generator.
      2 // Force-returning closes the generator.
      3 
      4 load(libdir + "asserts.js");
      5 
      6 let g = newGlobal({newCompartment: true});
      7 g.values = [1, 2, 3];
      8 g.eval(`function* f() { yield* values; }`);
      9 
     10 let dbg = Debugger(g);
     11 
     12 // onEnterFrame will fire up to 5 times.
     13 // - once for the initial call to g.f();
     14 // - four times at resume points:
     15 //   - initial resume at the top of the generator body
     16 //   - resume after yielding 1
     17 //   - resume after yielding 2
     18 //   - resume after yielding 3 (this resumption will run to the end).
     19 // This test ignores the initial call and focuses on resume points.
     20 for (let i = 1; i < 5; i++) {
     21    let hits = 0;
     22    dbg.onEnterFrame = frame => {
     23        return hits++ < i ? undefined : {return: "we're done here"};
     24    };
     25 
     26    let genObj = g.f();
     27    let actual = [];
     28    while (true) {
     29        let r = genObj.next();
     30        if (r.done) {
     31            assertDeepEq(r, {value: "we're done here", done: true});
     32            break;
     33        }
     34        actual.push(r.value);
     35    }
     36    assertEq(hits, i + 1);
     37    assertDeepEq(actual, g.values.slice(0, i - 1));
     38    assertDeepEq(genObj.next(), {value: undefined, done: true});
     39 }