tor-browser

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

disposal-during-throw-lexical-scopes.js (988B)


      1 // |jit-test| skip-if: !getBuildConfiguration("explicit-resource-management"); --enable-explicit-resource-management
      2 
      3 load(libdir + "asserts.js");
      4 
      5 const disposed = [];
      6 function testThrowsInsideInnerLexicalScope() {
      7  using x = {
      8    value: 'x',
      9    [Symbol.dispose]() {
     10      disposed.push(this.value);
     11    }
     12  }
     13  let b;
     14  {
     15    const a = 1;
     16    b = () => a;
     17    disposed.push('y');
     18    throw new Error("err");
     19  }
     20 }
     21 assertThrowsInstanceOf(testThrowsInsideInnerLexicalScope, Error);
     22 assertArrayEq(disposed, ['y', 'x']);
     23 
     24 const disposed2 = [];
     25 function lexicalFnWithThrow(th) {
     26  const a = 1;
     27  if (th) {
     28    throw new Error("err");
     29  }
     30  return () => a;
     31 }
     32 function testThrowsInsideInnerLexicalScope2() {
     33  using x = {
     34    value: 'x',
     35    [Symbol.dispose]() {
     36      disposed2.push(this.value);
     37    }
     38  }
     39  let b;
     40  {
     41    disposed2.push('y');
     42    b = lexicalFnWithThrow(true);
     43  }
     44 }
     45 assertThrowsInstanceOf(testThrowsInsideInnerLexicalScope2, Error);
     46 assertArrayEq(disposed2, ['y', 'x']);