Debian Codegraph @

rhino/testsrc/tests/js1_5/Exceptions/regress-121658.js

raw symbols SCIP
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/. */
5
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 gTestfile = 'regress-121658.js';
19 var UBound = 0;
20 var BUGNUMBER = 121658;
21 var msg = '"Too much recursion" errors should be safely caught by try...catch';
22 var TEST_PASSED = 'i retained the value it had at location of error';
23 var TEST_FAILED = 'i did NOT retain this value';
24 var status = '';
25 var statusitems = [];
26 var actual = '';
27 var actualvalues = [];
28 var expect= '';
29 var expectedvalues = [];
30 var i;
31
32
33 function f()
34 {
35 ++i;
36
37 // try...catch should catch the "too much recursion" error to ensue
38 try
39 {
40 f();
41 }
42 catch(e)
43 {
44 }
45 }
46
47 i=0;
48 f();
49 status = inSection(1);
50 actual = (i>0);
51 expect = true;
52 addThis();
53
54
55
56 // Now try in function scope -
57 function g()
58 {
59 f();
60 }
61
62 i=0;
63 g();
64 status = inSection(2);
65 actual = (i>0);
66 expect = true;
67 addThis();
68
69
70
71 // Now try in eval scope -
72 var sEval = 'function h(){++i; try{h();} catch(e){}}; i=0; h();';
73 eval(sEval);
74 status = inSection(3);
75 actual = (i>0);
76 expect = true;
77 addThis();
78
79
80
81 // Try in eval scope and mix functions up -
82 sEval = 'function a(){++i; try{h();} catch(e){}}; i=0; a();';
83 eval(sEval);
84 status = inSection(4);
85 actual = (i>0);
86 expect = true;
87 addThis();
88
89
90
91
92 //-----------------------------------------------------------------------------
93 test();
94 //-----------------------------------------------------------------------------
95
96
97
98 function addThis()
99 {
100 statusitems[UBound] = status;
101 actualvalues[UBound] = formatThis(actual);
102 expectedvalues[UBound] = formatThis(expect);
103 UBound++;
104 }
105
106
107 function formatThis(bool)
108 {
109 return bool? TEST_PASSED : TEST_FAILED;
110 }
111
112
113 function test()
114 {
115 enterFunc('test');
116 printBugNumber(BUGNUMBER);
117 printStatus(msg);
118
119 for (var i=0; i<UBound; i++)
120 {
121 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
122 }
123
124 exitFunc ('test');
125 }