tor-browser

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

throw-exception-stack-location.js (1042B)


      1 function throwValue(value) {
      2  throw value;
      3 }
      4 
      5 // Test for-of loops keep the exception stack.
      6 function testForOfLoop() {
      7  function f() {
      8    for (let _ of [null]) {
      9      throwValue("exception-value");
     10    }
     11  }
     12 
     13  let info = getExceptionInfo(f);
     14  assertEq(info.exception, "exception-value");
     15  assertEq(info.stack.includes("throwValue"), true);
     16 }
     17 testForOfLoop();
     18 
     19 // Test try-finally keep the exception stack.
     20 function testFinally() {
     21  function f() {
     22    try {
     23      throwValue("exception-value");
     24    } finally {
     25    }
     26  }
     27 
     28  let info = getExceptionInfo(f);
     29  assertEq(info.exception, "exception-value");
     30  assertEq(info.stack.includes("throwValue"), true);
     31 }
     32 testFinally();
     33 
     34 // Test try-catch-finally keep the exception stack.
     35 function testCatchFinally() {
     36  function f() {
     37    try {
     38      throw null;
     39    } catch {
     40     throwValue("exception-value");
     41    } finally {
     42    }
     43  }
     44 
     45  let info = getExceptionInfo(f);
     46  assertEq(info.exception, "exception-value");
     47  assertEq(info.stack.includes("throwValue"), true);
     48 }
     49 testCatchFinally();