tor-browser

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

onEnterFrame-async-resumption-05.js (1437B)


      1 // A Debugger can't force-return from the first onEnterFrame for an async generator.
      2 
      3 ignoreUnhandledRejections();
      4 
      5 let g = newGlobal({newCompartment: true});
      6 g.eval(`async function* f(x) { await x; return "ponies"; }`);
      7 
      8 let dbg = new Debugger;
      9 let gw = dbg.addDebuggee(g);
     10 let log = "";
     11 let completion = undefined;
     12 let resumption = undefined;
     13 dbg.uncaughtExceptionHook = exc => {
     14    log += "2";
     15    assertEq(exc.message, "can't force return from a generator before the initial yield");
     16    assertEq(exc.constructor, TypeError);
     17    return undefined;  // Squelch the error and let the debuggee continue.
     18 };
     19 dbg.onEnterFrame = frame => {
     20    if (frame.type == "call" && frame.callee.name === "f") {
     21        frame.onPop = c => {
     22            // We get here after the uncaughtExcpetionHook fires
     23            // and the debuggee frame has run to the first await.
     24            completion = c;
     25            assertEq(completion.return.class, "AsyncGenerator");
     26            assertEq(completion.return !== resumption.return, true);
     27            log += "3";
     28        };
     29 
     30        // Try force-returning an actual object of the expected type.
     31        dbg.onEnterFrame = undefined;  // don't recurse
     32        resumption = frame.eval('f(0)');
     33        assertEq(resumption.return.class, "AsyncGenerator");
     34        log += "1";
     35        return resumption;
     36    }
     37 };
     38 
     39 let it = g.f(0);
     40 assertEq(log, "123");
     41 assertEq(gw.makeDebuggeeValue(it), completion.return);