Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Side by Side Diff: test/mjsunit/harmony/block-leave.js

Issue 7792100: Simplfy handling of exits from scoped blocks. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/parser.cc ('K') | « src/parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 // Flags: --harmony-block-scoping
29
30 // We want to test the context chain shape. In each of the tests cases
31 // below, the outer with is to force a runtime lookup of the identifier 'x'
32 // to actually verify that the inner context has been discarded. A static
33 // lookup of 'x' might accidentally succeed.
34
35 {
36 let x = 2;
37 L: {
38 let x = 3;
39 assertEquals(3, x);
40 break L;
41 assertTrue(false);
42 }
43 assertEquals(2, x);
44 }
45
46 do {
47 let x = 4;
48 assertEquals(4,x);
49 {
50 let x = 5;
51 assertEquals(5, x);
52 continue;
53 assertTrue(false);
54 }
55 } while (false);
56
57 var caught = false;
58 try {
59 {
60 let xx = 18;
61 throw 25;
62 assertTrue(false);
63 }
64 } catch (e) {
65 caught = true;
66 assertEquals(25, e);
67 with ({y:19}) {
68 assertEquals(19, y);
69 try {
70 // NOTE: This checks that the block scope containing xx has been
71 // removed from the context chain.
72 xx;
73 assertTrue(false); // should not reach here
74 } catch (e2) {
75 assertTrue(e2 instanceof ReferenceError);
76 }
77 }
78 }
79 assertTrue(caught);
80
81
82 with ({x: 'outer'}) {
83 label: {
84 let x = 'inner';
85 break label;
86 }
87 assertEquals('outer', x);
88 }
89
90
91 with ({x: 'outer'}) {
92 label: {
93 let x = 'middle';
94 {
95 let x = 'inner';
96 break label;
97 }
98 }
99 assertEquals('outer', x);
100 }
101
102
103 with ({x: 'outer'}) {
104 for (var i = 0; i < 10; ++i) {
105 let x = 'inner' + i;
106 continue;
107 }
108 assertEquals('outer', x);
109 }
110
111
112 with ({x: 'outer'}) {
113 label: for (var i = 0; i < 10; ++i) {
114 let x = 'middle' + i;
115 for (var j = 0; j < 10; ++j) {
116 let x = 'inner' + j;
117 continue label;
118 }
119 }
120 assertEquals('outer', x);
121 }
122
123
124 with ({x: 'outer'}) {
125 try {
126 let x = 'inner';
127 throw 0;
128 } catch (e) {
129 assertEquals('outer', x);
130 }
131 }
132
133
134 with ({x: 'outer'}) {
135 try {
136 let x = 'middle';
137 {
138 let x = 'inner';
139 throw 0;
140 }
141 } catch (e) {
142 assertEquals('outer', x);
143 }
144 }
145
146
147 try {
148 with ({x: 'outer'}) {
149 try {
150 let x = 'inner';
151 throw 0;
152 } finally {
153 assertEquals('outer', x);
154 }
155 }
156 } catch (e) {
157 if (e instanceof MjsUnitAssertionError) throw e;
158 }
159
160
161 try {
162 with ({x: 'outer'}) {
163 try {
164 let x = 'middle';
165 {
166 let x = 'inner';
167 throw 0;
168 }
169 } finally {
170 assertEquals('outer', x);
171 }
172 }
173 } catch (e) {
174 if (e instanceof MjsUnitAssertionError) throw e;
175 }
176
177
178 // Verify that the context is correctly set in the stack frame after exiting
179 // from with.
180 function f() {}
181
182 with ({x: 'outer'}) {
183 label: {
184 let x = 'inner';
185 break label;
186 }
187 f(); // The context could be restored from the stack after the call.
188 assertEquals('outer', x);
189 }
190
191
192 with ({x: 'outer'}) {
193 for (var i = 0; i < 10; ++i) {
194 let x = 'inner';
195 continue;
196 }
197 f();
198 assertEquals('outer', x);
199 }
200
201
202 with ({x: 'outer'}) {
203 try {
204 let x = 'inner';
205 throw 0;
206 } catch (e) {
207 f();
208 assertEquals('outer', x);
209 }
210 }
211
212
213 try {
214 with ({x: 'outer'}) {
215 try {
216 let x = 'inner';
217 throw 0;
218 } finally {
219 f();
220 assertEquals('outer', x);
221 }
222 }
223 } catch (e) {
224 if (e instanceof MjsUnitAssertionError) throw e;
225 }
OLDNEW
« src/parser.cc ('K') | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698