Debian Codegraph @

rhino/testsrc/tests/js1_5/extensions/regress-104077.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: 10 October 2001
9 * SUMMARY: Regression test for Bugzilla bug 104077
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=104077
11 * "JS crash: with/finally/return"
12 *
13 * Also http://bugzilla.mozilla.org/show_bug.cgi?id=120571
14 * "JS crash: try/catch/continue."
15 *
16 * SpiderMonkey crashed on this code - it shouldn't.
17 *
18 * NOTE: the finally-blocks below should execute even if their try-blocks
19 * have return or throw statements in them:
20 *
21 * ------- Additional Comment #76 From Mike Shaver 2001-12-07 01:21 -------
22 * finally trumps return, and all other control-flow constructs that cause
23 * program execution to jump out of the try block: throw, break, etc. Once you
24 * enter a try block, you will execute the finally block after leaving the try,
25 * regardless of what happens to make you leave the try.
26 *
27 */
28 //-----------------------------------------------------------------------------
29 var gTestfile = 'regress-104077.js';
30 var UBound = 0;
31 var BUGNUMBER = 104077;
32 var summary = "Just testing that we don't crash on with/finally/return -";
33 var status = '';
34 var statusitems = [];
35 var actual = '';
36 var actualvalues = [];
37 var expect= '';
38 var expectedvalues = [];
39
40
41 function addValues_3(obj)
42 {
43 var sum = 0;
44
45 with (obj)
46 {
47 try
48 {
49 sum = arg1 + arg2;
50 with (arg3)
51 {
52 while (sum < 10)
53 {
54 try
55 {
56 if (sum > 5)
57 return sum;
58 sum += 1;
59 }
60 catch (e)
61 {
62 sum += 1;
63 print(e);
64 }
65 }
66 }
67 }
68 finally
69 {
70 try
71 {
72 sum +=1;
73 print("In finally block of addValues_3() function: sum = " + sum);
74 }
75 catch (e if e == 42)
76 {
77 sum +=1;
78 print('In finally catch block of addValues_3() function: sum = ' + sum + ', e = ' + e);
79 }
80 finally
81 {
82 sum +=1;
83 print("In finally finally block of addValues_3() function: sum = " + sum);
84 return sum;
85 }
86 }
87 }
88 }
89
90 status = inSection(9);
91 obj = new Object();
92 obj.arg1 = 1;
93 obj.arg2 = 2;
94 obj.arg3 = new Object();
95 obj.arg3.a = 10;
96 obj.arg3.b = 20;
97 actual = addValues_3(obj);
98 expect = 8;
99 captureThis();
100
101
102
103
104 function addValues_4(obj)
105 {
106 var sum = 0;
107
108 with (obj)
109 {
110 try
111 {
112 sum = arg1 + arg2;
113 with (arg3)
114 {
115 while (sum < 10)
116 {
117 try
118 {
119 if (sum > 5)
120 return sum;
121 sum += 1;
122 }
123 catch (e)
124 {
125 sum += 1;
126 print(e);
127 }
128 }
129 }
130 }
131 finally
132 {
133 try
134 {
135 sum += 1;
136 print("In finally block of addValues_4() function: sum = " + sum);
137 }
138 catch (e if e == 42)
139 {
140 sum += 1;
141 print("In 1st finally catch block of addValues_4() function: sum = " + sum + ", e = " + e);
142 }
143 catch (e if e == 43)
144 {
145 sum += 1;
146 print("In 2nd finally catch block of addValues_4() function: sum = " + sum + ", e = " + e);
147 }
148 finally
149 {
150 sum += 1;
151 print("In finally finally block of addValues_4() function: sum = " + sum);
152 return sum;
153 }
154 }
155 }
156 }
157
158 status = inSection(10);
159 obj = new Object();
160 obj.arg1 = 1;
161 obj.arg2 = 2;
162 obj.arg3 = new Object();
163 obj.arg3.a = 10;
164 obj.arg3.b = 20;
165 actual = addValues_4(obj);
166 expect = 8;
167 captureThis();
168
169
170
171
172 //-----------------------------------------------------------------------------
173 test();
174 //-----------------------------------------------------------------------------
175
176
177
178 function captureThis()
179 {
180 statusitems[UBound] = status;
181 actualvalues[UBound] = actual;
182 expectedvalues[UBound] = expect;
183 UBound++;
184 }
185
186
187 function test()
188 {
189 enterFunc ('test');
190 printBugNumber(BUGNUMBER);
191 printStatus (summary);
192
193 for (var i=0; i<UBound; i++)
194 {
195 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
196 }
197
198 exitFunc ('test');
199 }