tor-browser

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

await-using-in-function.js (1638B)


      1 // |jit-test| skip-if: !getBuildConfiguration("explicit-resource-management"); --enable-explicit-resource-management
      2 
      3 load(libdir + "asserts.js");
      4 
      5 {
      6  const disposed = [];
      7  async function testAwaitUsingInFunction() {
      8    await using x = {
      9      [Symbol.asyncDispose]() {
     10        disposed.push(1);
     11      }
     12    }
     13 
     14    await using y = {
     15      [Symbol.asyncDispose]() {
     16        disposed.push(2);
     17      }
     18    }
     19 
     20    await using z = {
     21      [Symbol.asyncDispose]() {
     22        disposed.push(3);
     23      }
     24    }
     25  }
     26  testAwaitUsingInFunction();
     27  // An async function is synchronously executed until the first await.
     28  // herein at the end of scope the await using inserts the first await
     29  // thus before awaiting this function we only see 3 to be pushed
     30  // into the disposed array.
     31  assertArrayEq(disposed, [3]);
     32  drainJobQueue();
     33  assertArrayEq(disposed, [3, 2, 1]);
     34 }
     35 
     36 {
     37  const values = [];
     38  async function testDisposedInFunctionAndBlock() {
     39    await using a = {
     40      [Symbol.dispose]: () => values.push("a")
     41    };
     42 
     43    await using b = {
     44      [Symbol.dispose]: () => values.push("b")
     45    };
     46 
     47    {
     48      await using c = {
     49        [Symbol.dispose]: () => values.push("c")
     50      };
     51  
     52      {
     53        await using d = {
     54          [Symbol.dispose]: () => values.push("d")
     55        };
     56      }
     57 
     58      await using e = {
     59        [Symbol.dispose]: () => values.push("e")
     60      };
     61    }
     62 
     63    await using f = {
     64      [Symbol.dispose]: () => values.push("f")
     65    };
     66 
     67    values.push("g");
     68  }
     69  testDisposedInFunctionAndBlock();
     70  assertArrayEq(values, ["d"]);
     71  drainJobQueue();
     72  assertArrayEq(values, ["d", "e", "c", "g", "f", "b", "a"]);
     73 }