tor-browser

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

regress-104077.js (4154B)


      1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 /*
      7 *
      8 * Date: 10 October 2001
      9 * SUMMARY: Regression test for Bugzilla bug 104077
     10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=104077
     11 * "JS crash: with/finally/return"
     12 *
     13 * Also http://bugzilla.mozilla.org/show_bug.cgi?id=120571
     14 * "JS crash: try/catch/continue."
     15 *
     16 * SpiderMonkey crashed on this code - it shouldn't.
     17 *
     18 * NOTE: the finally-blocks below should execute even if their try-blocks
     19 * have return or throw statements in them:
     20 *
     21 * ------- Additional Comment #76 From Mike Shaver 2001-12-07 01:21 -------
     22 * finally trumps return, and all other control-flow constructs that cause
     23 * program execution to jump out of the try block: throw, break, etc.  Once you
     24 * enter a try block, you will execute the finally block after leaving the try,
     25 * regardless of what happens to make you leave the try.
     26 *
     27 */
     28 //-----------------------------------------------------------------------------
     29 var UBound = 0;
     30 var BUGNUMBER = 104077;
     31 var summary = "Just testing that we don't crash on with/finally/return -";
     32 var status = '';
     33 var statusitems = [];
     34 var actual = '';
     35 var actualvalues = [];
     36 var expect= '';
     37 var expectedvalues = [];
     38 
     39 
     40 function addValues_3(obj)
     41 {
     42  var sum = 0;
     43 
     44  with (obj)
     45  {
     46    try
     47    {
     48      sum = arg1 + arg2;
     49      with (arg3)
     50      {
     51        while (sum < 10)
     52        {
     53          try
     54          {
     55            if (sum > 5)
     56              return sum;
     57            sum += 1;
     58          }
     59          catch (e)
     60          {
     61            sum += 1;
     62          }
     63        }
     64      }
     65    }
     66    finally
     67    {
     68      try
     69      {
     70        sum +=1;
     71        print("In finally block of addValues_3() function: sum = " + sum);
     72      }
     73      catch (e) {
     74        if (e != 42)
     75          throw e;
     76        sum +=1;
     77        print('In finally catch block of addValues_3() function: sum = ' + sum + ', e = ' + e);
     78      }
     79      finally
     80      {
     81        sum +=1;
     82        print("In finally finally block of addValues_3() function: sum = " + sum);
     83        return sum;
     84      }
     85    }
     86  }
     87 }
     88 
     89 status = inSection(9);
     90 obj = new Object();
     91 obj.arg1 = 1;
     92 obj.arg2 = 2;
     93 obj.arg3 = new Object();
     94 obj.arg3.a = 10;
     95 obj.arg3.b = 20;
     96 actual = addValues_3(obj);
     97 expect = 8;
     98 captureThis();
     99 
    100 
    101 
    102 
    103 function addValues_4(obj)
    104 {
    105  var sum = 0;
    106 
    107  with (obj)
    108  {
    109    try
    110    {
    111      sum = arg1 + arg2;
    112      with (arg3)
    113      {
    114        while (sum < 10)
    115        {
    116          try
    117          {
    118            if (sum > 5)
    119              return sum;
    120            sum += 1;
    121          }
    122          catch (e)
    123          {
    124            sum += 1;
    125          }
    126        }
    127      }
    128    }
    129    finally
    130    {
    131      try
    132      {
    133        sum += 1;
    134        print("In finally block of addValues_4() function: sum = " + sum);
    135      }
    136      catch (e) {
    137        if (e == 42) {
    138          sum += 1;
    139          print("In 1st finally catch block of addValues_4() function: sum = " + sum + ", e = " + e);
    140        } else if (e == 43) {
    141          sum += 1;
    142          print("In 2nd finally catch block of addValues_4() function: sum = " + sum + ", e = " + e);
    143        } else {
    144          throw e;
    145        }
    146      }
    147      finally
    148      {
    149        sum += 1;
    150        print("In finally finally block of addValues_4() function: sum = " + sum);
    151        return sum;
    152      }
    153    }
    154  }
    155 }
    156 
    157 status = inSection(10);
    158 obj = new Object();
    159 obj.arg1 = 1;
    160 obj.arg2 = 2;
    161 obj.arg3 = new Object();
    162 obj.arg3.a = 10;
    163 obj.arg3.b = 20;
    164 actual = addValues_4(obj);
    165 expect = 8;
    166 captureThis();
    167 
    168 
    169 
    170 
    171 //-----------------------------------------------------------------------------
    172 test();
    173 //-----------------------------------------------------------------------------
    174 
    175 
    176 
    177 function captureThis()
    178 {
    179  statusitems[UBound] = status;
    180  actualvalues[UBound] = actual;
    181  expectedvalues[UBound] = expect;
    182  UBound++;
    183 }
    184 
    185 
    186 function test()
    187 {
    188  printBugNumber(BUGNUMBER);
    189  printStatus (summary);
    190 
    191  for (var i=0; i<UBound; i++)
    192  {
    193    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    194  }
    195 }