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

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

Issue 1376623002: Extend Annex B 3.3 sloppy-mode block-scoped hoisting to scripts, eval (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Tests, many of which fail Created 5 years, 2 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
« no previous file with comments | « 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
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --no-legacy-const --harmony-sloppy --harmony-sloppy-let 5 // Flags: --no-legacy-const --harmony-sloppy --harmony-sloppy-let
6 // Flags: --harmony-sloppy-function --harmony-destructuring 6 // Flags: --harmony-sloppy-function --harmony-destructuring
7 // Flags: --harmony-rest-parameters 7 // Flags: --harmony-rest-parameters
8 8
9 // Test Annex B 3.3 semantics for functions declared in blocks in sloppy mode. 9 // Test Annex B 3.3 semantics for functions declared in blocks in sloppy mode.
10 // http://www.ecma-international.org/ecma-262/6.0/#sec-block-level-function-decl arations-web-legacy-compatibility-semantics 10 // http://www.ecma-international.org/ecma-262/6.0/#sec-block-level-function-decl arations-web-legacy-compatibility-semantics
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 139 }
140 assertEquals(2, f()); 140 assertEquals(2, f());
141 L: { 141 L: {
142 assertEquals(3, f()); 142 assertEquals(3, f());
143 break L; 143 break L;
144 function f() { return 3; } 144 function f() { return 3; }
145 } 145 }
146 assertEquals(2, f()); 146 assertEquals(2, f());
147 })(); 147 })();
148 148
149 // Test that hoisting from blocks doesn't happen in global scope
150 function globalUnhoisted() { return 0; }
151 {
152 function globalUnhoisted() { return 1; }
153 }
154 assertEquals(0, globalUnhoisted());
155
156 // Test that shadowing arguments is fine 149 // Test that shadowing arguments is fine
157 (function shadowArguments(x) { 150 (function shadowArguments(x) {
158 assertArrayEquals([1], arguments); 151 assertArrayEquals([1], arguments);
159 { 152 {
160 assertEquals('function', typeof arguments); 153 assertEquals('function', typeof arguments);
161 function arguments() {} 154 function arguments() {}
162 assertEquals('function', typeof arguments); 155 assertEquals('function', typeof arguments);
163 } 156 }
164 assertEquals('function', typeof arguments); 157 assertEquals('function', typeof arguments);
165 })(1); 158 })(1);
(...skipping 28 matching lines...) Expand all
194 // assertEquals('function', typeof x); 187 // assertEquals('function', typeof x);
195 })(1); 188 })(1);
196 189
197 assertThrows(function notInDefaultScope(x = y) { 190 assertThrows(function notInDefaultScope(x = y) {
198 { 191 {
199 function y() {} 192 function y() {}
200 } 193 }
201 assertEquals('function', typeof y); 194 assertEquals('function', typeof y);
202 assertEquals(x, undefined); 195 assertEquals(x, undefined);
203 }, ReferenceError); 196 }, ReferenceError);
197
198 // Test that hoisting from blocks does happen in global scope
199 function globalHoisted() { return 0; }
200 {
201 function globalHoisted() { return 1; }
202 }
203 assertEquals(1, globalHoisted());
204
205 // Also happens when not previously defined
206 assertEquals(undefined, globalUndefinedHoisted);
207 {
208 function globalUndefinedHoisted() { return 1; }
209 }
210 assertEquals(1, globalUndefinedHoisted());
211 var globalUndefinedHoistedDescriptor =
212 Object.getOwnPropertyDescriptor(this, "globalUndefinedHoisted");
213 // Configurablility is not set properly BUG(v8:4451#1)
214 // assertTrue(globalUndefinedHoistedDescriptor.configurable);
adamk 2015/09/30 18:24:26 Please leave this uncommented (with the current be
Dan Ehrenberg 2015/09/30 23:06:55 Done
215 assertTrue(globalUndefinedHoistedDescriptor.writable);
216 assertTrue(globalUndefinedHoistedDescriptor.enumerable);
217 assertEquals(1, globalUndefinedHoistedDescriptor.value());
218
219 // When a function property is hoisted, it should be
220 // made enumerable.
221 // BUG(v8:4451)
222 Object.defineProperty(this, "globalNonEnumerable", {
223 value: false,
224 configurable: true,
225 writable: true,
226 enumerable: false
227 });
228 eval("{function globalNonEnumerable() { return 1; }}");
229 var globalNonEnumerableDescriptor
230 = Object.getOwnPropertyDescriptor(this, "globalNonEnumerable");
231 assertTrue(globalNonEnumerableDescriptor.configurable);
232 assertTrue(globalNonEnumerableDescriptor.writable);
233 // BUG(v8:4451)
234 // assertTrue(globalNonEnumerableDescriptor.enumerable);
adamk 2015/09/30 18:24:26 Same here.
Dan Ehrenberg 2015/09/30 23:06:55 Done
235 assertEquals(1, globalNonEnumerableDescriptor.value());
236
237 // Test that hoisting from blocks does happen in an eval
238 eval(`
239 function evalHoisted() { return 0; }
240 {
241 function evalHoisted() { return 1; }
242 }
243 assertEquals(1, evalHoisted());
244 `);
245
246 // Test that hoisting from blocks happens from eval in a function
247 !function() {
248 eval(`
249 function evalInFunctionHoisted() { return 0; }
250 {
251 function evalInFunctionHoisted() { return 1; }
252 }
253 assertEquals(1, evalInFunctionHoisted());
254 `);
255 }();
256
257 // When the global object is frozen, silently don't hoist
258 // Currently this actually throws BUG(v8:4452)
adamk 2015/09/30 18:24:26 Ah, this throws because it goes through the define
Dan Ehrenberg 2015/09/30 23:06:55 I guess it matches, but still, we eventually want
259 // Object.freeze(this);
260 // eval(`
261 // {
262 // function hoistWhenFrozen() {}
263 // }
264 // `);
265 // assertFalse(this.hasOwnProperty("hoistWhenFrozen"));
266 assertThrows(() => hoistWhenFrozen, ReferenceError);
267
268 let dontHoistGlobal;
269 { function dontHoistGlobal() {} }
270 assertEquals(undefined, dontHoistGlobal);
271
272 let dontHoistEval;
273 // OK, this really needs to be fixed...
adamk 2015/09/30 18:24:26 Yeah, this needs to be fixed before landing.
Dan Ehrenberg 2015/09/30 23:06:55 We talked about this off-line and it sounded like
274 // eval("{ function dontHoistEval() {} }");
275 // assertEquals(undefined, dontHoistEval);
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698