more ttf bug fixes
[swftools.git] / lib / as3 / ok / finally2.as
1 /* same as finally.as, only for larger finally blocks which require a
2    lookupswitch */
3
4 package {
5     import flash.display.MovieClip;
6
7     public class Main extends flash.display.MovieClip {
8         var i=0;
9         function test_return():int {
10             try {
11                 if(i==0) return 0;
12                 if(i==1) return 2;
13                 if(i==2) return 4;
14                 if(i==3) return 7;
15                 if(i==4) return 9;
16                 trace("error");
17             } finally {
18                 i = 0;
19                 trace("ok","1/11");
20             }
21             trace("error");
22             return 0;
23         }
24        
25         function test_break() {
26             do {
27                 try {
28                     if(i==0) break;
29                     trace("error");
30                     if(i==3) break;
31                     if(i==7) break;
32                     if(i==9) break;
33                     if(i==11) break;
34                     trace("error");
35                 } finally {
36                     i = 0;
37                     trace("ok","2/11");
38                 }
39                 trace("error");
40             } while(true);
41         }
42         
43         function test_fallthrough() {
44             try {
45                 var x = 1+1;
46                 if(i==1) return;
47                 if(i==2) return;
48                 if(i==3) return;
49                 if(i==4) return;
50                 if(i==5) return;
51             } finally {
52                 i = 0;
53                 trace("ok","3/11");
54             }
55         }
56        
57         function test_exception() {
58             try {
59                 try {
60                     if(i==0)
61                         throw new Error();
62                     if(i==1)
63                         return;
64                     if(i==2)
65                         return;
66                     if(i==3)
67                         throw new Object();
68                     trace("error");
69                 } finally {
70                     i = 0;
71                     trace("ok","4/11");
72                 }
73                 trace("error");
74             } catch(e:Error) {
75                 i = 0;
76                 trace("ok","5/11");
77             }
78         }
79         
80         function test_exception2() {
81             var x:int = 0;
82             try {
83                 if(i==1)
84                     return;
85                 if(i==0)
86                     throw new Error();
87                 if(i==3)
88                     throw new Error();
89                 trace("error");
90             } catch(e:Error) {
91                 x=1;
92             } finally {
93                 new Array(1,2,3,4,5,6);
94                 i = 0;
95                 x*=2;
96             }
97             if(x==2)
98                 trace("ok 6/11");
99         }
100         
101         function fail1() {
102             try {
103                 if(i==0) throw new Error();
104                 if(i==7) throw new Error();
105                 if(i==11) throw new Error();
106                 if(i==15) throw new Error();
107                 if(i==17) throw new Error();
108             } finally {
109                 new Array(1,2,3,4,5,6);
110                 i = 0;
111                 trace("ok","7/11");
112             }
113         }
114         
115         function fail2() {
116             try {
117                 fail1();
118             } finally {
119                 new Array(1,2,3,4,5,6);
120                 i = 0;
121                 trace("ok","8/11");
122             }
123         }
124         
125         function test_exception3() {
126             try {
127                 fail2();
128             } catch(e:Error) {
129                 trace("ok 9/11");
130             }
131         }
132         
133         function test_empty() {
134             try {
135             } finally {
136             }
137             trace("ok 10/11");
138         }
139
140         function test_mixed():int {
141             while(true) {
142                 try {
143                     if(i==3) continue;
144                     if(i==2) throw new Error();
145                     if(i==1) return 1;
146                     if(i==0) break;
147                 } finally {
148                     trace("ok","11/11");
149                     i = 0;
150                 }
151             }
152             return 0;
153         }
154
155         function Main() {
156             test_return();
157             test_break();
158             test_fallthrough();
159             test_exception();
160             test_exception2();
161             test_exception3();
162             test_empty();
163             test_mixed();
164             trace("[exit]");
165         }
166     }
167 }