tor-browser

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

throw-during-async-disposal-with-generators-doesnt-expose-magic-value.js (1102B)


      1 // |jit-test| skip-if: !getBuildConfiguration("explicit-resource-management"); --enable-explicit-resource-management
      2 
      3 load(libdir + "asserts.js");
      4 
      5 class CustomError extends Error {}
      6 
      7 {
      8  const values = [];
      9  let caught = false;
     10  async function* gen() {
     11    yield await Promise.resolve(1);
     12    await using a = {
     13      [Symbol.asyncDispose]() {
     14        values.push("a");
     15        throw new CustomError();
     16      }
     17    }
     18    yield await Promise.resolve(2);
     19    yield await Promise.resolve(3);
     20  }
     21  async function testGeneratorDoesntExposeMagicValue() {
     22    let it = gen();
     23    values.push((await it.next()).value);
     24    values.push((await it.next()).value);
     25    it.return(40).catch(e => {
     26      caught = true;
     27      // The "generator closing" is represented as a throw completion with a magic value.
     28      // The magic value shouldn't be captured as a suppressed error and exposed via the
     29      // suppressed property.
     30      assertEq(e instanceof CustomError, true);
     31    });
     32  }
     33  testGeneratorDoesntExposeMagicValue();
     34  drainJobQueue();
     35  assertArrayEq(values, [1, 2, "a"]);
     36  assertEq(caught, true);
     37 }