Debian Codegraph @

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