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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
     6 /*
     7  *
     8  * Date:    24 Jan 2002
     9  * SUMMARY: "Too much recursion" errors should be safely caught by try...catch
    10  * See http://bugzilla.mozilla.org/show_bug.cgi?id=121658
    11  *
    12  * In the cases below, we expect i>0. The bug was filed because we
    13  * were getting i===0; i.e. |i| did not retain the value it had at the
    14  * location of the error.
    15  *
    16  */
    17 //-----------------------------------------------------------------------------
    18 var UBound = 0;
    19 var BUGNUMBER = 121658;
    20 var msg = '"Too much recursion" errors should be safely caught by try...catch';
    21 var TEST_PASSED = 'i retained the value it had at location of error';
    22 var TEST_FAILED = 'i did NOT retain this value';
    23 var status = '';
    24 var statusitems = [];
    25 var actual = '';
    26 var actualvalues = [];
    27 var expect= '';
    28 var expectedvalues = [];
    29 var i;
    32 function f()
    33 {
    34   ++i;
    36   // try...catch should catch the "too much recursion" error to ensue
    37   try
    38   {
    39     f();
    40   }
    41   catch(e)
    42   {
    43   }
    44 }
    46 i=0;
    47 f();
    48 status = inSection(1);
    49 actual = (i>0);
    50 expect = true;
    51 addThis();
    55 // Now try in function scope -
    56 function g()
    57 {
    58   f();
    59 }
    61 i=0;
    62 g();
    63 status = inSection(2);
    64 actual = (i>0);
    65 expect = true;
    66 addThis();
    70 // Now try in eval scope -
    71 var sEval = 'function h(){++i; try{h();} catch(e){}}; i=0; h();';
    72 eval(sEval);
    73 status = inSection(3);
    74 actual = (i>0);
    75 expect = true;
    76 addThis();
    80 // Try in eval scope and mix functions up -
    81 sEval = 'function a(){++i; try{h();} catch(e){}}; i=0; a();';
    82 eval(sEval);
    83 status = inSection(4);
    84 actual = (i>0);
    85 expect = true;
    86 addThis();
    91 //-----------------------------------------------------------------------------
    92 test();
    93 //-----------------------------------------------------------------------------
    97 function addThis()
    98 {
    99   statusitems[UBound] = status;
   100   actualvalues[UBound] = formatThis(actual);
   101   expectedvalues[UBound] = formatThis(expect);
   102   UBound++;
   103 }
   106 function formatThis(bool)
   107 {
   108   return bool? TEST_PASSED : TEST_FAILED;
   109 }
   112 function test()
   113 {
   114   enterFunc('test');
   115   printBugNumber(BUGNUMBER);
   116   printStatus(msg);
   118   for (var i=0; i<UBound; i++)
   119   {
   120     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   121   }
   123   exitFunc ('test');
   124 }

mercurial