Debian Codegraph @

js/src/tests/test262/language/statements/try/S12.14_A13_T3.js

raw
1 // Copyright 2009 the Sputnik authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 info: Using "try" with "catch" or "finally" statement with a "return" statement
6 es5id: 12.14_A13_T3
7 description: Using try/catch/finally syntax construction
8 ---*/
9
10 // CHECK#1
11 var c1=0;
12 function myFunction1(){
13 try{
14 return 1;
15 }catch(err){
16 throw new Test262Error('#1.1: "return 1" inside function does not lead to throwing exception');
17 return 0;
18 }finally{
19 c1=1;
20 }
21 return 2;
22 }
23 var x1=myFunction1();
24 if(x1!==1){
25 throw new Test262Error('#1.3: x1===1. Actual: x1==='+x1);
26 }
27 if (c1!==1){
28 throw new Test262Error('#1.4: "finally" block must be evaluated');
29 }
30
31 // CHECK#2
32 var c2=0;
33 function myFunction2(){
34 try{
35 throw "exc";
36 return 1;
37 }catch(err){
38 return 0;
39 }finally{
40 c2=1;
41 }
42 return 2;
43 }
44 var x2=myFunction2();
45 if (c2!==1){
46 throw new Test262Error('#2.1: "finally" block must be evaluated');
47 }
48 if (x2!==0){
49 throw new Test262Error('#2.2: x2===0. Actual: x2==='+x2);
50 }
51
52 // CHECK#3
53 var c3=0;
54 function myFunction3(){
55 try{
56 return someValue;
57 }catch(err){
58 return 1;
59 }finally{
60 c3=1;
61 }
62 return 2;
63 }
64 var x3=myFunction3();
65 if (c3!==1){
66 throw new Test262Error('#3.1: "finally" block must be evaluated');
67 }
68 if (x3!==1){
69 throw new Test262Error('#3.2: x3===1. Actual: x3==='+x3);
70 }
71
72 // CHECK#4
73 var c4=0;
74 function myFunction4(){
75 try{
76 throw "ex1";
77 return 1;
78 }catch(err){
79 throw "ex2"
80 return 0;
81 }finally{
82 c4=1;
83 }
84 return 2;
85 }
86 try{
87 var x4=myFunction4();
88 throw new Test262Error('#4.1: Throwing exception inside function lead to throwing exception outside this function');
89 }
90 catch(e){
91 if(e==="ex1"){
92 throw new Test262Error('#4.2: Exception !== "ex1". Actual: catch previous exception');
93 }
94 if(e!=="ex2"){
95 throw new Test262Error('#4.3: Exception === "ex2". Actual: Exception ==='+ e );
96 }
97 if (c4!==1){
98 throw new Test262Error('#4.4: "finally" block must be evaluated');
99 }
100 }
101
102 // CHECK#5
103 var c5=0;
104 function myFunction5(){
105 try{
106 throw "ex1";
107 return 1;
108 }catch(err){
109 return 0;
110 }finally{
111 c5=1;
112 throw "ex2";
113 }
114 return 2;
115 }
116 try{
117 var x5=myFunction5();
118 throw new Test262Error('#5.1: Throwing exception inside function lead to throwing exception outside this function');
119 }
120 catch(e){
121 if(e==="ex1"){
122 throw new Test262Error('#5.2: Exception !== "ex1". Actual: catch previous exception');
123 }
124 if(e!=="ex2"){
125 throw new Test262Error('#5.3: Exception === "ex2". Actual: Exception ==='+ e );
126 }
127 if (c5!==1){
128 throw new Test262Error('#5.4: "finally" block must be evaluated');
129 }
130 }
131
132 // CHECK#6
133 var c6=0;
134 function myFunction6(){
135 try{
136 throw "ex1";
137 return 1;
138 }catch(err){
139 throw "ex2";
140 return 0;
141 }finally{
142 c6=1;
143 throw "ex3";
144 }
145 return 2;
146 }
147 try{
148 var x6=myFunction6();
149 throw new Test262Error('#6.1: Throwing exception inside function lead to throwing exception outside this function');
150 }
151 catch(e){
152 if(e==="ex1"){
153 throw new Test262Error('#6.2: Exception !== "ex1". Actual: catch previous exception');
154 }
155 if(e==="ex2"){
156 throw new Test262Error('#6.3: Exception !== "ex2". Actual: catch previous exception');
157 }
158 if(e!=="ex3"){
159 throw new Test262Error('#6.4: Exception === "ex3". Actual: Exception ==='+ e );
160 }
161 if(c6!==1) throw new Test262Error('#6.5: "finally" block must be evaluated');
162 }
163
164 // CHECK#7
165 var c7=0;
166 function myFunction7(){
167 try{
168 throw "ex1";
169 return 1;
170 }catch(err){
171 throw "ex2";
172 return 0;
173 }finally{
174 c7=1;
175 return 2;
176 }
177 return 3;
178 }
179 try{
180 var x7=myFunction7();
181 if(x7!==2) throw new Test262Error('#7.1: x7===2. Actual: x7==='+x7);
182 }
183 catch(e){}
184 if(c7!==1) throw new Test262Error('#7.2: "finally" block must be evaluated');
185
186 reportCompare(0, 0);