tor-browser

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

suppressed-error-handling-generators.js (1396B)


      1 // |jit-test| skip-if: !getBuildConfiguration("explicit-resource-management"); --enable-explicit-resource-management
      2 
      3 load(libdir + "asserts.js");
      4 
      5 {
      6  const values = [];
      7  const errorsToThrow = [new Error("test1"), new Error("test2")];
      8  function* gen() {
      9    using d = {
     10      value: "d",
     11      [Symbol.dispose]() {
     12        values.push(this.value);
     13      }
     14    }
     15    yield "a";
     16    yield "b";
     17    using c = {
     18      value: "c",
     19      [Symbol.dispose]() {
     20        values.push(this.value);
     21        throw errorsToThrow[0]; // This error will suppress the error thrown below.
     22      }
     23    }
     24    throw errorsToThrow[1]; // This error will be suppressed during disposal.
     25  }
     26  assertSuppressionChain(() => {
     27    let x = gen();
     28    values.push(x.next().value);
     29    values.push(x.next().value);
     30    x.next();
     31  }, errorsToThrow);
     32 
     33  assertArrayEq(values, ["a", "b", "c", "d"]);
     34 }
     35 
     36 {
     37  const values = [];
     38  const errorsToThrow = [new Error("test1"), new Error("test2")];
     39  function* gen() {
     40    using c = {
     41      value: "c",
     42      [Symbol.dispose]() {
     43        values.push(this.value);
     44        throw errorsToThrow[0];
     45      }
     46    }
     47    yield "a";
     48    yield "b";
     49    return;
     50  }
     51 
     52  assertSuppressionChain(() => {
     53    let x = gen();
     54    values.push(x.next().value);
     55    x.throw(errorsToThrow[1]); // This error will be suppressed during disposal.
     56  }, errorsToThrow);
     57 
     58  assertArrayEq(values, ["a", "c"]);
     59 }