|
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 UBound = 0; |
|
30 var BUGNUMBER = 104077; |
|
31 var summary = "Just testing that we don't crash on with/finally/return -"; |
|
32 var status = ''; |
|
33 var statusitems = []; |
|
34 var actual = ''; |
|
35 var actualvalues = []; |
|
36 var expect= ''; |
|
37 var expectedvalues = []; |
|
38 |
|
39 |
|
40 function addValues(obj) |
|
41 { |
|
42 var sum; |
|
43 with (obj) |
|
44 { |
|
45 try |
|
46 { |
|
47 sum = arg1 + arg2; |
|
48 } |
|
49 finally |
|
50 { |
|
51 return sum; |
|
52 } |
|
53 } |
|
54 } |
|
55 |
|
56 status = inSection(1); |
|
57 var obj = new Object(); |
|
58 obj.arg1 = 1; |
|
59 obj.arg2 = 2; |
|
60 actual = addValues(obj); |
|
61 expect = 3; |
|
62 captureThis(); |
|
63 |
|
64 |
|
65 |
|
66 function tryThis() |
|
67 { |
|
68 var sum = 4 ; |
|
69 var i = 0; |
|
70 |
|
71 while (sum < 10) |
|
72 { |
|
73 try |
|
74 { |
|
75 sum += 1; |
|
76 i += 1; |
|
77 } |
|
78 finally |
|
79 { |
|
80 print("In finally case of tryThis() function"); |
|
81 } |
|
82 } |
|
83 return i; |
|
84 } |
|
85 |
|
86 status = inSection(2); |
|
87 actual = tryThis(); |
|
88 expect = 6; |
|
89 captureThis(); |
|
90 |
|
91 |
|
92 |
|
93 function myTest(x) |
|
94 { |
|
95 var obj = new Object(); |
|
96 var msg; |
|
97 |
|
98 with (obj) |
|
99 { |
|
100 msg = (x != null) ? "NO" : "YES"; |
|
101 print("Is the provided argument to myTest() null? : " + msg); |
|
102 |
|
103 try |
|
104 { |
|
105 throw "ZZZ"; |
|
106 } |
|
107 catch(e) |
|
108 { |
|
109 print("Caught thrown exception = " + e); |
|
110 } |
|
111 } |
|
112 |
|
113 return 1; |
|
114 } |
|
115 |
|
116 status = inSection(3); |
|
117 actual = myTest(null); |
|
118 expect = 1; |
|
119 captureThis(); |
|
120 |
|
121 |
|
122 |
|
123 function addValues_2(obj) |
|
124 { |
|
125 var sum = 0; |
|
126 with (obj) |
|
127 { |
|
128 try |
|
129 { |
|
130 sum = arg1 + arg2; |
|
131 with (arg3) |
|
132 { |
|
133 while (sum < 10) |
|
134 { |
|
135 try |
|
136 { |
|
137 if (sum > 5) |
|
138 return sum; |
|
139 sum += 1; |
|
140 } |
|
141 catch(e) |
|
142 { |
|
143 print('Caught an exception in addValues_2() function: ' + e); |
|
144 } |
|
145 } |
|
146 } |
|
147 } |
|
148 finally |
|
149 { |
|
150 return sum; |
|
151 } |
|
152 } |
|
153 } |
|
154 |
|
155 status = inSection(4); |
|
156 obj = new Object(); |
|
157 obj.arg1 = 1; |
|
158 obj.arg2 = 2; |
|
159 obj.arg3 = new Object(); |
|
160 obj.arg3.a = 10; |
|
161 obj.arg3.b = 20; |
|
162 actual = addValues_2(obj); |
|
163 expect = 6; |
|
164 captureThis(); |
|
165 |
|
166 |
|
167 |
|
168 status = inSection(5); |
|
169 try |
|
170 { |
|
171 throw new A(); |
|
172 } |
|
173 catch(e) |
|
174 { |
|
175 } |
|
176 finally |
|
177 { |
|
178 try |
|
179 { |
|
180 throw new A(); |
|
181 } |
|
182 catch(e) |
|
183 { |
|
184 } |
|
185 finally |
|
186 { |
|
187 actual = 'a'; |
|
188 } |
|
189 actual = 'b'; |
|
190 } |
|
191 expect = 'b'; |
|
192 captureThis(); |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 function testfunc(mode) |
|
198 { |
|
199 var obj = new Object(); |
|
200 with (obj) |
|
201 { |
|
202 var num = 100; |
|
203 var str = "abc" ; |
|
204 |
|
205 if (str == null) |
|
206 { |
|
207 try |
|
208 { |
|
209 throw "authentication.0"; |
|
210 } |
|
211 catch(e) |
|
212 { |
|
213 } |
|
214 finally |
|
215 { |
|
216 } |
|
217 |
|
218 return num; |
|
219 } |
|
220 else |
|
221 { |
|
222 try |
|
223 { |
|
224 if (mode == 0) |
|
225 throw "authentication.0"; |
|
226 else |
|
227 mytest(); |
|
228 } |
|
229 catch(e) |
|
230 { |
|
231 } |
|
232 finally |
|
233 { |
|
234 } |
|
235 |
|
236 return num; |
|
237 } |
|
238 } |
|
239 } |
|
240 |
|
241 status = inSection(6); |
|
242 actual = testfunc(0); |
|
243 expect = 100; |
|
244 captureThis(); |
|
245 |
|
246 status = inSection(7); |
|
247 actual = testfunc(); |
|
248 expect = 100; |
|
249 captureThis(); |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 function entry_menu() |
|
255 { |
|
256 var document = new Object(); |
|
257 var dialog = new Object(); |
|
258 var num = 100; |
|
259 |
|
260 with (document) |
|
261 { |
|
262 with (dialog) |
|
263 { |
|
264 try |
|
265 { |
|
266 while (true) |
|
267 { |
|
268 return num; |
|
269 } |
|
270 } |
|
271 finally |
|
272 { |
|
273 } |
|
274 } |
|
275 } |
|
276 } |
|
277 |
|
278 status = inSection(8); |
|
279 actual = entry_menu(); |
|
280 expect = 100; |
|
281 captureThis(); |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 function addValues_5(obj) |
|
287 { |
|
288 var sum = 0; |
|
289 |
|
290 with (obj) |
|
291 { |
|
292 try |
|
293 { |
|
294 sum = arg1 + arg2; |
|
295 with (arg3) |
|
296 { |
|
297 while (sum < 10) |
|
298 { |
|
299 try |
|
300 { |
|
301 if (sum > 5) |
|
302 return sum; |
|
303 sum += 1; |
|
304 } |
|
305 catch (e) |
|
306 { |
|
307 sum += 1; |
|
308 } |
|
309 } |
|
310 } |
|
311 } |
|
312 finally |
|
313 { |
|
314 try |
|
315 { |
|
316 sum += 1; |
|
317 print("In finally block of addValues_5() function: sum = " + sum); |
|
318 } |
|
319 catch (e) |
|
320 { |
|
321 sum += 1; |
|
322 print("In finally catch block of addValues_5() function: sum = " + sum + ", e = " + e); |
|
323 } |
|
324 finally |
|
325 { |
|
326 sum += 1; |
|
327 print("In finally finally block of addValues_5() function: sum = " + sum); |
|
328 return sum; |
|
329 } |
|
330 } |
|
331 } |
|
332 } |
|
333 |
|
334 status = inSection(11); |
|
335 obj = new Object(); |
|
336 obj.arg1 = 1; |
|
337 obj.arg2 = 2; |
|
338 obj.arg3 = new Object(); |
|
339 obj.arg3.a = 10; |
|
340 obj.arg3.b = 20; |
|
341 actual = addValues_5(obj); |
|
342 expect = 8; |
|
343 captureThis(); |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 function testObj(obj) |
|
349 { |
|
350 var x = 42; |
|
351 |
|
352 try |
|
353 { |
|
354 with (obj) |
|
355 { |
|
356 if (obj.p) |
|
357 throw obj.p; |
|
358 x = obj.q; |
|
359 } |
|
360 } |
|
361 finally |
|
362 { |
|
363 print("in finally block of testObj() function"); |
|
364 return 999; |
|
365 } |
|
366 } |
|
367 |
|
368 status = inSection(12); |
|
369 obj = {p:43}; |
|
370 actual = testObj(obj); |
|
371 expect = 999; |
|
372 captureThis(); |
|
373 |
|
374 |
|
375 |
|
376 /* |
|
377 * Next two cases are from http://bugzilla.mozilla.org/show_bug.cgi?id=120571 |
|
378 */ |
|
379 function a120571() |
|
380 { |
|
381 while(0) |
|
382 { |
|
383 try |
|
384 { |
|
385 } |
|
386 catch(e) |
|
387 { |
|
388 continue; |
|
389 } |
|
390 } |
|
391 } |
|
392 |
|
393 // this caused a crash! Test to see that it doesn't now. |
|
394 print(a120571); |
|
395 |
|
396 // Now test that we have a non-null value for a120571.toString() |
|
397 status = inSection(13); |
|
398 try |
|
399 { |
|
400 actual = a120571.toString().match(/continue/)[0]; |
|
401 } |
|
402 catch(e) |
|
403 { |
|
404 actual = 'FAILED! Did not find "continue" in function body'; |
|
405 } |
|
406 expect = 'continue'; |
|
407 captureThis(); |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 function b() |
|
413 { |
|
414 for(;;) |
|
415 { |
|
416 try |
|
417 { |
|
418 } |
|
419 catch(e) |
|
420 { |
|
421 continue; |
|
422 } |
|
423 } |
|
424 } |
|
425 |
|
426 // this caused a crash!!! Test to see that it doesn't now. |
|
427 print(b); |
|
428 |
|
429 // Now test that we have a non-null value for b.toString() |
|
430 status = inSection(14); |
|
431 try |
|
432 { |
|
433 actual = b.toString().match(/continue/)[0]; |
|
434 } |
|
435 catch(e) |
|
436 { |
|
437 actual = 'FAILED! Did not find "continue" in function body'; |
|
438 } |
|
439 expect = 'continue'; |
|
440 captureThis(); |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 //----------------------------------------------------------------------------- |
|
447 test(); |
|
448 //----------------------------------------------------------------------------- |
|
449 |
|
450 |
|
451 |
|
452 function captureThis() |
|
453 { |
|
454 statusitems[UBound] = status; |
|
455 actualvalues[UBound] = actual; |
|
456 expectedvalues[UBound] = expect; |
|
457 UBound++; |
|
458 } |
|
459 |
|
460 |
|
461 function test() |
|
462 { |
|
463 enterFunc ('test'); |
|
464 printBugNumber(BUGNUMBER); |
|
465 printStatus (summary); |
|
466 |
|
467 for (var i=0; i<UBound; i++) |
|
468 { |
|
469 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
|
470 } |
|
471 |
|
472 exitFunc ('test'); |
|
473 } |