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

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

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

Powered by Google App Engine
This is Rietveld 408576698