Commit 1d7cd306 authored by rossberg@chromium.org's avatar rossberg@chromium.org

Parser sync tests for `let` identifiers

R=marja@chromium.org
BUG=

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22324 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent e274edc8
......@@ -2013,6 +2013,7 @@ Block* Parser::ParseVariableDeclarations(
is_const = true;
needs_init = true;
} else if (peek() == Token::LET && strict_mode() == STRICT) {
ASSERT(allow_harmony_scoping());
Consume(Token::LET);
if (var_context == kStatement) {
// Let declarations are only allowed in source element positions.
......@@ -3052,6 +3053,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
init = variable_statement;
}
} else if (peek() == Token::LET && strict_mode() == STRICT) {
ASSERT(allow_harmony_scoping());
const AstRawString* name = NULL;
VariableDeclarationProperties decl_props = kHasNoInitializers;
Block* variable_statement =
......
......@@ -1749,9 +1749,43 @@ TEST(ErrorsReservedWords) {
}
TEST(NoErrorsLetSloppyAllModes) {
// In sloppy mode, it's okay to use "let" as identifier.
const char* context_data[][2] = {
{ "", "" },
{ "function f() {", "}" },
{ "(function f() {", "})" },
{ NULL, NULL }
};
const char* statement_data[] = {
"var let;",
"var foo, let;",
"try { } catch (let) { }",
"function let() { }",
"(function let() { })",
"function foo(let) { }",
"function foo(bar, let) { }",
"let = 1;",
"var foo = let = 1;",
"let * 2;",
"++let;",
"let++;",
"let: 34",
"function let(let) { let: let(let + let(0)); }",
"({ let: 1 })",
"({ get let() { 1 } })",
"let(100)",
NULL
};
RunParserSyncTest(context_data, statement_data, kSuccess);
}
TEST(NoErrorsYieldSloppyAllModes) {
// In sloppy mode, it's okay to use "yield" as identifier, *except* inside a
// generator (see next test).
// generator (see other test).
const char* context_data[][2] = {
{ "", "" },
{ "function not_gen() {", "}" },
......@@ -1769,19 +1803,19 @@ TEST(NoErrorsYieldSloppyAllModes) {
"function foo(bar, yield) { }",
"yield = 1;",
"var foo = yield = 1;",
"yield * 2;",
"++yield;",
"yield++;",
"yield: 34",
"function yield(yield) { yield: yield (yield + yield (0)); }",
"function yield(yield) { yield: yield (yield + yield(0)); }",
"({ yield: 1 })",
"({ get yield() { 1 } })",
"yield (100)",
"yield(100)",
"yield[100]",
NULL
};
static const ParserFlag always_flags[] = {kAllowArrowFunctions};
RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
always_flags, ARRAY_SIZE(always_flags));
RunParserSyncTest(context_data, statement_data, kSuccess);
}
......@@ -1809,20 +1843,20 @@ TEST(NoErrorsYieldSloppyGeneratorsEnabled) {
"(function * yield() { })",
"yield = 1;",
"var foo = yield = 1;",
"yield * 2;",
"++yield;",
"yield++;",
"yield: 34",
"function yield(yield) { yield: yield (yield + yield (0)); }",
"function yield(yield) { yield: yield (yield + yield(0)); }",
"({ yield: 1 })",
"({ get yield() { 1 } })",
"yield (100)",
"yield(100)",
"yield[100]",
NULL
};
// This test requires kAllowGenerators to succeed.
static const ParserFlag always_true_flags[] = {
kAllowGenerators
};
static const ParserFlag always_true_flags[] = { kAllowGenerators };
RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
always_true_flags, 1);
}
......
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