Reviewers: Lasse Reichstein,
Message:
Disallowing
for (..) function foo {}
in harmony mode. Please take a look. This is a prerequisite for
http://codereview.chromium.org/7837028
Description:
Disallow function declarations in statement positions in harmony mode.
Please review this at http://codereview.chromium.org/8306025/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/parser.cc
M test/mjsunit/harmony/block-let-declaration.js
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index
dc8cec240fa8f9329519eafacd6c9f7b71c2e107..6df216dc32c4d4406086f98fc84e511afcb32b98
100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -1334,7 +1334,7 @@ Statement* Parser::ParseStatement(ZoneStringList*
labels, bool* ok) {
// FunctionDeclaration
// Common language extension is to allow function declaration in
place
// of any statement. This language extension is disabled in strict
mode.
- if (top_scope_->is_strict_mode()) {
+ if (top_scope_->is_strict_mode() || harmony_scoping_) {
ReportMessageAt(scanner().peek_location(), "strict_function",
Vector<const char*>::empty());
*ok = false;
Index: test/mjsunit/harmony/block-let-declaration.js
diff --git a/test/mjsunit/harmony/block-let-declaration.js
b/test/mjsunit/harmony/block-let-declaration.js
index
7f3264f257fedd68f8669719ba99e4e580bab9e8..e43e62b044959530f5600c11f3b64599dfa04f88
100644
--- a/test/mjsunit/harmony/block-let-declaration.js
+++ b/test/mjsunit/harmony/block-let-declaration.js
@@ -93,24 +93,15 @@ function f() {
{
function g1() { }
}
- // Non-strict statement positions.
- if (true) function g2() { }
- if (true) {} else function g3() { }
- do function g4() { } while (false)
- while (false) function g5() { }
- label: function g6() { }
- for (;false;) function g7() { }
- switch (true) { case true: function g8() { } }
- switch (true) { default: function g9() { } }
}
f();
// Test function declarations in statement position in strict mode.
-TestLocalThrows("function f() { 'use strict'; if (true) function g() {}",
SyntaxError);
-TestLocalThrows("function f() { 'use strict'; if (true) {} else function
g() {}", SyntaxError);
-TestLocalThrows("function f() { 'use strict'; do function g() {} while
(false)", SyntaxError);
-TestLocalThrows("function f() { 'use strict'; while (false) function g()
{}", SyntaxError);
-TestLocalThrows("function f() { 'use strict'; label: function g() {}",
SyntaxError);
-TestLocalThrows("function f() { 'use strict'; for (;false;) function g()
{}", SyntaxError);
-TestLocalThrows("function f() { 'use strict'; switch (true) { case true:
function g() {} }", SyntaxError);
-TestLocalThrows("function f() { 'use strict'; switch (true) { default:
function g() {} }", SyntaxError);
+TestLocalThrows("function f() { if (true) function g() {}", SyntaxError);
+TestLocalThrows("function f() { if (true) {} else function g() {}",
SyntaxError);
+TestLocalThrows("function f() { do function g() {} while (false)",
SyntaxError);
+TestLocalThrows("function f() { while (false) function g() {}",
SyntaxError);
+TestLocalThrows("function f() { label: function g() {}", SyntaxError);
+TestLocalThrows("function f() { for (;false;) function g() {}",
SyntaxError);
+TestLocalThrows("function f() { switch (true) { case true: function g() {}
}", SyntaxError);
+TestLocalThrows("function f() { switch (true) { default: function g() {}
}", SyntaxError);
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev