tor-browser

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

suppressed-error-handling-runtime-errors.js (3436B)


      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  function testUndefinedAccessSuppressedErrorWithThrowInDispose() {
      8    using x = {
      9      [Symbol.dispose]() {
     10        disposed.push(1);
     11        undefined.x;
     12      }
     13    }
     14  }
     15  assertSuppressionChainErrorMessages(testUndefinedAccessSuppressedErrorWithThrowInDispose, [{ctor: TypeError, message: "can't access property \"x\" of undefined"}]);
     16  assertArrayEq(disposed, [1]);
     17 }
     18 
     19 {
     20  const disposed = [];
     21  function testReferenceErrorSuppressedErrorWithThrowInDispose() {
     22    using x = {
     23      [Symbol.dispose]() {
     24        disposed.push(1);
     25        y.x;
     26      }
     27    }
     28  }
     29  assertSuppressionChainErrorMessages(testReferenceErrorSuppressedErrorWithThrowInDispose, [{ctor: ReferenceError, message: "y is not defined"}]);
     30 }
     31 
     32 {
     33  const disposed = [];
     34  function testMultipleRuntimeErrorsWithThrowsDuringDispose() {
     35    using x = {
     36      [Symbol.dispose]() {
     37        disposed.push(1);
     38        undefined.x;
     39      }
     40    }
     41    using y = {
     42      [Symbol.dispose]() {
     43        disposed.push(2);
     44        a.x;
     45      }
     46    }
     47    using z = {
     48      [Symbol.dispose]() {
     49        this[Symbol.dispose]();
     50      }
     51    }
     52  }
     53  assertSuppressionChainErrorMessages(testMultipleRuntimeErrorsWithThrowsDuringDispose, [
     54    {ctor: TypeError, message: "can't access property \"x\" of undefined"},
     55    {ctor: ReferenceError, message: "a is not defined"},
     56    {ctor: InternalError, message: "too much recursion"},
     57  ]);
     58 }
     59 
     60 {
     61  const disposed = [];
     62  function testMultipleRuntimeErrorsWithThrowsDuringDisposeAndOutsideDispose() {
     63    using x = {
     64      [Symbol.dispose]() {
     65        disposed.push(1);
     66        undefined.x;
     67      }
     68    }
     69    using y = {
     70      [Symbol.dispose]() {
     71        disposed.push(2);
     72        a.x;
     73      }
     74    }
     75    using z = {
     76      [Symbol.dispose]() {
     77        this[Symbol.dispose]();
     78      }
     79    }
     80 
     81    null.x;
     82  }
     83  assertSuppressionChainErrorMessages(testMultipleRuntimeErrorsWithThrowsDuringDisposeAndOutsideDispose, [
     84    {ctor: TypeError, message: "can't access property \"x\" of undefined"},
     85    {ctor: ReferenceError, message: "a is not defined"},
     86    {ctor: InternalError, message: "too much recursion"},
     87    {ctor: TypeError, message: "can't access property \"x\" of null"},
     88  ]);
     89 }
     90 
     91 {
     92  const values = [];
     93  function* gen() {
     94    using d = {
     95      value: "d",
     96      [Symbol.dispose]() {
     97        values.push(this.value);
     98      }
     99    }
    100    yield "a";
    101    yield "b";
    102    using c = {
    103      value: "c",
    104      [Symbol.dispose]() {
    105        values.push(this.value);
    106        a.x;
    107      }
    108    }
    109    null.x;
    110  }
    111  function testRuntimeErrorsWithGenerators() {
    112    let x = gen();
    113    values.push(x.next().value);
    114    values.push(x.next().value);
    115    x.next();
    116  }
    117  assertSuppressionChainErrorMessages(testRuntimeErrorsWithGenerators, [
    118    {ctor: ReferenceError, message: "a is not defined"},
    119    {ctor: TypeError, message: "can't access property \"x\" of null"}
    120  ]);
    121 }
    122 
    123 {
    124  const disposed = [];
    125  const d = {
    126    [Symbol.dispose]() {
    127      disposed.push(1);
    128      null.x;
    129    }
    130  }
    131  function testRuntimeErrorWithLoops() {
    132    for (using x of [d]) {
    133      y.a;
    134    }
    135  }
    136  assertSuppressionChainErrorMessages(testRuntimeErrorWithLoops, [
    137    {ctor: TypeError, message: "can't access property \"x\" of null"},
    138    {ctor: ReferenceError, message: "y is not defined"},
    139  ]);
    140 }