js/src/tests/js1_5/Exceptions/regress-121658.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/Exceptions/regress-121658.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,124 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + *
    1.11 + * Date:    24 Jan 2002
    1.12 + * SUMMARY: "Too much recursion" errors should be safely caught by try...catch
    1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=121658
    1.14 + *
    1.15 + * In the cases below, we expect i>0. The bug was filed because we
    1.16 + * were getting i===0; i.e. |i| did not retain the value it had at the
    1.17 + * location of the error.
    1.18 + *
    1.19 + */
    1.20 +//-----------------------------------------------------------------------------
    1.21 +var UBound = 0;
    1.22 +var BUGNUMBER = 121658;
    1.23 +var msg = '"Too much recursion" errors should be safely caught by try...catch';
    1.24 +var TEST_PASSED = 'i retained the value it had at location of error';
    1.25 +var TEST_FAILED = 'i did NOT retain this value';
    1.26 +var status = '';
    1.27 +var statusitems = [];
    1.28 +var actual = '';
    1.29 +var actualvalues = [];
    1.30 +var expect= '';
    1.31 +var expectedvalues = [];
    1.32 +var i;
    1.33 +
    1.34 +
    1.35 +function f()
    1.36 +{
    1.37 +  ++i;
    1.38 +
    1.39 +  // try...catch should catch the "too much recursion" error to ensue
    1.40 +  try
    1.41 +  {
    1.42 +    f();
    1.43 +  }
    1.44 +  catch(e)
    1.45 +  {
    1.46 +  }
    1.47 +}
    1.48 +
    1.49 +i=0;
    1.50 +f();
    1.51 +status = inSection(1);
    1.52 +actual = (i>0);
    1.53 +expect = true;
    1.54 +addThis();
    1.55 +
    1.56 +
    1.57 +
    1.58 +// Now try in function scope -
    1.59 +function g()
    1.60 +{
    1.61 +  f();
    1.62 +}
    1.63 +
    1.64 +i=0;
    1.65 +g();
    1.66 +status = inSection(2);
    1.67 +actual = (i>0);
    1.68 +expect = true;
    1.69 +addThis();
    1.70 +
    1.71 +
    1.72 +
    1.73 +// Now try in eval scope -
    1.74 +var sEval = 'function h(){++i; try{h();} catch(e){}}; i=0; h();';
    1.75 +eval(sEval);
    1.76 +status = inSection(3);
    1.77 +actual = (i>0);
    1.78 +expect = true;
    1.79 +addThis();
    1.80 +
    1.81 +
    1.82 +
    1.83 +// Try in eval scope and mix functions up -
    1.84 +sEval = 'function a(){++i; try{h();} catch(e){}}; i=0; a();';
    1.85 +eval(sEval);
    1.86 +status = inSection(4);
    1.87 +actual = (i>0);
    1.88 +expect = true;
    1.89 +addThis();
    1.90 +
    1.91 +
    1.92 +
    1.93 +
    1.94 +//-----------------------------------------------------------------------------
    1.95 +test();
    1.96 +//-----------------------------------------------------------------------------
    1.97 +
    1.98 +
    1.99 +
   1.100 +function addThis()
   1.101 +{
   1.102 +  statusitems[UBound] = status;
   1.103 +  actualvalues[UBound] = formatThis(actual);
   1.104 +  expectedvalues[UBound] = formatThis(expect);
   1.105 +  UBound++;
   1.106 +}
   1.107 +
   1.108 +
   1.109 +function formatThis(bool)
   1.110 +{
   1.111 +  return bool? TEST_PASSED : TEST_FAILED;
   1.112 +}
   1.113 +
   1.114 +
   1.115 +function test()
   1.116 +{
   1.117 +  enterFunc('test');
   1.118 +  printBugNumber(BUGNUMBER);
   1.119 +  printStatus(msg);
   1.120 +
   1.121 +  for (var i=0; i<UBound; i++)
   1.122 +  {
   1.123 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.124 +  }
   1.125 +
   1.126 +  exitFunc ('test');
   1.127 +}

mercurial