From f93c69308f39846d3303dd82befc1319584cc158 Mon Sep 17 00:00:00 2001 From: "keuchel@chromium.org" Date: Mon, 17 Oct 2011 11:59:08 +0000 Subject: [PATCH] Disallow function declarations in statement positions in harmony mode. Review URL: http://codereview.chromium.org/8306025 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9657 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/parser.cc | 2 +- src/preparser.cc | 2 +- test/mjsunit/harmony/block-let-declaration.js | 25 ++++++++----------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/parser.cc b/src/parser.cc index dc8cec2..6df216d 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::empty()); *ok = false; diff --git a/src/preparser.cc b/src/preparser.cc index 9f8e1ee..beb868c 100644 --- a/src/preparser.cc +++ b/src/preparser.cc @@ -240,7 +240,7 @@ PreParser::Statement PreParser::ParseStatement(bool* ok) { i::Scanner::Location start_location = scanner_->peek_location(); Statement statement = ParseFunctionDeclaration(CHECK_OK); i::Scanner::Location end_location = scanner_->location(); - if (strict_mode()) { + if (strict_mode() || harmony_scoping_) { ReportMessageAt(start_location.beg_pos, end_location.end_pos, "strict_function", NULL); *ok = false; diff --git a/test/mjsunit/harmony/block-let-declaration.js b/test/mjsunit/harmony/block-let-declaration.js index 7f3264f..e43e62b 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); -- 2.7.4