tor-browser

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

bug-1387503-2.js (1374B)


      1 // Test uncatchable error when a stream's queuing strategy's size() method is called.
      2 /* global newGlobal */
      3 
      4 let fnFinished = false;
      5 let g;
      6 add_task(async function test() {
      7  // Make `debugger;` raise an uncatchable exception.
      8  g = newGlobal();
      9  g.parent = this;
     10  g.hit = false;
     11  g.info = info;
     12  g.eval(`
     13    var dbg = new Debugger(parent);
     14    dbg.onDebuggerStatement = (_frame, exc) => {hit = true; info("hit"); return null};
     15 `);
     16 
     17  async function fn() {
     18    // Await once to postpone the uncatchable error until we're running inside
     19    // a reaction job. We don't want the rest of the test to be terminated.
     20    // (`drainJobQueue` catches uncatchable errors!)
     21    await 1;
     22 
     23    try {
     24      // Create a stream with a strategy whose .size() method raises an
     25      // uncatchable exception, and have it call that method.
     26      new ReadableStream(
     27        {
     28          start(controller) {
     29            controller.enqueue("FIRST POST"); // this calls .size()
     30          },
     31        },
     32        {
     33          size() {
     34            // eslint-disable-next-line no-debugger
     35            debugger;
     36          },
     37        }
     38      );
     39    } finally {
     40      fnFinished = true;
     41    }
     42  }
     43 
     44  fn()
     45    .then(() => info("Resolved"))
     46    .catch(() => info("Rejected"));
     47 });
     48 
     49 add_task(() => {
     50  equal(g.hit, true, "We hit G");
     51  equal(fnFinished, false, "We didn't hit the finally block");
     52 });