|
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 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; |
|
30 |
|
31 |
|
32 function f() |
|
33 { |
|
34 ++i; |
|
35 |
|
36 // try...catch should catch the "too much recursion" error to ensue |
|
37 try |
|
38 { |
|
39 f(); |
|
40 } |
|
41 catch(e) |
|
42 { |
|
43 } |
|
44 } |
|
45 |
|
46 i=0; |
|
47 f(); |
|
48 status = inSection(1); |
|
49 actual = (i>0); |
|
50 expect = true; |
|
51 addThis(); |
|
52 |
|
53 |
|
54 |
|
55 // Now try in function scope - |
|
56 function g() |
|
57 { |
|
58 f(); |
|
59 } |
|
60 |
|
61 i=0; |
|
62 g(); |
|
63 status = inSection(2); |
|
64 actual = (i>0); |
|
65 expect = true; |
|
66 addThis(); |
|
67 |
|
68 |
|
69 |
|
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(); |
|
77 |
|
78 |
|
79 |
|
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(); |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 //----------------------------------------------------------------------------- |
|
92 test(); |
|
93 //----------------------------------------------------------------------------- |
|
94 |
|
95 |
|
96 |
|
97 function addThis() |
|
98 { |
|
99 statusitems[UBound] = status; |
|
100 actualvalues[UBound] = formatThis(actual); |
|
101 expectedvalues[UBound] = formatThis(expect); |
|
102 UBound++; |
|
103 } |
|
104 |
|
105 |
|
106 function formatThis(bool) |
|
107 { |
|
108 return bool? TEST_PASSED : TEST_FAILED; |
|
109 } |
|
110 |
|
111 |
|
112 function test() |
|
113 { |
|
114 enterFunc('test'); |
|
115 printBugNumber(BUGNUMBER); |
|
116 printStatus(msg); |
|
117 |
|
118 for (var i=0; i<UBound; i++) |
|
119 { |
|
120 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
|
121 } |
|
122 |
|
123 exitFunc ('test'); |
|
124 } |