Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / js1_5 / Exceptions / regress-121658.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is JavaScript Engine testing utilities.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corp.
19  * Portions created by the Initial Developer are Copyright (C) 2002
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *   timeless@mac.com,pschwartau@netscape.com
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 /*
40  *
41  * Date:    24 Jan 2002
42  * SUMMARY: "Too much recursion" errors should be safely caught by try...catch
43  * See http://bugzilla.mozilla.org/show_bug.cgi?id=121658
44  *
45  * In the cases below, we expect i>0. The bug was filed because we
46  * were getting i===0; i.e. |i| did not retain the value it had at the
47  * location of the error.
48  *
49  */
50 //-----------------------------------------------------------------------------
51 var UBound = 0;
52 var BUGNUMBER = 121658;
53 var msg = '"Too much recursion" errors should be safely caught by try...catch';
54 var TEST_PASSED = 'i retained the value it had at location of error';
55 var TEST_FAILED = 'i did NOT retain this value';
56 var status = '';
57 var statusitems = [];
58 var actual = '';
59 var actualvalues = [];
60 var expect= '';
61 var expectedvalues = [];
62 var i;
63
64
65 function f()
66 {
67   ++i;
68
69   // try...catch should catch the "too much recursion" error to ensue
70   try
71   {
72     f();
73   }
74   catch(e)
75   {
76   }
77 }
78
79 i=0;
80 f();
81 status = inSection(1);
82 actual = (i>0);
83 expect = true;
84 addThis();
85
86
87
88 // Now try in function scope -
89 function g()
90 {
91   f();
92 }
93
94 i=0;
95 g();
96 status = inSection(2);
97 actual = (i>0);
98 expect = true;
99 addThis();
100
101
102
103 // Now try in eval scope -
104 var sEval = 'function h(){++i; try{h();} catch(e){}}; i=0; h();';
105 eval(sEval);
106 status = inSection(3);
107 actual = (i>0);
108 expect = true;
109 addThis();
110
111
112
113 // Try in eval scope and mix functions up -
114 sEval = 'function a(){++i; try{h();} catch(e){}}; i=0; a();';
115 eval(sEval);
116 status = inSection(4);
117 actual = (i>0);
118 expect = true;
119 addThis();
120
121
122
123
124 //-----------------------------------------------------------------------------
125 test();
126 //-----------------------------------------------------------------------------
127
128
129
130 function addThis()
131 {
132   statusitems[UBound] = status;
133   actualvalues[UBound] = formatThis(actual);
134   expectedvalues[UBound] = formatThis(expect);
135   UBound++;
136 }
137
138
139 function formatThis(bool)
140 {
141   return bool? TEST_PASSED : TEST_FAILED;
142 }
143
144
145 function test()
146 {
147   enterFunc('test');
148   printBugNumber(BUGNUMBER);
149   printStatus(msg);
150
151   for (var i=0; i<UBound; i++)
152   {
153     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
154   }
155
156   exitFunc ('test');
157 }