Chromium Code Reviews| Index: test/mjsunit/harmony/sloppy-implicit-block-function.js |
| diff --git a/test/mjsunit/harmony/sloppy-implicit-block-function.js b/test/mjsunit/harmony/sloppy-implicit-block-function.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9bdce9c693273b26dd615b27232150d6c3594c8c |
| --- /dev/null |
| +++ b/test/mjsunit/harmony/sloppy-implicit-block-function.js |
| @@ -0,0 +1,109 @@ |
| +// Copyright 2016 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Flags: --no-harmony-restrictive-declarations |
| + |
| +// ES#sec-functiondeclarations-in-ifstatement-statement-clauses |
| +// Annex B 3.4 FunctionDeclarations in IfStatement Statement Clauses |
| +// In sloppy mode, function declarations in if statements act like |
| +// they have a block around them. Prohibited in strict mode. |
| +(function() { |
|
adamk
2016/03/02 00:33:45
Maybe add assertEquals(undefined, f) before the if
Dan Ehrenberg
2016/03/02 00:49:54
Done
|
| + if (false) function f() { }; |
|
adamk
2016/03/02 00:33:45
What about if (true)? I assume that results in the
Dan Ehrenberg
2016/03/02 00:49:54
Good point, added tests for this, and for the 'els
|
| + assertEquals(undefined, f); |
| +})(); |
| + |
| +assertThrows(` |
| + function() { |
| + 'use strict'; |
| + if (true) function foo() {} |
| + } |
| +`, SyntaxError); |
|
adamk
2016/03/02 00:51:10
All these parsing tests will better-exercise the p
Dan Ehrenberg
2016/03/03 02:32:57
Oops, not sure how I completely forgot about the p
|
| + |
| +// For legacy reasons, we also support these types of semantics as |
| +// the body of a for or with statement. |
| +(function() { |
| + for (;false;) function f() { }; |
| + assertEquals(undefined, f); |
| +})(); |
| + |
| +(function() { |
| + for (var x in {}) function f() { }; |
| + assertEquals(undefined, f); |
| +})(); |
| + |
| +(function() { |
| + var x; |
| + for (x in {}) function f() { }; |
| + assertEquals(undefined, f); |
| +})(); |
| + |
| +(function() { |
| + for (var i = 0; i < 1; i++) function f() { }; |
| + assertEquals('function', typeof f); |
| +})(); |
| + |
| +(function() { |
| + for (var x in {a: 1}) function f() { }; |
| + assertEquals('function', typeof f); |
| +})(); |
| + |
| +(function() { |
| + var x; |
| + for (x in {a: 1}) function f() { }; |
| + assertEquals('function', typeof f); |
| +})(); |
| + |
| +(function() { |
| + with ({}) function f() { }; |
| + assertEquals('function', typeof f); |
| +})(); |
| + |
| +(function() { |
| + do function f() {} while (0); |
| + assertEquals('function', typeof f); |
| +})(); |
| + |
| +assertThrows(` |
| + function() { |
| + 'use strict'; |
| + for (;false;) function foo() {} |
| + } |
| +`, SyntaxError); |
| + |
| +assertThrows(` |
| + function() { |
| + 'use strict'; |
| + for (var x in {}) function foo() {} |
| + } |
| +`, SyntaxError); |
| + |
| +assertThrows(` |
| + function() { |
| + 'use strict'; |
| + var x; |
| + for (x in {}) function foo() {} |
| + } |
| +`, SyntaxError); |
| + |
| +assertThrows(` |
| + function() { |
| + 'use strict'; |
| + do function foo() {} while (0); |
| + } |
| +`, SyntaxError); |
| + |
| +// Some contexts always throw for function declarations, even in sloppy mode |
| + |
| +assertThrows(` |
| + function() { |
| + try function foo() {} catch (e) {} |
| + } |
| +`, SyntaxError); |
| + |
| +assertThrows(` |
| + function() { |
| + 'use strict'; |
| + try function foo() {} catch (e) {} |
| + } |
| +`, SyntaxError); |