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

Unified Diff: test/cctest/test-parsing.cc

Issue 160073006: Implement handling of arrow functions in the parser (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Made tests more comprehensive Created 6 years, 6 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
« src/scanner.h ('K') | « src/token.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index 79b32e8000658b017723b2fc3260195189955419..51ba3030f067e279629dbf0b812b82a652839918 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -155,6 +155,7 @@ TEST(ScanHTMLEndComments) {
scanner.Initialize(&stream);
i::PreParser preparser(&scanner, &log, stack_limit);
preparser.set_allow_lazy(true);
+ preparser.set_allow_arrow_functions(true);
i::PreParser::PreParseResult result = preparser.PreParseProgram();
CHECK_EQ(i::PreParser::kPreParseSuccess, result);
i::ScriptData data(log.ExtractData());
@@ -170,6 +171,7 @@ TEST(ScanHTMLEndComments) {
scanner.Initialize(&stream);
i::PreParser preparser(&scanner, &log, stack_limit);
preparser.set_allow_lazy(true);
+ preparser.set_allow_arrow_functions(true);
i::PreParser::PreParseResult result = preparser.PreParseProgram();
// Even in the case of a syntax error, kPreParseSuccess is returned.
CHECK_EQ(i::PreParser::kPreParseSuccess, result);
@@ -194,6 +196,7 @@ class ScriptResource : public v8::String::ExternalAsciiStringResource {
TEST(UsingCachedData) {
+ i::FLAG_harmony_arrow_functions = true;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handles(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
@@ -241,6 +244,7 @@ TEST(PreparseFunctionDataIsUsed) {
// Make preparsing work for short scripts.
i::FLAG_min_preparse_length = 0;
+ i::FLAG_harmony_arrow_functions = true;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handles(isolate);
@@ -250,31 +254,38 @@ TEST(PreparseFunctionDataIsUsed) {
CcTest::i_isolate()->stack_guard()->SetStackLimit(
reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
- const char* good_code =
- "function this_is_lazy() { var a; } function foo() { return 25; } foo();";
+ const char* good_code[] = {
+ "function this_is_lazy() { var a; } function foo() { return 25; } foo();",
+ NULL
+ };
// Insert a syntax error inside the lazy function.
- const char* bad_code =
- "function this_is_lazy() { if ( } function foo() { return 25; } foo();";
+ const char* bad_code[] = {
+ "function this_is_lazy() { if ( } function foo() { return 25; } foo();",
+ NULL
+ };
- v8::ScriptCompiler::Source good_source(v8_str(good_code));
- v8::ScriptCompiler::Compile(isolate, &good_source,
- v8::ScriptCompiler::kProduceDataToCache);
+ for (int i = 0; good_code[i]; i++) {
+ v8::ScriptCompiler::Source good_source(v8_str(good_code[i]));
+ v8::ScriptCompiler::Compile(isolate, &good_source,
+ v8::ScriptCompiler::kProduceDataToCache);
- const v8::ScriptCompiler::CachedData* cached_data =
- good_source.GetCachedData();
- CHECK(cached_data->data != NULL);
- CHECK_GT(cached_data->length, 0);
+ const v8::ScriptCompiler::CachedData* cached_data =
+ good_source.GetCachedData();
+ CHECK(cached_data->data != NULL);
+ CHECK_GT(cached_data->length, 0);
- // Now compile the erroneous code with the good preparse data. If the preparse
- // data is used, the lazy function is skipped and it should compile fine.
- v8::ScriptCompiler::Source bad_source(
- v8_str(bad_code), new v8::ScriptCompiler::CachedData(
- cached_data->data, cached_data->length));
- v8::Local<v8::Value> result =
- v8::ScriptCompiler::Compile(isolate, &bad_source)->Run();
- CHECK(result->IsInt32());
- CHECK_EQ(25, result->Int32Value());
+ // Now compile the erroneous code with the good preparse data. If the
+ // preparse data is used, the lazy function is skipped and it should
+ // compile fine.
+ v8::ScriptCompiler::Source bad_source(
+ v8_str(bad_code[i]), new v8::ScriptCompiler::CachedData(
+ cached_data->data, cached_data->length));
+ v8::Local<v8::Value> result =
+ v8::ScriptCompiler::Compile(isolate, &bad_source)->Run();
+ CHECK(result->IsInt32());
+ CHECK_EQ(25, result->Int32Value());
+ }
}
@@ -291,6 +302,7 @@ TEST(StandAlonePreParser) {
"function foo(x, y) { return x + y; }",
"%ArgleBargle(glop);",
"var x = new new Function('this.x = 42');",
+ "var f = (x, y) => x + y;",
NULL
};
@@ -307,6 +319,7 @@ TEST(StandAlonePreParser) {
i::PreParser preparser(&scanner, &log, stack_limit);
preparser.set_allow_lazy(true);
preparser.set_allow_natives_syntax(true);
+ preparser.set_allow_arrow_functions(true);
i::PreParser::PreParseResult result = preparser.PreParseProgram();
CHECK_EQ(i::PreParser::kPreParseSuccess, result);
i::ScriptData data(log.ExtractData());
@@ -341,6 +354,7 @@ TEST(StandAlonePreParserNoNatives) {
// Preparser defaults to disallowing natives syntax.
i::PreParser preparser(&scanner, &log, stack_limit);
preparser.set_allow_lazy(true);
+ preparser.set_allow_arrow_functions(true);
i::PreParser::PreParseResult result = preparser.PreParseProgram();
CHECK_EQ(i::PreParser::kPreParseSuccess, result);
i::ScriptData data(log.ExtractData());
@@ -353,6 +367,7 @@ TEST(StandAlonePreParserNoNatives) {
TEST(PreparsingObjectLiterals) {
// Regression test for a bug where the symbol stream produced by PreParser
// didn't match what Parser wanted to consume.
+ i::FLAG_harmony_arrow_functions = true;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handles(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
@@ -411,6 +426,7 @@ TEST(RegressChromium62639) {
i::PreParser preparser(&scanner, &log,
CcTest::i_isolate()->stack_guard()->real_climit());
preparser.set_allow_lazy(true);
+ preparser.set_allow_arrow_functions(true);
i::PreParser::PreParseResult result = preparser.PreParseProgram();
// Even in the case of a syntax error, kPreParseSuccess is returned.
CHECK_EQ(i::PreParser::kPreParseSuccess, result);
@@ -445,6 +461,7 @@ TEST(Regress928) {
i::PreParser preparser(&scanner, &log,
CcTest::i_isolate()->stack_guard()->real_climit());
preparser.set_allow_lazy(true);
+ preparser.set_allow_arrow_functions(true);
i::PreParser::PreParseResult result = preparser.PreParseProgram();
CHECK_EQ(i::PreParser::kPreParseSuccess, result);
i::ScriptData data(log.ExtractData());
@@ -492,6 +509,7 @@ TEST(PreParseOverflow) {
i::PreParser preparser(&scanner, &log, stack_limit);
preparser.set_allow_lazy(true);
+ preparser.set_allow_arrow_functions(true);
i::PreParser::PreParseResult result = preparser.PreParseProgram();
CHECK_EQ(i::PreParser::kPreParseStackOverflow, result);
}
@@ -967,7 +985,13 @@ TEST(ScopePositions) {
" infunction;\n"
" }", "\n"
" more;", i::FUNCTION_SCOPE, i::SLOPPY },
- { " (function fun", "(a,b) { infunction; }", ")();",
+ // TODO(aperez): Change to use i::ARROW_SCOPE when implemented
+ { " start;\n", "(a,b) => a + b", "; more;",
+ i::FUNCTION_SCOPE, i::SLOPPY },
+ { " start;\n", "(a,b) => { return a+b; }", "\nmore;",
+ i::FUNCTION_SCOPE, i::SLOPPY },
+ { " start;\n"
+ " (function fun", "(a,b) { infunction; }", ")();",
i::FUNCTION_SCOPE, i::SLOPPY },
{ " for ", "(let x = 1 ; x < 10; ++ x) { block; }", " more;",
i::BLOCK_SCOPE, i::STRICT },
@@ -1122,6 +1146,7 @@ TEST(ScopePositions) {
i::Parser parser(&info);
parser.set_allow_lazy(true);
parser.set_allow_harmony_scoping(true);
+ parser.set_allow_arrow_functions(true);
info.MarkAsGlobal();
info.SetStrictMode(source_data[i].strict_mode);
parser.Parse();
@@ -1199,6 +1224,7 @@ void SetParserFlags(i::ParserBase<Traits>* parser,
parser->set_allow_for_of(flags.Contains(kAllowForOf));
parser->set_allow_harmony_numeric_literals(
flags.Contains(kAllowHarmonyNumericLiterals));
+ parser->set_allow_arrow_functions(i::FLAG_harmony_arrow_functions);
}
@@ -1317,6 +1343,8 @@ void TestParserSync(const char* source,
TEST(ParserSync) {
+ i::FLAG_harmony_arrow_functions = true;
+
const char* context_data[][2] = {
{ "", "" },
{ "{", "}" },
@@ -1438,6 +1466,8 @@ TEST(StrictOctal) {
// Test that syntax error caused by octal literal is reported correctly as
// such (issue 2220).
v8::V8::Initialize();
+ i::FLAG_harmony_arrow_functions = true;
+
v8::HandleScope scope(CcTest::isolate());
v8::Context::Scope context_scope(
v8::Context::New(CcTest::isolate()));
@@ -1526,6 +1556,10 @@ TEST(ErrorsEvalAndArguments) {
"function foo(arguments) { }",
"function foo(bar, eval) { }",
"function foo(bar, arguments) { }",
+ "(eval) => { }",
+ "(arguments) => { }",
+ "(foo, eval) => { }",
+ "(foo, arguments) => { }",
"eval = 1;",
"arguments = 1;",
"var foo = eval = 1;",
@@ -1537,6 +1571,7 @@ TEST(ErrorsEvalAndArguments) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kError);
}
@@ -1563,6 +1598,10 @@ TEST(NoErrorsEvalAndArgumentsSloppy) {
"function foo(arguments) { }",
"function foo(bar, eval) { }",
"function foo(bar, arguments) { }",
+ "(eval) => { }",
+ "(arguments) => { }",
+ "(bar, eval) => { }",
+ "(bar, arguments) => { }",
"eval = 1;",
"arguments = 1;",
"var foo = eval = 1;",
@@ -1574,6 +1613,7 @@ TEST(NoErrorsEvalAndArgumentsSloppy) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kSuccess);
}
@@ -1582,6 +1622,7 @@ TEST(NoErrorsEvalAndArgumentsStrict) {
const char* context_data[][2] = {
{ "\"use strict\";", "" },
{ "function test_func() { \"use strict\";", "}" },
+ { "() => { \"use strict\"; ", "}" },
{ NULL, NULL }
};
@@ -1597,6 +1638,7 @@ TEST(NoErrorsEvalAndArgumentsStrict) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kSuccess);
}
@@ -1609,6 +1651,7 @@ TEST(ErrorsFutureStrictReservedWords) {
const char* context_data[][2] = {
{ "\"use strict\";", "" },
{ "function test_func() {\"use strict\"; ", "}"},
+ { "() => { \"use strict\"; ", "}" },
{ NULL, NULL }
};
@@ -1619,6 +1662,8 @@ TEST(ErrorsFutureStrictReservedWords) {
"function interface() { }",
"function foo(interface) { }",
"function foo(bar, interface) { }",
+ "(interface) => { }",
+ "(bar, interface) => { }",
"interface = 1;",
"var foo = interface = 1;",
"++interface;",
@@ -1626,6 +1671,7 @@ TEST(ErrorsFutureStrictReservedWords) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kError);
}
@@ -1634,6 +1680,7 @@ TEST(NoErrorsFutureStrictReservedWords) {
const char* context_data[][2] = {
{ "", "" },
{ "function test_func() {", "}"},
+ { "() => {", "}" },
{ NULL, NULL }
};
@@ -1644,6 +1691,8 @@ TEST(NoErrorsFutureStrictReservedWords) {
"function interface() { }",
"function foo(interface) { }",
"function foo(bar, interface) { }",
+ "(interface) => { }",
+ "(bar, interface) => { }",
"interface = 1;",
"var foo = interface = 1;",
"++interface;",
@@ -1651,6 +1700,7 @@ TEST(NoErrorsFutureStrictReservedWords) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kSuccess);
}
@@ -1664,6 +1714,8 @@ TEST(ErrorsReservedWords) {
{ "\"use strict\";", "" },
{ "var eval; function test_func() {", "}"},
{ "var eval; function test_func() {\"use strict\"; ", "}"},
+ { "var eval; () => {", "}" },
+ { "var eval; () => {\"use strict\"; ", "}" },
{ NULL, NULL }
};
@@ -1674,6 +1726,8 @@ TEST(ErrorsReservedWords) {
"function super() { }",
"function foo(super) { }",
"function foo(bar, super) { }",
+ "(super) => { }",
+ "(bar, super) => { }",
"super = 1;",
"var foo = super = 1;",
"++super;",
@@ -1682,6 +1736,7 @@ TEST(ErrorsReservedWords) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kError);
}
@@ -1692,6 +1747,7 @@ TEST(NoErrorsYieldSloppy) {
const char* context_data[][2] = {
{ "", "" },
{ "function is_not_gen() {", "}" },
+ { "() => {", "}" },
{ NULL, NULL }
};
@@ -1702,6 +1758,8 @@ TEST(NoErrorsYieldSloppy) {
"function yield() { }",
"function foo(yield) { }",
"function foo(bar, yield) { }",
+ "(yield) => { }",
+ "(bar, yield) => { }",
"yield = 1;",
"var foo = yield = 1;",
"++yield;",
@@ -1709,6 +1767,7 @@ TEST(NoErrorsYieldSloppy) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kSuccess);
}
@@ -1737,6 +1796,7 @@ TEST(ErrorsYieldSloppyGenerator) {
// If generators are not allowed, the error will be produced at the '*' token,
// so this test works both with and without the kAllowGenerators flag.
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kError);
}
@@ -1746,6 +1806,7 @@ TEST(ErrorsYieldStrict) {
{ "\"use strict\";", "" },
{ "\"use strict\"; function is_not_gen() {", "}" },
{ "function test_func() {\"use strict\"; ", "}"},
+ { "() => {\"use strict\"; ", "}" },
{ NULL, NULL }
};
@@ -1756,6 +1817,8 @@ TEST(ErrorsYieldStrict) {
"function yield() { }",
"function foo(yield) { }",
"function foo(bar, yield) { }",
+ "(yield) => { }",
+ "(bar, yield) => { }",
"yield = 1;",
"var foo = yield = 1;",
"++yield;",
@@ -1763,6 +1826,7 @@ TEST(ErrorsYieldStrict) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kError);
}
@@ -1782,6 +1846,7 @@ TEST(ErrorsYield) {
// Here we cannot assert that there is no error, since there will be without
// the kAllowGenerators flag. However, we test that Parser and PreParser
// produce the same errors.
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kSuccessOrError);
}
@@ -1806,6 +1871,7 @@ TEST(ErrorsNameOfStrictFunction) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kError);
}
@@ -1824,6 +1890,7 @@ TEST(NoErrorsNameOfStrictFunction) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kSuccess);
}
@@ -1834,6 +1901,7 @@ TEST(ErrorsIllegalWordsAsLabelsSloppy) {
const char* context_data[][2] = {
{ "", ""},
{ "function test_func() {", "}" },
+ { "() => {", "}" },
{ NULL, NULL }
};
@@ -1842,6 +1910,7 @@ TEST(ErrorsIllegalWordsAsLabelsSloppy) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kError);
}
@@ -1851,6 +1920,7 @@ TEST(ErrorsIllegalWordsAsLabelsStrict) {
const char* context_data[][2] = {
{ "\"use strict\";", "" },
{ "function test_func() {\"use strict\"; ", "}"},
+ { "() => {\"use strict\"; ", "}" },
{ NULL, NULL }
};
@@ -1861,6 +1931,7 @@ TEST(ErrorsIllegalWordsAsLabelsStrict) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kError);
}
@@ -1870,8 +1941,10 @@ TEST(NoErrorsIllegalWordsAsLabels) {
const char* context_data[][2] = {
{ "", ""},
{ "function test_func() {", "}" },
+ { "() => {", "}" },
{ "\"use strict\";", "" },
{ "\"use strict\"; function test_func() {", "}" },
+ { "\"use strict\"; () => {", "}" },
{ NULL, NULL }
};
@@ -1882,6 +1955,7 @@ TEST(NoErrorsIllegalWordsAsLabels) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kSuccess);
}
@@ -1891,6 +1965,7 @@ TEST(ErrorsParenthesizedLabels) {
const char* context_data[][2] = {
{ "", ""},
{ "function test_func() {", "}" },
+ { "() => {", "}" },
{ NULL, NULL }
};
@@ -1899,6 +1974,7 @@ TEST(ErrorsParenthesizedLabels) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kError);
}
@@ -1915,6 +1991,7 @@ TEST(NoErrorsParenthesizedDirectivePrologue) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kSuccess);
}
@@ -1936,6 +2013,7 @@ TEST(ErrorsNotAnIdentifierName) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kError);
}
@@ -1958,6 +2036,7 @@ TEST(NoErrorsIdentifierNames) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kSuccess);
}
@@ -1966,6 +2045,7 @@ TEST(DontRegressPreParserDataSizes) {
// These tests make sure that Parser doesn't start producing less "preparse
// data" (data which the embedder can cache).
v8::V8::Initialize();
+ i::FLAG_harmony_arrow_functions = true;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handles(isolate);
@@ -2036,6 +2116,20 @@ TEST(FunctionDeclaresItselfStrict) {
{"function foo(bar, yield) {", "}"},
{"function foo(bar, interface) {", "}"},
{"function foo(bar, bar) {", "}"},
+ {"eval => {", "}"},
+ {"arguments => {", "}"},
+ {"yield => {", "}"},
+ {"interface => {", "}"},
+ {"(eval) => {", "}"},
+ {"(arguments) => {", "}"},
+ {"(yield) => {", "}"},
+ {"(interface) => {", "}"},
+ {"(eval, bar) => {", "}"},
+ {"(bar, eval) => {", "}"},
+ {"(bar, arguments) => {", "}"},
+ {"(bar, yield) => {", "}"},
+ {"(bar, interface) => {", "}"},
+ {"(bar, bar) => {", "}"},
{ NULL, NULL }
};
@@ -2049,6 +2143,7 @@ TEST(FunctionDeclaresItselfStrict) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, strict_statement_data, kError);
RunParserSyncTest(context_data, non_strict_statement_data, kSuccess);
}
@@ -2069,6 +2164,7 @@ TEST(ErrorsTryWithoutCatchOrFinally) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kError);
}
@@ -2086,6 +2182,7 @@ TEST(NoErrorsTryCatchFinally) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kSuccess);
}
@@ -2101,6 +2198,7 @@ TEST(ErrorsRegexpLiteral) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kError);
}
@@ -2118,6 +2216,7 @@ TEST(NoErrorsRegexpLiteral) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kSuccess);
}
@@ -2135,6 +2234,7 @@ TEST(Intrinsics) {
// Parsing will fail or succeed depending on whether we allow natives syntax
// or not.
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kSuccessOrError);
}
@@ -2174,6 +2274,7 @@ TEST(NoErrorsNewExpression) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kSuccess);
}
@@ -2193,6 +2294,7 @@ TEST(ErrorsNewExpression) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kError);
}
@@ -2219,6 +2321,7 @@ TEST(StrictObjectLiteralChecking) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(non_strict_context_data, statement_data, kSuccess);
RunParserSyncTest(strict_context_data, statement_data, kError);
}
@@ -2260,6 +2363,7 @@ TEST(ErrorsObjectLiteralChecking) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kError);
}
@@ -2303,6 +2407,7 @@ TEST(NoErrorsObjectLiteralChecking) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
RunParserSyncTest(context_data, statement_data, kSuccess);
}
@@ -2327,6 +2432,7 @@ TEST(TooManyArguments) {
};
// The test is quite slow, so run it with a reduced set of flags.
+ i::FLAG_harmony_arrow_functions = true;
static const ParserFlag empty_flags[] = {kAllowLazy};
RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1);
}
@@ -2375,6 +2481,8 @@ TEST(StrictDelete) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
+
RunParserSyncTest(strict_context_data, sloppy_statement_data, kError);
RunParserSyncTest(sloppy_context_data, sloppy_statement_data, kSuccess);
@@ -2451,6 +2559,8 @@ TEST(InvalidLeftHandSide) {
NULL
};
+ i::FLAG_harmony_arrow_functions = true;
+
RunParserSyncTest(assignment_context_data, good_statement_data, kSuccess);
RunParserSyncTest(assignment_context_data, bad_statement_data_common, kError);
RunParserSyncTest(assignment_context_data, bad_statement_data_for_assignment,
@@ -2467,6 +2577,7 @@ TEST(InvalidLeftHandSide) {
TEST(FuncNameInferrerBasic) {
// Tests that function names are inferred properly.
i::FLAG_allow_natives_syntax = true;
+ i::FLAG_harmony_arrow_functions = true;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
LocalContext env;
@@ -2508,6 +2619,7 @@ TEST(FuncNameInferrerTwoByte) {
// Tests function name inferring in cases where some parts of the inferred
// function name are two-byte strings.
i::FLAG_allow_natives_syntax = true;
+ i::FLAG_harmony_arrow_functions = true;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
LocalContext env;
@@ -2533,6 +2645,7 @@ TEST(FuncNameInferrerEscaped) {
// The same as FuncNameInferrerTwoByte, except that we express the two-byte
// character as a unicode escape.
i::FLAG_allow_natives_syntax = true;
+ i::FLAG_harmony_arrow_functions = true;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
LocalContext env;
@@ -2559,6 +2672,7 @@ TEST(RegressionLazyFunctionWithErrorWithArg) {
// parameter (such as "unknown label" here). The error message was processed
// before the AstValueFactory containing the error message string was
// internalized.
+ i::FLAG_harmony_arrow_functions = true;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
LocalContext env;
@@ -2569,3 +2683,135 @@ TEST(RegressionLazyFunctionWithErrorWithArg) {
"}\n"
"this_is_lazy();\n");
}
+
+
+TEST(ErrorsArrowFunctions) {
+ // Tests that parser and preparser generate the same kind of errors
+ // on invalid arrow function syntax.
+ const char* context_data[][2] = {
+ {"", ";"},
+ {"v = ", ";"},
+ {"bar ? (", ") : baz;"},
+ {"bar ? baz : (", ");"},
+ {"bar[", "];"},
+ {"bar, ", ";"},
+ {"", ", bar;"},
+ { NULL, NULL }
+ };
+
+ const char* statement_data[] = {
+ "=> 0",
+ "=>",
+ "() =>",
+ "=> {}",
+ ") => {}",
+ ", => {}",
+ "(,) => {}",
+ "return => {}",
+ "() => {'value': 42}",
+
+ // Check that the early return introduced in ParsePrimaryExpression
+ // does not accept stray closing parentheses.
+ ")",
+ ") => 0",
+ "foo[()]",
+ "()",
+
+ // Parameter lists with extra parens should be recognized as errors.
+ "(()) => 0",
+ "((x)) => 0",
+ "((x, y)) => 0",
+ "(x, (y)) => 0",
+ "((x, y, z)) => 0",
+ "(x, (y, z)) => 0",
+ "((x, y), z) => 0",
+
+ // The parameter list is parsed as an expression, but only
+ // a comma-separated list of identifier is valid.
+ "32 => {}",
+ "(32) => {}",
+ "(a, 32) => {}",
+ "if => {}",
+ "(if) => {}",
+ "(a, if) => {}",
+ "a + b => {}",
+ "(a + b) => {}",
+ "(a + b, c) => {}",
+ "(a, b - c) => {}",
+ "\"a\" => {}",
+ "(\"a\") => {}",
+ "(\"a\", b) => {}",
+ "(a, \"b\") => {}",
+ "-a => {}",
+ "(-a) => {}",
+ "(-a, b) => {}",
+ "(a, -b) => {}",
+ "{} => {}",
+ "({}) => {}",
+ "(a, {}) => {}",
+ "({}, a) => {}",
+ "a++ => {}",
+ "(a++) => {}",
+ "(a++, b) => {}",
+ "(a, b++) => {}",
+ "[] => {}",
+ "([]) => {}",
+ "(a, []) => {}",
+ "([], a) => {}",
+ "(a = b) => {}",
+ "(a = b, c) => {}",
+ "(a, b = c) => {}",
+ "(foo ? bar : baz) => {}",
+ "(a, foo ? bar : baz) => {}",
+ "(foo ? bar : baz, a) => {}",
+
+ NULL
+ };
+
+ i::FLAG_harmony_arrow_functions = true;
+ RunParserSyncTest(context_data, statement_data, kError);
+}
+
+
+TEST(NoErrorsArrowFunctions) {
+ // Tests that parser and preparser accept valid arrow functions syntax.
+ const char* context_data[][2] = {
+ {"", ";"},
+ {"bar ? (", ") : baz;"},
+ {"bar ? baz : (", ");"},
+ {"bar, ", ";"},
+ {"", ", bar;"},
+ { NULL, NULL }
+ };
+
+ const char* statement_data[] = {
+ "() => {}",
+ "() => { return 42 }",
+ "x => { return x; }",
+ "(x) => { return x; }",
+ "(x, y) => { return x + y; }",
+ "(x, y, z) => { return x + y + z; }",
+ "(x, y) => { x.a = y; }",
+ "() => 42",
+ "x => x",
+ "x => x * x",
+ "(x) => x",
+ "(x) => x * x",
+ "(x, y) => x + y",
+ "(x, y, z) => x, y, z",
+ "(x, y) => x.a = y",
+ "() => ({'value': 42})",
+ "x => y => x + y",
+ "(x, y) => (u, v) => x*u + y*v",
+ "(x, y) => z => z * (x + y)",
+ "x => (y, z) => z * (x + y)",
+
+ // Arrow has more precedence, this is the same as: foo ? bar : (baz = {})
+ "foo ? bar : baz => {}",
+
+ NULL
+ };
+
+ i::FLAG_harmony_arrow_functions = true;
+ RunParserSyncTest(context_data, statement_data, kSuccess);
+}
« src/scanner.h ('K') | « src/token.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698