|
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 var BUGNUMBER = 350312; |
|
8 var summary = 'Accessing wrong stack slot with nested catch/finally'; |
|
9 var actual = ''; |
|
10 var expect = ''; |
|
11 |
|
12 |
|
13 //----------------------------------------------------------------------------- |
|
14 test(); |
|
15 //----------------------------------------------------------------------------- |
|
16 |
|
17 function test() |
|
18 { |
|
19 enterFunc ('test'); |
|
20 printBugNumber(BUGNUMBER); |
|
21 printStatus (summary); |
|
22 |
|
23 function createPrint(obj) |
|
24 { |
|
25 return new Function("actual += " + obj + " + ','; " + |
|
26 "print(" + obj + ");"); |
|
27 } |
|
28 |
|
29 function createThrow(obj) |
|
30 { |
|
31 return new Function("throw " + obj + "; "); |
|
32 } |
|
33 |
|
34 |
|
35 function f(a, b, c) |
|
36 { |
|
37 try { |
|
38 a(); |
|
39 } catch (e if e == null) { |
|
40 b(); |
|
41 } finally { |
|
42 c(); |
|
43 } |
|
44 } |
|
45 |
|
46 print('test 1'); |
|
47 expect = 'a,c,'; |
|
48 actual = ''; |
|
49 try |
|
50 { |
|
51 f(createPrint("'a'"), createPrint("'b'"), createPrint("'c'")); |
|
52 } |
|
53 catch(ex) |
|
54 { |
|
55 actual += 'caught ' + ex; |
|
56 } |
|
57 reportCompare(expect, actual, summary + ': 1'); |
|
58 |
|
59 print('test 2'); |
|
60 expect = 'c,caught a'; |
|
61 actual = ''; |
|
62 try |
|
63 { |
|
64 f(createThrow("'a'"), createPrint("'b'"), createPrint("'c'")); |
|
65 } |
|
66 catch(ex) |
|
67 { |
|
68 actual += 'caught ' + ex; |
|
69 } |
|
70 reportCompare(expect, actual, summary + ': 2'); |
|
71 |
|
72 print('test 3'); |
|
73 expect = 'b,c,'; |
|
74 actual = ''; |
|
75 try |
|
76 { |
|
77 f(createThrow("null"), createPrint("'b'"), createPrint("'c'")); |
|
78 } |
|
79 catch(ex) |
|
80 { |
|
81 actual += 'caught ' + ex; |
|
82 } |
|
83 reportCompare(expect, actual, summary + ': 3'); |
|
84 |
|
85 print('test 4'); |
|
86 expect = 'a,c,'; |
|
87 actual = ''; |
|
88 try |
|
89 { |
|
90 f(createPrint("'a'"), createThrow("'b'"), createPrint("'c'")); |
|
91 } |
|
92 catch(ex) |
|
93 { |
|
94 actual += 'caught ' + ex; |
|
95 } |
|
96 reportCompare(expect, actual, summary + ': 4'); |
|
97 |
|
98 print('test 5'); |
|
99 expect = 'c,caught b'; |
|
100 actual = ''; |
|
101 try |
|
102 { |
|
103 f(createThrow("null"), createThrow("'b'"), createPrint("'c'")); |
|
104 } |
|
105 catch(ex) |
|
106 { |
|
107 actual += 'caught ' + ex; |
|
108 } |
|
109 reportCompare(expect, actual, summary + ': 5'); |
|
110 |
|
111 exitFunc ('test'); |
|
112 } |