blob: da434306472ed5b5bde3722d783a6100f330abd7 [file] [log] [blame]
saambarati1@gmail.come4556722015-07-19 16:57:44 +00001"use strict";
2
3function truth() {
4 return true;
5}
6noInline(truth);
7
8function assert(cond) {
9 if (!cond)
10 throw new Error("broke assertion");
11}
12noInline(assert);
13
14// Tests
15
16
saambarati1@gmail.comd5293a62015-07-27 23:04:43 +000017const NUM_LOOPS = 100;
saambarati1@gmail.come4556722015-07-19 16:57:44 +000018
19;(function () {
20function foo() {
21 const x = 20;
22 const y = "y";
23 try {
24 assert(x === 20);
25 assert(y === "y");
26 throw "error";
27 } catch(e) {
28 assert(x === 20);
29 } finally {
30 assert(x === 20);
31 assert(y === "y");
32 }
33
34 for (let i = 0; i < 1; i++) {
35 let numFinally = 0;
36 try {
37 let a = 40;
38 let capA = function() { return a; }
39 assert(capA() === 40);
40 try {
41 const b = 41;
42 const capB = function() { return b; }
43 assert(capB() === 41);
44 assert(capA() === 40);
45 try {
46 return 20;
47 } catch(e){
48 } finally {
49 const c = 42;
50 const capC = function() { return c; }
51 assert(capC() === 42);
52 assert(capB() === 41);
53 assert(capA() === 40);
54 if (i === 0) {
55 numFinally++;
56 }
57 return 22;
58 }
59 } catch(e) {
60 } finally {
61 if (i === 0) {
62 numFinally++;
63 }
64 return 23;
65 }
66 } catch(e) {
67 } finally {
68 if (i === 0) {
69 numFinally++;
70 }
71 assert(numFinally === 3);
72 return 24;
73 }
74 }
75}
76
77for (var i = 0; i < NUM_LOOPS; i++) {
78 assert(foo() === 24);
79}
80
81})();
82
83
84;(function () {
85function foo() {
86 for (let i = 0; i < 1; i++) {
87 let numFinally = 0;
88 let numErrors = 0;
89 try {
90 let a = 40;
91 let capA = function() { return a; }
92 assert(capA() === 40);
93 try {
94 const b = 41;
95 const capB = function() { return b; }
96 assert(capB() === 41);
97 assert(capA() === 40);
98 try {
99 throw "e";
100 } catch(e) {
101 assert(i === 0);
102 assert(capB() === 41);
103 assert(capA() === 40);
104 numErrors++;
105 throw e;
106 } finally {
107 const c = 42;
108 const capC = function() { return c; }
109 const local = "local";
110 assert(local === "local");
111 assert(capC() === 42);
112 assert(capB() === 41);
113 assert(capA() === 40);
114 if (i === 0) {
115 numFinally++;
116 }
117 }
118 } catch(e) {
119 assert(i === 0);
120 assert(capA() === 40);
121 numErrors++;
122 const local = "local";
123 assert(local === "local");
124 } finally {
125 assert(capA() === 40);
126 if (i === 0) {
127 numFinally++;
128 }
129 const local = "local";
130 assert(local === "local");
131 return 23;
132 }
133 } catch(e) {
134 //assert(i === 0);
135 } finally {
136 if (i === 0) {
137 numFinally++;
138 }
139
140 assert(numFinally === 3);
141 assert(numErrors === 2);
142 return 24;
143 }
144 }
145}
146
147for (var i = 0; i < NUM_LOOPS; i++) {
148 assert(foo() === 24);
149}
150
151})();
152
153
154var d = 100;
155;(function (){
156function foo() {
157 assert(d === 100);
158 for (let i = 0; i < 1; i++) {
159 let numFinally = 0;
160 let numErrors = 0;
161 const c = 44;
162 assert(d === 100);
163 try {
164 const d = 45;
165 if (truth()) {
166 const a = 20;
167 const capA = function() { return a; }
168 assert(capA() === 20);
169 if (truth()) {
170 const b = 21;
171 const e = 48;
172 const capB = function() { return b; }
173 assert(capB() === 21);
174 assert(d === 45);
175 try {
176 throw "e";
177 } catch(e) {
178 assert(capA() === 20);
179 assert(a === 20);
180 numErrors++;
181 } finally {
182 assert(capA() === 20);
183 assert(e === 48);
184 numFinally++;
185 return 30;
186 }
187 }
188 }
189 } finally {
190 assert(c === 44);
191 assert(d === 100);
192 numFinally++;
193 assert(numFinally === 2);
194 assert(numErrors === 1);
195 return 40;
196 }
197 }
198}
199
200for (var i = 0; i < NUM_LOOPS; i++) {
201 assert(foo() === 40);
202}
203
204})();