Commit a8289230 authored by dslomov's avatar dslomov Committed by Commit bot

Fix test for function declarations syntax error.

Also fix parsing of declarations after case labels.

R=waldron.rick@gmail.com,rossberg@chromium.org
BUG=v8:3939
LOG=N

Review URL: https://codereview.chromium.org/964063003

Cr-Commit-Position: refs/heads/master@{#27189}
parent 3fcb38f7
......@@ -2777,8 +2777,8 @@ Statement* Parser::ParseWithStatement(ZoneList<const AstRawString*>* labels,
CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) {
// CaseClause ::
// 'case' Expression ':' Statement*
// 'default' ':' Statement*
// 'case' Expression ':' StatementList
// 'default' ':' StatementList
Expression* label = NULL; // NULL expression indicates default case
if (peek() == Token::CASE) {
......@@ -2800,7 +2800,7 @@ CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) {
while (peek() != Token::CASE &&
peek() != Token::DEFAULT &&
peek() != Token::RBRACE) {
Statement* stat = ParseStatement(NULL, CHECK_OK);
Statement* stat = ParseStatementListItem(CHECK_OK);
statements->Add(stat, zone());
}
......
......@@ -674,7 +674,7 @@ PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) {
while (token != Token::CASE &&
token != Token::DEFAULT &&
token != Token::RBRACE) {
ParseStatement(CHECK_OK);
ParseStatementListItem(CHECK_OK);
token = peek();
}
}
......
......@@ -2957,6 +2957,36 @@ TEST(StrictDelete) {
}
TEST(NoErrorsDeclsInCase) {
const char* context_data[][2] = {
{"'use strict'; switch(x) { case 1:", "}"},
{"function foo() {'use strict'; switch(x) { case 1:", "}}"},
{"'use strict'; switch(x) { case 1: case 2:", "}"},
{"function foo() {'use strict'; switch(x) { case 1: case 2:", "}}"},
{"'use strict'; switch(x) { default:", "}"},
{"function foo() {'use strict'; switch(x) { default:", "}}"},
{"'use strict'; switch(x) { case 1: default:", "}"},
{"function foo() {'use strict'; switch(x) { case 1: default:", "}}"},
{ nullptr, nullptr }
};
const char* statement_data[] = {
"function f() { }",
"class C { }",
"class C extends Q {}",
"function f() { } class C {}",
"function f() { }; class C {}",
"class C {}; function f() {}",
nullptr
};
static const ParserFlag always_flags[] = {kAllowHarmonyClasses};
RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
always_flags, arraysize(always_flags));
}
TEST(InvalidLeftHandSide) {
const char* assignment_context_data[][2] = {
{"", " = 1;"},
......
......@@ -68,8 +68,8 @@ TestLocalThrows("do let x; while (false)", SyntaxError);
TestLocalThrows("while (false) let x;", SyntaxError);
TestLocalThrows("label: let x;", SyntaxError);
TestLocalThrows("for (;false;) let x;", SyntaxError);
TestLocalThrows("switch (true) { case true: let x; }", SyntaxError);
TestLocalThrows("switch (true) { default: let x; }", SyntaxError);
TestLocalDoesNotThrow("switch (true) { case true: let x; }");
TestLocalDoesNotThrow("switch (true) { default: let x; }");
// Test const declarations with initialisers in statement positions.
TestLocalThrows("if (true) const x = 1;", SyntaxError);
......@@ -78,8 +78,8 @@ TestLocalThrows("do const x = 1; while (false)", SyntaxError);
TestLocalThrows("while (false) const x = 1;", SyntaxError);
TestLocalThrows("label: const x = 1;", SyntaxError);
TestLocalThrows("for (;false;) const x = 1;", SyntaxError);
TestLocalThrows("switch (true) { case true: const x = 1; }", SyntaxError);
TestLocalThrows("switch (true) { default: const x = 1; }", SyntaxError);
TestLocalDoesNotThrow("switch (true) { case true: const x = 1; }");
TestLocalDoesNotThrow("switch (true) { default: const x = 1; }");
// Test const declarations without initialisers.
TestLocalThrows("const x;", SyntaxError);
......@@ -147,11 +147,11 @@ function f() {
f();
// Test function declarations in statement position in strict mode.
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);
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);
TestLocalDoesNotThrow("function f() { switch (true) { case true: function g() {} } }");
TestLocalDoesNotThrow("function f() { switch (true) { default: function g() {} } }");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment