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

Unified Diff: test/mjsunit/harmony/sloppy-restrictive-block-function.js

Issue 1757543003: Restrict FunctionDeclarations in Statement position (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: ignition failure expectation Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: test/mjsunit/harmony/sloppy-restrictive-block-function.js
diff --git a/test/mjsunit/harmony/sloppy-restrictive-block-function.js b/test/mjsunit/harmony/sloppy-restrictive-block-function.js
new file mode 100644
index 0000000000000000000000000000000000000000..2c75d81b8dedd39c6b43fc1c0ad6d0539eafa69e
--- /dev/null
+++ b/test/mjsunit/harmony/sloppy-restrictive-block-function.js
@@ -0,0 +1,99 @@
+// 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: --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() {
+ if (false) function f() { };
+ assertEquals(undefined, f);
+})();
+
+assertThrows(`
+ function() {
+ 'use strict';
+ if (true) function foo() {}
+ }
+`, SyntaxError);
+
+// In the spec-compliant mode, legacy features of allowing function
+// declarations as the body of various constructs is disallowed.
+assertThrows(`
+ for (;false;) function f() { };
+`, SyntaxError);
+
+assertThrows(`
+ for (var x in {}) function f() { };
+`, SyntaxError);
+
+assertThrows(`
+ for (x in {}) function f() { };
+`, SyntaxError);
+
+assertThrows(`
+ for (var i = 0; i < 1; i++) function f() { };
+`, SyntaxError);
+
+assertThrows(`
+ for (var x in {a: 1}) function f() { };
+`, SyntaxError);
+
+assertThrows(`
+ for (x in {a: 1}) function f() { };
+`, SyntaxError);
+
+assertThrows(`
+ with ({}) function f() { };
+`, SyntaxError);
+
+assertThrows(`
+ do function foo() {} while (0);
+`, SyntaxError);
+
+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);

Powered by Google App Engine
This is Rietveld 408576698