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

Side by Side Diff: test/cctest/test-parsing.cc

Issue 1373633002: Remove --harmony-arrow-functions flag (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « test/cctest/test-ast-expression-visitor.cc ('k') | test/cctest/test-typing-reset.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 "var w = /RegExp Literal\\u0020With Escape/gin;" 220 "var w = /RegExp Literal\\u0020With Escape/gin;"
221 "var y = { get getter() { return 42; }, " 221 "var y = { get getter() { return 42; }, "
222 " set setter(v) { this.value = v; }};" 222 " set setter(v) { this.value = v; }};"
223 "var f = a => function (b) { return a + b; };" 223 "var f = a => function (b) { return a + b; };"
224 "var g = a => b => a + b;"; 224 "var g = a => b => a + b;";
225 int source_length = i::StrLength(source); 225 int source_length = i::StrLength(source);
226 226
227 // ScriptResource will be deleted when the corresponding String is GCd. 227 // ScriptResource will be deleted when the corresponding String is GCd.
228 v8::ScriptCompiler::Source script_source(v8::String::NewExternal( 228 v8::ScriptCompiler::Source script_source(v8::String::NewExternal(
229 isolate, new ScriptResource(source, source_length))); 229 isolate, new ScriptResource(source, source_length)));
230 i::FLAG_harmony_arrow_functions = true;
231 i::FLAG_min_preparse_length = 0; 230 i::FLAG_min_preparse_length = 0;
232 v8::ScriptCompiler::Compile(isolate, &script_source, 231 v8::ScriptCompiler::Compile(isolate, &script_source,
233 v8::ScriptCompiler::kProduceParserCache); 232 v8::ScriptCompiler::kProduceParserCache);
234 CHECK(script_source.GetCachedData()); 233 CHECK(script_source.GetCachedData());
235 234
236 // Compile the script again, using the cached data. 235 // Compile the script again, using the cached data.
237 bool lazy_flag = i::FLAG_lazy; 236 bool lazy_flag = i::FLAG_lazy;
238 i::FLAG_lazy = true; 237 i::FLAG_lazy = true;
239 v8::ScriptCompiler::Compile(isolate, &script_source, 238 v8::ScriptCompiler::Compile(isolate, &script_source,
240 v8::ScriptCompiler::kConsumeParserCache); 239 v8::ScriptCompiler::kConsumeParserCache);
241 i::FLAG_lazy = false; 240 i::FLAG_lazy = false;
242 v8::ScriptCompiler::CompileUnbound(isolate, &script_source, 241 v8::ScriptCompiler::CompileUnbound(isolate, &script_source,
243 v8::ScriptCompiler::kConsumeParserCache); 242 v8::ScriptCompiler::kConsumeParserCache);
244 i::FLAG_lazy = lazy_flag; 243 i::FLAG_lazy = lazy_flag;
245 } 244 }
246 245
247 246
248 TEST(PreparseFunctionDataIsUsed) { 247 TEST(PreparseFunctionDataIsUsed) {
249 // This tests that we actually do use the function data generated by the 248 // This tests that we actually do use the function data generated by the
250 // preparser. 249 // preparser.
251 250
252 // Make preparsing work for short scripts. 251 // Make preparsing work for short scripts.
253 i::FLAG_min_preparse_length = 0; 252 i::FLAG_min_preparse_length = 0;
254 i::FLAG_harmony_arrow_functions = true;
255 253
256 v8::Isolate* isolate = CcTest::isolate(); 254 v8::Isolate* isolate = CcTest::isolate();
257 v8::HandleScope handles(isolate); 255 v8::HandleScope handles(isolate);
258 v8::Local<v8::Context> context = v8::Context::New(isolate); 256 v8::Local<v8::Context> context = v8::Context::New(isolate);
259 v8::Context::Scope context_scope(context); 257 v8::Context::Scope context_scope(context);
260 CcTest::i_isolate()->stack_guard()->SetStackLimit( 258 CcTest::i_isolate()->stack_guard()->SetStackLimit(
261 i::GetCurrentStackPosition() - 128 * 1024); 259 i::GetCurrentStackPosition() - 128 * 1024);
262 260
263 const char* good_code[] = { 261 const char* good_code[] = {
264 "function this_is_lazy() { var a; } function foo() { return 25; } foo();", 262 "function this_is_lazy() { var a; } function foo() { return 25; } foo();",
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 321 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
324 scanner.Initialize(&stream); 322 scanner.Initialize(&stream);
325 323
326 i::Zone zone; 324 i::Zone zone;
327 i::AstValueFactory ast_value_factory( 325 i::AstValueFactory ast_value_factory(
328 &zone, CcTest::i_isolate()->heap()->HashSeed()); 326 &zone, CcTest::i_isolate()->heap()->HashSeed());
329 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 327 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
330 stack_limit); 328 stack_limit);
331 preparser.set_allow_lazy(true); 329 preparser.set_allow_lazy(true);
332 preparser.set_allow_natives(true); 330 preparser.set_allow_natives(true);
333 preparser.set_allow_harmony_arrow_functions(true);
334 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 331 i::PreParser::PreParseResult result = preparser.PreParseProgram();
335 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 332 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
336 CHECK(!log.HasError()); 333 CHECK(!log.HasError());
337 } 334 }
338 } 335 }
339 336
340 337
341 TEST(StandAlonePreParserNoNatives) { 338 TEST(StandAlonePreParserNoNatives) {
342 v8::V8::Initialize(); 339 v8::V8::Initialize();
343 340
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 i::CompleteParserRecorder log; 514 i::CompleteParserRecorder log;
518 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 515 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
519 scanner.Initialize(&stream); 516 scanner.Initialize(&stream);
520 517
521 i::Zone zone; 518 i::Zone zone;
522 i::AstValueFactory ast_value_factory(&zone, 519 i::AstValueFactory ast_value_factory(&zone,
523 CcTest::i_isolate()->heap()->HashSeed()); 520 CcTest::i_isolate()->heap()->HashSeed());
524 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 521 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
525 stack_limit); 522 stack_limit);
526 preparser.set_allow_lazy(true); 523 preparser.set_allow_lazy(true);
527 preparser.set_allow_harmony_arrow_functions(true);
528 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 524 i::PreParser::PreParseResult result = preparser.PreParseProgram();
529 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); 525 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result);
530 } 526 }
531 527
532 528
533 class TestExternalResource: public v8::String::ExternalStringResource { 529 class TestExternalResource: public v8::String::ExternalStringResource {
534 public: 530 public:
535 explicit TestExternalResource(uint16_t* data, int length) 531 explicit TestExternalResource(uint16_t* data, int length)
536 : data_(data), length_(static_cast<size_t>(length)) { } 532 : data_(data), length_(static_cast<size_t>(length)) { }
537 533
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 i::ScopedVector<char> program(kProgramByteSize + 1); 1053 i::ScopedVector<char> program(kProgramByteSize + 1);
1058 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, 1054 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix,
1059 source_data[i].body, surroundings[j].suffix); 1055 source_data[i].body, surroundings[j].suffix);
1060 i::Handle<i::String> source = 1056 i::Handle<i::String> source =
1061 factory->NewStringFromUtf8(i::CStrVector(program.start())) 1057 factory->NewStringFromUtf8(i::CStrVector(program.start()))
1062 .ToHandleChecked(); 1058 .ToHandleChecked();
1063 i::Handle<i::Script> script = factory->NewScript(source); 1059 i::Handle<i::Script> script = factory->NewScript(source);
1064 i::Zone zone; 1060 i::Zone zone;
1065 i::ParseInfo info(&zone, script); 1061 i::ParseInfo info(&zone, script);
1066 i::Parser parser(&info); 1062 i::Parser parser(&info);
1067 parser.set_allow_harmony_arrow_functions(true);
1068 parser.set_allow_harmony_sloppy(true); 1063 parser.set_allow_harmony_sloppy(true);
1069 info.set_global(); 1064 info.set_global();
1070 CHECK(parser.Parse(&info)); 1065 CHECK(parser.Parse(&info));
1071 CHECK(i::Rewriter::Rewrite(&info)); 1066 CHECK(i::Rewriter::Rewrite(&info));
1072 CHECK(i::Scope::Analyze(&info)); 1067 CHECK(i::Scope::Analyze(&info));
1073 CHECK(info.literal() != NULL); 1068 CHECK(info.literal() != NULL);
1074 1069
1075 i::Scope* script_scope = info.literal()->scope(); 1070 i::Scope* script_scope = info.literal()->scope();
1076 CHECK(script_scope->is_script_scope()); 1071 CHECK(script_scope->is_script_scope());
1077 CHECK_EQ(1, script_scope->inner_scopes()->length()); 1072 CHECK_EQ(1, script_scope->inner_scopes()->length());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 full_source += "; }"; 1106 full_source += "; }";
1112 1107
1113 i::Handle<i::String> source_code = 1108 i::Handle<i::String> source_code =
1114 factory->NewStringFromUtf8(i::CStrVector(full_source.c_str())) 1109 factory->NewStringFromUtf8(i::CStrVector(full_source.c_str()))
1115 .ToHandleChecked(); 1110 .ToHandleChecked();
1116 1111
1117 i::Handle<i::Script> script = factory->NewScript(source_code); 1112 i::Handle<i::Script> script = factory->NewScript(source_code);
1118 1113
1119 i::ParseInfo info(handles.main_zone(), script); 1114 i::ParseInfo info(handles.main_zone(), script);
1120 i::Parser parser(&info); 1115 i::Parser parser(&info);
1121 parser.set_allow_harmony_arrow_functions(true);
1122 parser.set_allow_harmony_sloppy(true); 1116 parser.set_allow_harmony_sloppy(true);
1123 info.set_global(); 1117 info.set_global();
1124 info.set_lazy(false); 1118 info.set_lazy(false);
1125 info.set_allow_lazy_parsing(false); 1119 info.set_allow_lazy_parsing(false);
1126 info.set_toplevel(true); 1120 info.set_toplevel(true);
1127 1121
1128 i::CompilationInfo compilation_info(&info); 1122 i::CompilationInfo compilation_info(&info);
1129 CHECK(i::Compiler::ParseAndAnalyze(&info)); 1123 CHECK(i::Compiler::ParseAndAnalyze(&info));
1130 1124
1131 CHECK(info.scope()->declarations()->length() == 1); 1125 CHECK(info.scope()->declarations()->length() == 1);
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 1362
1369 // Parse program source. 1363 // Parse program source.
1370 i::Handle<i::String> source = factory->NewStringFromUtf8( 1364 i::Handle<i::String> source = factory->NewStringFromUtf8(
1371 i::CStrVector(program.start())).ToHandleChecked(); 1365 i::CStrVector(program.start())).ToHandleChecked();
1372 CHECK_EQ(source->length(), kProgramSize); 1366 CHECK_EQ(source->length(), kProgramSize);
1373 i::Handle<i::Script> script = factory->NewScript(source); 1367 i::Handle<i::Script> script = factory->NewScript(source);
1374 i::Zone zone; 1368 i::Zone zone;
1375 i::ParseInfo info(&zone, script); 1369 i::ParseInfo info(&zone, script);
1376 i::Parser parser(&info); 1370 i::Parser parser(&info);
1377 parser.set_allow_lazy(true); 1371 parser.set_allow_lazy(true);
1378 parser.set_allow_harmony_arrow_functions(true);
1379 info.set_global(); 1372 info.set_global();
1380 info.set_language_mode(source_data[i].language_mode); 1373 info.set_language_mode(source_data[i].language_mode);
1381 parser.Parse(&info); 1374 parser.Parse(&info);
1382 CHECK(info.literal() != NULL); 1375 CHECK(info.literal() != NULL);
1383 1376
1384 // Check scope types and positions. 1377 // Check scope types and positions.
1385 i::Scope* scope = info.literal()->scope(); 1378 i::Scope* scope = info.literal()->scope();
1386 CHECK(scope->is_script_scope()); 1379 CHECK(scope->is_script_scope());
1387 CHECK_EQ(scope->start_position(), 0); 1380 CHECK_EQ(scope->start_position(), 0);
1388 CHECK_EQ(scope->end_position(), kProgramSize); 1381 CHECK_EQ(scope->end_position(), kProgramSize);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 } 1483 }
1491 1484
1492 data.Dispose(); 1485 data.Dispose();
1493 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); 1486 return i::MessageTemplate::FormatMessage(isolate, message, arg_object);
1494 } 1487 }
1495 1488
1496 1489
1497 enum ParserFlag { 1490 enum ParserFlag {
1498 kAllowLazy, 1491 kAllowLazy,
1499 kAllowNatives, 1492 kAllowNatives,
1500 kAllowHarmonyArrowFunctions,
1501 kAllowHarmonyDefaultParameters, 1493 kAllowHarmonyDefaultParameters,
1502 kAllowHarmonyRestParameters, 1494 kAllowHarmonyRestParameters,
1503 kAllowHarmonySloppy, 1495 kAllowHarmonySloppy,
1504 kAllowHarmonySloppyLet, 1496 kAllowHarmonySloppyLet,
1505 kAllowHarmonySpreadCalls, 1497 kAllowHarmonySpreadCalls,
1506 kAllowHarmonyDestructuring, 1498 kAllowHarmonyDestructuring,
1507 kAllowHarmonySpreadArrays, 1499 kAllowHarmonySpreadArrays,
1508 kAllowHarmonyNewTarget, 1500 kAllowHarmonyNewTarget,
1509 kAllowStrongMode, 1501 kAllowStrongMode,
1510 kNoLegacyConst 1502 kNoLegacyConst
1511 }; 1503 };
1512 1504
1513 1505
1514 enum ParserSyncTestResult { 1506 enum ParserSyncTestResult {
1515 kSuccessOrError, 1507 kSuccessOrError,
1516 kSuccess, 1508 kSuccess,
1517 kError 1509 kError
1518 }; 1510 };
1519 1511
1520 template <typename Traits> 1512 template <typename Traits>
1521 void SetParserFlags(i::ParserBase<Traits>* parser, 1513 void SetParserFlags(i::ParserBase<Traits>* parser,
1522 i::EnumSet<ParserFlag> flags) { 1514 i::EnumSet<ParserFlag> flags) {
1523 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1515 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1524 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1516 parser->set_allow_natives(flags.Contains(kAllowNatives));
1525 parser->set_allow_harmony_arrow_functions(
1526 flags.Contains(kAllowHarmonyArrowFunctions));
1527 parser->set_allow_harmony_default_parameters( 1517 parser->set_allow_harmony_default_parameters(
1528 flags.Contains(kAllowHarmonyDefaultParameters)); 1518 flags.Contains(kAllowHarmonyDefaultParameters));
1529 parser->set_allow_harmony_rest_parameters( 1519 parser->set_allow_harmony_rest_parameters(
1530 flags.Contains(kAllowHarmonyRestParameters)); 1520 flags.Contains(kAllowHarmonyRestParameters));
1531 parser->set_allow_harmony_spread_calls( 1521 parser->set_allow_harmony_spread_calls(
1532 flags.Contains(kAllowHarmonySpreadCalls)); 1522 flags.Contains(kAllowHarmonySpreadCalls));
1533 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); 1523 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy));
1534 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); 1524 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet));
1535 parser->set_allow_harmony_destructuring( 1525 parser->set_allow_harmony_destructuring(
1536 flags.Contains(kAllowHarmonyDestructuring)); 1526 flags.Contains(kAllowHarmonyDestructuring));
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1999 "arguments;", 1989 "arguments;",
2000 "var foo = eval;", 1990 "var foo = eval;",
2001 "var foo = arguments;", 1991 "var foo = arguments;",
2002 "var foo = { eval: 1 };", 1992 "var foo = { eval: 1 };",
2003 "var foo = { arguments: 1 };", 1993 "var foo = { arguments: 1 };",
2004 "var foo = { }; foo.eval = {};", 1994 "var foo = { }; foo.eval = {};",
2005 "var foo = { }; foo.arguments = {};", 1995 "var foo = { }; foo.arguments = {};",
2006 NULL 1996 NULL
2007 }; 1997 };
2008 1998
2009 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; 1999 RunParserSyncTest(context_data, statement_data, kSuccess);
2010 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2011 always_flags, arraysize(always_flags));
2012 } 2000 }
2013 2001
2014 2002
2015 #define FUTURE_STRICT_RESERVED_WORDS(V) \ 2003 #define FUTURE_STRICT_RESERVED_WORDS(V) \
2016 V(implements) \ 2004 V(implements) \
2017 V(interface) \ 2005 V(interface) \
2018 V(let) \ 2006 V(let) \
2019 V(package) \ 2007 V(package) \
2020 V(private) \ 2008 V(private) \
2021 V(protected) \ 2009 V(protected) \
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2080 { "function test_func() {", "}"}, 2068 { "function test_func() {", "}"},
2081 { "() => {", "}" }, 2069 { "() => {", "}" },
2082 { NULL, NULL } 2070 { NULL, NULL }
2083 }; 2071 };
2084 2072
2085 const char* statement_data[] = { 2073 const char* statement_data[] = {
2086 FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) 2074 FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS)
2087 NULL 2075 NULL
2088 }; 2076 };
2089 2077
2090 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; 2078 RunParserSyncTest(context_data, statement_data, kSuccess);
2091 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2092 always_flags, arraysize(always_flags));
2093
2094 static const ParserFlag classes_flags[] = {kAllowHarmonyArrowFunctions};
2095 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2096 classes_flags, arraysize(classes_flags));
2097 } 2079 }
2098 2080
2099 2081
2100 TEST(ErrorsReservedWords) { 2082 TEST(ErrorsReservedWords) {
2101 // Tests that both preparsing and parsing produce the right kind of errors for 2083 // Tests that both preparsing and parsing produce the right kind of errors for
2102 // using future reserved words as identifiers. These tests don't depend on the 2084 // using future reserved words as identifiers. These tests don't depend on the
2103 // strict mode. 2085 // strict mode.
2104 const char* context_data[][2] = { 2086 const char* context_data[][2] = {
2105 { "", "" }, 2087 { "", "" },
2106 { "\"use strict\";", "" }, 2088 { "\"use strict\";", "" },
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
2513 { NULL, NULL } 2495 { NULL, NULL }
2514 }; 2496 };
2515 2497
2516 const char* statement_data[] = { 2498 const char* statement_data[] = {
2517 "mylabel: while(true) { break mylabel; }", 2499 "mylabel: while(true) { break mylabel; }",
2518 "eval: while(true) { break eval; }", 2500 "eval: while(true) { break eval; }",
2519 "arguments: while(true) { break arguments; }", 2501 "arguments: while(true) { break arguments; }",
2520 NULL 2502 NULL
2521 }; 2503 };
2522 2504
2523 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; 2505 RunParserSyncTest(context_data, statement_data, kSuccess);
2524 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2525 always_flags, arraysize(always_flags));
2526 } 2506 }
2527 2507
2528 2508
2529 TEST(NoErrorsFutureStrictReservedAsLabelsSloppy) { 2509 TEST(NoErrorsFutureStrictReservedAsLabelsSloppy) {
2530 const char* context_data[][2] = { 2510 const char* context_data[][2] = {
2531 { "", ""}, 2511 { "", ""},
2532 { "function test_func() {", "}" }, 2512 { "function test_func() {", "}" },
2533 { "() => {", "}" }, 2513 { "() => {", "}" },
2534 { NULL, NULL } 2514 { NULL, NULL }
2535 }; 2515 };
2536 2516
2537 #define LABELLED_WHILE(NAME) #NAME ": while (true) { break " #NAME "; }", 2517 #define LABELLED_WHILE(NAME) #NAME ": while (true) { break " #NAME "; }",
2538 const char* statement_data[] { 2518 const char* statement_data[] {
2539 FUTURE_STRICT_RESERVED_WORDS(LABELLED_WHILE) 2519 FUTURE_STRICT_RESERVED_WORDS(LABELLED_WHILE)
2540 NULL 2520 NULL
2541 }; 2521 };
2542 #undef LABELLED_WHILE 2522 #undef LABELLED_WHILE
2543 2523
2544 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; 2524 RunParserSyncTest(context_data, statement_data, kSuccess);
2545 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2546 always_flags, arraysize(always_flags));
2547 } 2525 }
2548 2526
2549 2527
2550 TEST(ErrorsParenthesizedLabels) { 2528 TEST(ErrorsParenthesizedLabels) {
2551 // Parenthesized identifiers shouldn't be recognized as labels. 2529 // Parenthesized identifiers shouldn't be recognized as labels.
2552 const char* context_data[][2] = { 2530 const char* context_data[][2] = {
2553 { "", ""}, 2531 { "", ""},
2554 { "function test_func() {", "}" }, 2532 { "function test_func() {", "}" },
2555 { "() => {", "}" }, 2533 { "() => {", "}" },
2556 { NULL, NULL } 2534 { NULL, NULL }
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after
3611 "c++", 3589 "c++",
3612 "`c`", 3590 "`c`",
3613 "`${c}`", 3591 "`${c}`",
3614 "`template-head${c}`", 3592 "`template-head${c}`",
3615 "`${c}template-tail`", 3593 "`${c}template-tail`",
3616 "`template-head${c}template-tail`", 3594 "`template-head${c}template-tail`",
3617 "`${c}template-tail`", 3595 "`${c}template-tail`",
3618 nullptr 3596 nullptr
3619 }; 3597 };
3620 3598
3621 static const ParserFlag always_flags[] = { kAllowHarmonyArrowFunctions, 3599 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters};
3622 kAllowHarmonyRestParameters };
3623 RunParserSyncTest(context_data, assignment_expression_suffix_data, kError, 3600 RunParserSyncTest(context_data, assignment_expression_suffix_data, kError,
3624 NULL, 0, always_flags, arraysize(always_flags)); 3601 NULL, 0, always_flags, arraysize(always_flags));
3625 } 3602 }
3626 3603
3627 3604
3628 TEST(ErrorsArrowFunctions) { 3605 TEST(ErrorsArrowFunctions) {
3629 // Tests that parser and preparser generate the same kind of errors 3606 // Tests that parser and preparser generate the same kind of errors
3630 // on invalid arrow function syntax. 3607 // on invalid arrow function syntax.
3631 const char* context_data[][2] = { 3608 const char* context_data[][2] = {
3632 {"", ";"}, 3609 {"", ";"},
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
3726 "(foo ? bar : baz, a) => {}", 3703 "(foo ? bar : baz, a) => {}",
3727 "(a.b, c) => {}", 3704 "(a.b, c) => {}",
3728 "(c, a.b) => {}", 3705 "(c, a.b) => {}",
3729 "(a['b'], c) => {}", 3706 "(a['b'], c) => {}",
3730 "(c, a['b']) => {}", 3707 "(c, a['b']) => {}",
3731 NULL 3708 NULL
3732 }; 3709 };
3733 3710
3734 // The test is quite slow, so run it with a reduced set of flags. 3711 // The test is quite slow, so run it with a reduced set of flags.
3735 static const ParserFlag flags[] = {kAllowLazy}; 3712 static const ParserFlag flags[] = {kAllowLazy};
3736 static const ParserFlag always_flags[] = { kAllowHarmonyArrowFunctions };
3737 RunParserSyncTest(context_data, statement_data, kError, flags, 3713 RunParserSyncTest(context_data, statement_data, kError, flags,
3738 arraysize(flags), always_flags, arraysize(always_flags)); 3714 arraysize(flags));
3739 } 3715 }
3740 3716
3741 3717
3742 TEST(NoErrorsArrowFunctions) { 3718 TEST(NoErrorsArrowFunctions) {
3743 // Tests that parser and preparser accept valid arrow functions syntax. 3719 // Tests that parser and preparser accept valid arrow functions syntax.
3744 const char* context_data[][2] = { 3720 const char* context_data[][2] = {
3745 {"", ";"}, 3721 {"", ";"},
3746 {"bar ? (", ") : baz;"}, 3722 {"bar ? (", ") : baz;"},
3747 {"bar ? baz : (", ");"}, 3723 {"bar ? baz : (", ");"},
3748 {"bar, ", ";"}, 3724 {"bar, ", ";"},
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3798 "(x, y = 9, ...a) => {}", 3774 "(x, y = 9, ...a) => {}",
3799 "(x, y = 9, {b}, z = 8, ...a) => {}", 3775 "(x, y = 9, {b}, z = 8, ...a) => {}",
3800 // TODO(wingo, rossberg): This is not accepted right now. 3776 // TODO(wingo, rossberg): This is not accepted right now.
3801 // "({a} = {}) => {}", 3777 // "({a} = {}) => {}",
3802 // "([x] = []) => {}", 3778 // "([x] = []) => {}",
3803 "({a = 42}) => {}", 3779 "({a = 42}) => {}",
3804 "([x = 0]) => {}", 3780 "([x = 0]) => {}",
3805 NULL 3781 NULL
3806 }; 3782 };
3807 3783
3808 static const ParserFlag always_flags[] = { 3784 static const ParserFlag always_flags[] = {kAllowHarmonyDefaultParameters,
3809 kAllowHarmonyArrowFunctions, kAllowHarmonyDefaultParameters, 3785 kAllowHarmonyRestParameters,
3810 kAllowHarmonyRestParameters, kAllowHarmonyDestructuring}; 3786 kAllowHarmonyDestructuring};
3811 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 3787 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
3812 always_flags, arraysize(always_flags)); 3788 always_flags, arraysize(always_flags));
3813 } 3789 }
3814 3790
3815 3791
3816 TEST(ArrowFunctionsSloppyParameterNames) { 3792 TEST(ArrowFunctionsSloppyParameterNames) {
3817 const char* strong_context_data[][2] = { 3793 const char* strong_context_data[][2] = {
3818 {"'use strong'; ", ";"}, 3794 {"'use strong'; ", ";"},
3819 {"'use strong'; bar ? (", ") : baz;"}, 3795 {"'use strong'; bar ? (", ") : baz;"},
3820 {"'use strong'; bar ? baz : (", ");"}, 3796 {"'use strong'; bar ? baz : (", ");"},
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3855 "(bar, arguments) => {}", 3831 "(bar, arguments) => {}",
3856 "(bar, yield) => {}", 3832 "(bar, yield) => {}",
3857 "(bar, interface) => {}", 3833 "(bar, interface) => {}",
3858 "(interface, eval) => {}", 3834 "(interface, eval) => {}",
3859 "(interface, arguments) => {}", 3835 "(interface, arguments) => {}",
3860 "(eval, interface) => {}", 3836 "(eval, interface) => {}",
3861 "(arguments, interface) => {}", 3837 "(arguments, interface) => {}",
3862 NULL 3838 NULL
3863 }; 3839 };
3864 3840
3865 static const ParserFlag always_flags[] = { kAllowHarmonyArrowFunctions, 3841 static const ParserFlag always_flags[] = {kAllowStrongMode};
3866 kAllowStrongMode};
3867 RunParserSyncTest(strong_context_data, statement_data, kError, NULL, 0, 3842 RunParserSyncTest(strong_context_data, statement_data, kError, NULL, 0,
3868 always_flags, arraysize(always_flags)); 3843 always_flags, arraysize(always_flags));
3869 RunParserSyncTest(strict_context_data, statement_data, kError, NULL, 0, 3844 RunParserSyncTest(strict_context_data, statement_data, kError, NULL, 0,
3870 always_flags, arraysize(always_flags)); 3845 always_flags, arraysize(always_flags));
3871 RunParserSyncTest(sloppy_context_data, statement_data, kSuccess, NULL, 0, 3846 RunParserSyncTest(sloppy_context_data, statement_data, kSuccess, NULL, 0,
3872 always_flags, arraysize(always_flags)); 3847 always_flags, arraysize(always_flags));
3873 } 3848 }
3874 3849
3875 3850
3876 TEST(ArrowFunctionsYieldParameterNameInGenerator) { 3851 TEST(ArrowFunctionsYieldParameterNameInGenerator) {
(...skipping 22 matching lines...) Expand all
3899 "(yield, a) => {}", 3874 "(yield, a) => {}",
3900 "(yield, ...a) => {}", 3875 "(yield, ...a) => {}",
3901 "(a, ...yield) => {}", 3876 "(a, ...yield) => {}",
3902 "({yield}) => {}", 3877 "({yield}) => {}",
3903 "([yield]) => {}", 3878 "([yield]) => {}",
3904 NULL 3879 NULL
3905 }; 3880 };
3906 3881
3907 static const ParserFlag always_flags[] = { kAllowHarmonyDestructuring, 3882 static const ParserFlag always_flags[] = { kAllowHarmonyDestructuring,
3908 kAllowHarmonyRestParameters, 3883 kAllowHarmonyRestParameters,
3909 kAllowHarmonyArrowFunctions,
3910 kAllowStrongMode}; 3884 kAllowStrongMode};
3911 RunParserSyncTest(sloppy_function_context_data, arrow_data, kSuccess, NULL, 0, 3885 RunParserSyncTest(sloppy_function_context_data, arrow_data, kSuccess, NULL, 0,
3912 always_flags, arraysize(always_flags)); 3886 always_flags, arraysize(always_flags));
3913 RunParserSyncTest(strict_function_context_data, arrow_data, kError, NULL, 0, 3887 RunParserSyncTest(strict_function_context_data, arrow_data, kError, NULL, 0,
3914 always_flags, arraysize(always_flags)); 3888 always_flags, arraysize(always_flags));
3915 RunParserSyncTest(generator_context_data, arrow_data, kError, NULL, 0, 3889 RunParserSyncTest(generator_context_data, arrow_data, kError, NULL, 0,
3916 always_flags, arraysize(always_flags)); 3890 always_flags, arraysize(always_flags));
3917 } 3891 }
3918 3892
3919 3893
(...skipping 12 matching lines...) Expand all
3932 "super[27]", 3906 "super[27]",
3933 "new super.x", 3907 "new super.x",
3934 "new super.x()", 3908 "new super.x()",
3935 "new super[27]", 3909 "new super[27]",
3936 "new super[27]()", 3910 "new super[27]()",
3937 "z.super", // Ok, property lookup. 3911 "z.super", // Ok, property lookup.
3938 NULL 3912 NULL
3939 }; 3913 };
3940 3914
3941 static const ParserFlag always_flags[] = { 3915 static const ParserFlag always_flags[] = {
3942 kAllowHarmonyArrowFunctions,
3943 kAllowHarmonySloppy 3916 kAllowHarmonySloppy
3944 }; 3917 };
3945 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 3918 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
3946 always_flags, arraysize(always_flags)); 3919 always_flags, arraysize(always_flags));
3947 } 3920 }
3948 3921
3949 3922
3950 TEST(SuperErrors) { 3923 TEST(SuperErrors) {
3951 const char* context_data[][2] = { 3924 const char* context_data[][2] = {
3952 {"class C { m() { ", "; } }"}, 3925 {"class C { m() { ", "; } }"},
(...skipping 26 matching lines...) Expand all
3979 TEST(SuperCall) { 3952 TEST(SuperCall) {
3980 const char* context_data[][2] = {{"", ""}, 3953 const char* context_data[][2] = {{"", ""},
3981 {NULL, NULL}}; 3954 {NULL, NULL}};
3982 3955
3983 const char* success_data[] = { 3956 const char* success_data[] = {
3984 "class C extends B { constructor() { super(); } }", 3957 "class C extends B { constructor() { super(); } }",
3985 "class C extends B { constructor() { () => super(); } }", 3958 "class C extends B { constructor() { () => super(); } }",
3986 NULL 3959 NULL
3987 }; 3960 };
3988 3961
3989 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions, 3962 static const ParserFlag always_flags[] = {kAllowHarmonySloppy};
3990 kAllowHarmonySloppy};
3991 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0, 3963 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0,
3992 always_flags, arraysize(always_flags)); 3964 always_flags, arraysize(always_flags));
3993 3965
3994 const char* error_data[] = { 3966 const char* error_data[] = {
3995 "class C { constructor() { super(); } }", 3967 "class C { constructor() { super(); } }",
3996 "class C { method() { super(); } }", 3968 "class C { method() { super(); } }",
3997 "class C { method() { () => super(); } }", 3969 "class C { method() { () => super(); } }",
3998 "class C { *method() { super(); } }", 3970 "class C { *method() { super(); } }",
3999 "class C { get x() { super(); } }", 3971 "class C { get x() { super(); } }",
4000 "class C { set x(_) { super(); } }", 3972 "class C { set x(_) { super(); } }",
(...skipping 29 matching lines...) Expand all
4030 }; 4002 };
4031 4003
4032 const char* expression_data[] = { 4004 const char* expression_data[] = {
4033 "new super.x;", 4005 "new super.x;",
4034 "new super.x();", 4006 "new super.x();",
4035 "() => new super.x;", 4007 "() => new super.x;",
4036 "() => new super.x();", 4008 "() => new super.x();",
4037 NULL 4009 NULL
4038 }; 4010 };
4039 4011
4040 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions, 4012 static const ParserFlag always_flags[] = {kAllowHarmonySloppy};
4041 kAllowHarmonySloppy};
4042 RunParserSyncTest(context_data, expression_data, kSuccess, NULL, 0, 4013 RunParserSyncTest(context_data, expression_data, kSuccess, NULL, 0,
4043 always_flags, arraysize(always_flags)); 4014 always_flags, arraysize(always_flags));
4044 } 4015 }
4045 4016
4046 4017
4047 TEST(SuperNewErrors) { 4018 TEST(SuperNewErrors) {
4048 const char* context_data[][2] = { 4019 const char* context_data[][2] = {
4049 {"class C { method() { ", " } }"}, 4020 {"class C { method() { ", " } }"},
4050 {"class C { *method() { ", " } }"}, 4021 {"class C { *method() { ", " } }"},
4051 {"class C { get x() { ", " } }"}, 4022 {"class C { get x() { ", " } }"},
(...skipping 12 matching lines...) Expand all
4064 }; 4035 };
4065 4036
4066 const char* statement_data[] = { 4037 const char* statement_data[] = {
4067 "new super;", 4038 "new super;",
4068 "new super();", 4039 "new super();",
4069 "() => new super;", 4040 "() => new super;",
4070 "() => new super();", 4041 "() => new super();",
4071 NULL 4042 NULL
4072 }; 4043 };
4073 4044
4074 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions, 4045 static const ParserFlag always_flags[] = {kAllowHarmonySloppy};
4075 kAllowHarmonySloppy};
4076 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, 4046 RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
4077 always_flags, arraysize(always_flags)); 4047 always_flags, arraysize(always_flags));
4078 } 4048 }
4079 4049
4080 4050
4081 TEST(SuperErrorsNonMethods) { 4051 TEST(SuperErrorsNonMethods) {
4082 // super is only allowed in methods, accessors and constructors. 4052 // super is only allowed in methods, accessors and constructors.
4083 const char* context_data[][2] = { 4053 const char* context_data[][2] = {
4084 {"", ";"}, 4054 {"", ";"},
4085 {"k = ", ";"}, 4055 {"k = ", ";"},
(...skipping 1960 matching lines...) Expand 10 before | Expand all | Expand 10 after
6046 "class C { constructor() { this.a = {b: 1}; this.a.b } }", 6016 "class C { constructor() { this.a = {b: 1}; this.a.b } }",
6047 "class C { constructor() { this.a = {b: 1}; this.a.b = 0 } }", 6017 "class C { constructor() { this.a = {b: 1}; this.a.b = 0 } }",
6048 "class C { constructor() { this.a = function(){}; this.a() } }", 6018 "class C { constructor() { this.a = function(){}; this.a() } }",
6049 NULL}; 6019 NULL};
6050 6020
6051 const char* success_data[] = { 6021 const char* success_data[] = {
6052 "class C { constructor() { this.a = 0; } }", 6022 "class C { constructor() { this.a = 0; } }",
6053 "class C { constructor() { label: 0; this.a = 0; this.b = 6; } }", 6023 "class C { constructor() { label: 0; this.a = 0; this.b = 6; } }",
6054 NULL}; 6024 NULL};
6055 6025
6056 static const ParserFlag always_flags[] = {kAllowStrongMode, 6026 static const ParserFlag always_flags[] = {kAllowStrongMode};
6057 kAllowHarmonyArrowFunctions};
6058 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0, 6027 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0,
6059 always_flags, arraysize(always_flags)); 6028 always_flags, arraysize(always_flags));
6060 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0, 6029 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0,
6061 always_flags, arraysize(always_flags)); 6030 always_flags, arraysize(always_flags));
6062 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0, 6031 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0,
6063 always_flags, arraysize(always_flags)); 6032 always_flags, arraysize(always_flags));
6064 6033
6065 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0, 6034 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0,
6066 always_flags, arraysize(always_flags)); 6035 always_flags, arraysize(always_flags));
6067 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0, 6036 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
6100 "class C extends Object { constructor() { super().a; } }", 6069 "class C extends Object { constructor() { super().a; } }",
6101 NULL}; 6070 NULL};
6102 6071
6103 const char* success_data[] = { 6072 const char* success_data[] = {
6104 "class C extends Object { constructor() { super(); } }", 6073 "class C extends Object { constructor() { super(); } }",
6105 "class C extends Object { constructor() { label: 66; super(); } }", 6074 "class C extends Object { constructor() { label: 66; super(); } }",
6106 "class C extends Object { constructor() { super(3); this.x = 0; } }", 6075 "class C extends Object { constructor() { super(3); this.x = 0; } }",
6107 "class C extends Object { constructor() { 3; super(3); this.x = 0; } }", 6076 "class C extends Object { constructor() { 3; super(3); this.x = 0; } }",
6108 NULL}; 6077 NULL};
6109 6078
6110 static const ParserFlag always_flags[] = {kAllowStrongMode, 6079 static const ParserFlag always_flags[] = {kAllowStrongMode};
6111 kAllowHarmonyArrowFunctions};
6112 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0, 6080 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0,
6113 always_flags, arraysize(always_flags)); 6081 always_flags, arraysize(always_flags));
6114 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0, 6082 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0,
6115 always_flags, arraysize(always_flags)); 6083 always_flags, arraysize(always_flags));
6116 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0, 6084 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0,
6117 always_flags, arraysize(always_flags)); 6085 always_flags, arraysize(always_flags));
6118 6086
6119 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0, 6087 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0,
6120 always_flags, arraysize(always_flags)); 6088 always_flags, arraysize(always_flags));
6121 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0, 6089 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
6242 "((a, b, undefined) => {return});", 6210 "((a, b, undefined) => {return});",
6243 NULL}; 6211 NULL};
6244 6212
6245 const char* local_strong[] = { 6213 const char* local_strong[] = {
6246 "(undefined => {'use strong';});", 6214 "(undefined => {'use strong';});",
6247 "((undefined, b, c) => {'use strong';});", 6215 "((undefined, b, c) => {'use strong';});",
6248 "((a, undefined, c) => {'use strong';});", 6216 "((a, undefined, c) => {'use strong';});",
6249 "((a, b, undefined) => {'use strong';});", 6217 "((a, b, undefined) => {'use strong';});",
6250 NULL}; 6218 NULL};
6251 6219
6252 static const ParserFlag always_flags[] = { 6220 static const ParserFlag always_flags[] = {kAllowStrongMode};
6253 kAllowStrongMode, kAllowHarmonyArrowFunctions
6254 };
6255 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, 6221 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags,
6256 arraysize(always_flags)); 6222 arraysize(always_flags));
6257 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, 6223 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags,
6258 arraysize(always_flags)); 6224 arraysize(always_flags));
6259 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, 6225 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags,
6260 arraysize(always_flags)); 6226 arraysize(always_flags));
6261 RunParserSyncTest(sloppy_context_data, local_strong, kError, NULL, 0, 6227 RunParserSyncTest(sloppy_context_data, local_strong, kError, NULL, 0,
6262 always_flags, arraysize(always_flags)); 6228 always_flags, arraysize(always_flags));
6263 } 6229 }
6264 6230
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
6360 {NULL, NULL}}; 6326 {NULL, NULL}};
6361 6327
6362 const char* data[] = { 6328 const char* data[] = {
6363 "(a\n=> a)(1)", 6329 "(a\n=> a)(1)",
6364 "(a/*\n*/=> a)(1)", 6330 "(a/*\n*/=> a)(1)",
6365 "((a)\n=> a)(1)", 6331 "((a)\n=> a)(1)",
6366 "((a)/*\n*/=> a)(1)", 6332 "((a)/*\n*/=> a)(1)",
6367 "((a, b)\n=> a + b)(1, 2)", 6333 "((a, b)\n=> a + b)(1, 2)",
6368 "((a, b)/*\n*/=> a + b)(1, 2)", 6334 "((a, b)/*\n*/=> a + b)(1, 2)",
6369 NULL}; 6335 NULL};
6370 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; 6336 RunParserSyncTest(context_data, data, kError);
6371 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6372 arraysize(always_flags));
6373 } 6337 }
6374 6338
6375 6339
6376 TEST(StrongModeFreeVariablesDeclaredByPreviousScript) { 6340 TEST(StrongModeFreeVariablesDeclaredByPreviousScript) {
6377 i::FLAG_strong_mode = true; 6341 i::FLAG_strong_mode = true;
6378 v8::V8::Initialize(); 6342 v8::V8::Initialize();
6379 v8::HandleScope scope(CcTest::isolate()); 6343 v8::HandleScope scope(CcTest::isolate());
6380 v8::Context::Scope context_scope(v8::Context::New(CcTest::isolate())); 6344 v8::Context::Scope context_scope(v8::Context::New(CcTest::isolate()));
6381 v8::TryCatch try_catch(CcTest::isolate()); 6345 v8::TryCatch try_catch(CcTest::isolate());
6382 6346
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
6518 strcmp( 6482 strcmp(
6519 "ReferenceError: In strong mode, using an undeclared global " 6483 "ReferenceError: In strong mode, using an undeclared global "
6520 "variable 'not_there3' is not allowed", 6484 "variable 'not_there3' is not allowed",
6521 *exception)); 6485 *exception));
6522 } 6486 }
6523 } 6487 }
6524 6488
6525 6489
6526 TEST(DestructuringPositiveTests) { 6490 TEST(DestructuringPositiveTests) {
6527 i::FLAG_harmony_destructuring = true; 6491 i::FLAG_harmony_destructuring = true;
6528 i::FLAG_harmony_arrow_functions = true;
6529 6492
6530 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6493 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6531 {"var ", " = {};"}, 6494 {"var ", " = {};"},
6532 {"'use strict'; const ", " = {};"}, 6495 {"'use strict'; const ", " = {};"},
6533 {"function f(", ") {}"}, 6496 {"function f(", ") {}"},
6534 {"function f(argument1, ", ") {}"}, 6497 {"function f(argument1, ", ") {}"},
6535 {"var f = (", ") => {};"}, 6498 {"var f = (", ") => {};"},
6536 {"var f = (argument1,", ") => {};"}, 6499 {"var f = (argument1,", ") => {};"},
6537 {NULL, NULL}}; 6500 {NULL, NULL}};
6538 6501
(...skipping 30 matching lines...) Expand all
6569 "{var: x = 42}", 6532 "{var: x = 42}",
6570 "{[x] : z}", 6533 "{[x] : z}",
6571 "{[1+1] : z}", 6534 "{[1+1] : z}",
6572 "{[foo()] : z}", 6535 "{[foo()] : z}",
6573 "{}", 6536 "{}",
6574 "[...rest]", 6537 "[...rest]",
6575 "[a,b,...rest]", 6538 "[a,b,...rest]",
6576 "[a,,...rest]", 6539 "[a,,...rest]",
6577 NULL}; 6540 NULL};
6578 // clang-format on 6541 // clang-format on
6579 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions, 6542 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6580 kAllowHarmonyDestructuring};
6581 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, 6543 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
6582 arraysize(always_flags)); 6544 arraysize(always_flags));
6583 } 6545 }
6584 6546
6585 6547
6586 TEST(DestructuringNegativeTests) { 6548 TEST(DestructuringNegativeTests) {
6587 i::FLAG_harmony_destructuring = true; 6549 i::FLAG_harmony_destructuring = true;
6588 i::FLAG_harmony_arrow_functions = true; 6550 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6589 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions,
6590 kAllowHarmonyDestructuring};
6591 6551
6592 { // All modes. 6552 { // All modes.
6593 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6553 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6594 {"var ", " = {};"}, 6554 {"var ", " = {};"},
6595 {"'use strict'; const ", " = {};"}, 6555 {"'use strict'; const ", " = {};"},
6596 {"function f(", ") {}"}, 6556 {"function f(", ") {}"},
6597 {"function f(argument1, ", ") {}"}, 6557 {"function f(argument1, ", ") {}"},
6598 {"var f = (", ") => {};"}, 6558 {"var f = (", ") => {};"},
6599 {"var f = ", " => {};"}, 6559 {"var f = ", " => {};"},
6600 {"var f = (argument1,", ") => {};"}, 6560 {"var f = (argument1,", ") => {};"},
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
6747 "for (var x = {} in null);", 6707 "for (var x = {} in null);",
6748 NULL}; 6708 NULL};
6749 // clang-format on 6709 // clang-format on
6750 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0, always_flags, 6710 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0, always_flags,
6751 arraysize(always_flags)); 6711 arraysize(always_flags));
6752 } 6712 }
6753 6713
6754 6714
6755 TEST(DestructuringDuplicateParams) { 6715 TEST(DestructuringDuplicateParams) {
6756 i::FLAG_harmony_destructuring = true; 6716 i::FLAG_harmony_destructuring = true;
6757 i::FLAG_harmony_arrow_functions = true; 6717 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6758 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions,
6759 kAllowHarmonyDestructuring};
6760 const char* context_data[][2] = {{"'use strict';", ""}, 6718 const char* context_data[][2] = {{"'use strict';", ""},
6761 {"function outer() { 'use strict';", "}"}, 6719 {"function outer() { 'use strict';", "}"},
6762 {nullptr, nullptr}}; 6720 {nullptr, nullptr}};
6763 6721
6764 6722
6765 // clang-format off 6723 // clang-format off
6766 const char* error_data[] = { 6724 const char* error_data[] = {
6767 "function f(x,x){}", 6725 "function f(x,x){}",
6768 "function f(x, {x : x}){}", 6726 "function f(x, {x : x}){}",
6769 "function f(x, {x}){}", 6727 "function f(x, {x}){}",
6770 "function f({x,x}) {}", 6728 "function f({x,x}) {}",
6771 "function f([x,x]) {}", 6729 "function f([x,x]) {}",
6772 "function f(x, [y,{z:x}]) {}", 6730 "function f(x, [y,{z:x}]) {}",
6773 "function f([x,{y:x}]) {}", 6731 "function f([x,{y:x}]) {}",
6774 // non-simple parameter list causes duplicates to be errors in sloppy mode. 6732 // non-simple parameter list causes duplicates to be errors in sloppy mode.
6775 "function f(x, x, {a}) {}", 6733 "function f(x, x, {a}) {}",
6776 nullptr}; 6734 nullptr};
6777 // clang-format on 6735 // clang-format on
6778 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, 6736 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
6779 arraysize(always_flags)); 6737 arraysize(always_flags));
6780 } 6738 }
6781 6739
6782 6740
6783 TEST(DestructuringDuplicateParamsSloppy) { 6741 TEST(DestructuringDuplicateParamsSloppy) {
6784 i::FLAG_harmony_destructuring = true; 6742 i::FLAG_harmony_destructuring = true;
6785 i::FLAG_harmony_arrow_functions = true; 6743 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6786 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions,
6787 kAllowHarmonyDestructuring};
6788 const char* context_data[][2] = { 6744 const char* context_data[][2] = {
6789 {"", ""}, {"function outer() {", "}"}, {nullptr, nullptr}}; 6745 {"", ""}, {"function outer() {", "}"}, {nullptr, nullptr}};
6790 6746
6791 6747
6792 // clang-format off 6748 // clang-format off
6793 const char* error_data[] = { 6749 const char* error_data[] = {
6794 // non-simple parameter list causes duplicates to be errors in sloppy mode. 6750 // non-simple parameter list causes duplicates to be errors in sloppy mode.
6795 "function f(x, {x : x}){}", 6751 "function f(x, {x : x}){}",
6796 "function f(x, {x}){}", 6752 "function f(x, {x}){}",
6797 "function f({x,x}) {}", 6753 "function f({x,x}) {}",
6798 "function f(x, x, {a}) {}", 6754 "function f(x, x, {a}) {}",
6799 nullptr}; 6755 nullptr};
6800 // clang-format on 6756 // clang-format on
6801 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, 6757 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
6802 arraysize(always_flags)); 6758 arraysize(always_flags));
6803 } 6759 }
6804 6760
6805 6761
6806 TEST(DestructuringDisallowPatternsInSingleParamArrows) { 6762 TEST(DestructuringDisallowPatternsInSingleParamArrows) {
6807 i::FLAG_harmony_destructuring = true; 6763 i::FLAG_harmony_destructuring = true;
6808 i::FLAG_harmony_arrow_functions = true; 6764 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6809 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions,
6810 kAllowHarmonyDestructuring};
6811 const char* context_data[][2] = {{"'use strict';", ""}, 6765 const char* context_data[][2] = {{"'use strict';", ""},
6812 {"function outer() { 'use strict';", "}"}, 6766 {"function outer() { 'use strict';", "}"},
6813 {"", ""}, 6767 {"", ""},
6814 {"function outer() { ", "}"}, 6768 {"function outer() { ", "}"},
6815 {nullptr, nullptr}}; 6769 {nullptr, nullptr}};
6816 6770
6817 // clang-format off 6771 // clang-format off
6818 const char* error_data[] = { 6772 const char* error_data[] = {
6819 "var f = {x} => {};", 6773 "var f = {x} => {};",
6820 "var f = {x,y} => {};", 6774 "var f = {x,y} => {};",
6821 nullptr}; 6775 nullptr};
6822 // clang-format on 6776 // clang-format on
6823 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, 6777 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
6824 arraysize(always_flags)); 6778 arraysize(always_flags));
6825 } 6779 }
6826 6780
6827 6781
6828 TEST(DestructuringDisallowPatternsInRestParams) { 6782 TEST(DestructuringDisallowPatternsInRestParams) {
6829 i::FLAG_harmony_destructuring = true; 6783 i::FLAG_harmony_destructuring = true;
6830 i::FLAG_harmony_arrow_functions = true;
6831 i::FLAG_harmony_rest_parameters = true; 6784 i::FLAG_harmony_rest_parameters = true;
6832 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions, 6785 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters,
6833 kAllowHarmonyRestParameters,
6834 kAllowHarmonyDestructuring}; 6786 kAllowHarmonyDestructuring};
6835 const char* context_data[][2] = {{"'use strict';", ""}, 6787 const char* context_data[][2] = {{"'use strict';", ""},
6836 {"function outer() { 'use strict';", "}"}, 6788 {"function outer() { 'use strict';", "}"},
6837 {"", ""}, 6789 {"", ""},
6838 {"function outer() { ", "}"}, 6790 {"function outer() { ", "}"},
6839 {nullptr, nullptr}}; 6791 {nullptr, nullptr}};
6840 6792
6841 // clang-format off 6793 // clang-format off
6842 const char* error_data[] = { 6794 const char* error_data[] = {
6843 "function(...{}) {}", 6795 "function(...{}) {}",
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
6912 6864
6913 "{x}=(yield)", 6865 "{x}=(yield)",
6914 "[x]=(yield)", 6866 "[x]=(yield)",
6915 6867
6916 "{x}=f(yield)", 6868 "{x}=f(yield)",
6917 "[x]=f(yield)", 6869 "[x]=f(yield)",
6918 NULL 6870 NULL
6919 }; 6871 };
6920 6872
6921 // clang-format on 6873 // clang-format on
6922 static const ParserFlag always_flags[] = { 6874 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring,
6923 kAllowHarmonyDestructuring, kAllowHarmonyDefaultParameters, 6875 kAllowHarmonyDefaultParameters,
6924 kAllowHarmonyArrowFunctions, kAllowStrongMode}; 6876 kAllowStrongMode};
6925 6877
6926 RunParserSyncTest(sloppy_function_context_data, parameter_data, kSuccess, 6878 RunParserSyncTest(sloppy_function_context_data, parameter_data, kSuccess,
6927 NULL, 0, always_flags, arraysize(always_flags)); 6879 NULL, 0, always_flags, arraysize(always_flags));
6928 RunParserSyncTest(sloppy_function_context_data, destructuring_assignment_data, 6880 RunParserSyncTest(sloppy_function_context_data, destructuring_assignment_data,
6929 kSuccess, NULL, 0, always_flags, arraysize(always_flags)); 6881 kSuccess, NULL, 0, always_flags, arraysize(always_flags));
6930 RunParserSyncTest(sloppy_arrow_context_data, parameter_data, kSuccess, NULL, 6882 RunParserSyncTest(sloppy_arrow_context_data, parameter_data, kSuccess, NULL,
6931 0, always_flags, arraysize(always_flags)); 6883 0, always_flags, arraysize(always_flags));
6932 // TODO(wingo): Will change to kSuccess when destructuring assignment lands. 6884 // TODO(wingo): Will change to kSuccess when destructuring assignment lands.
6933 RunParserSyncTest(sloppy_arrow_context_data, destructuring_assignment_data, 6885 RunParserSyncTest(sloppy_arrow_context_data, destructuring_assignment_data,
6934 kError, NULL, 0, always_flags, arraysize(always_flags)); 6886 kError, NULL, 0, always_flags, arraysize(always_flags));
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
7029 "() => { new.target }", 6981 "() => { new.target }",
7030 "() => new.target", 6982 "() => new.target",
7031 "if (1) { new.target }", 6983 "if (1) { new.target }",
7032 "if (1) {} else { new.target }", 6984 "if (1) {} else { new.target }",
7033 "while (0) { new.target }", 6985 "while (0) { new.target }",
7034 "do { new.target } while (0)", 6986 "do { new.target } while (0)",
7035 NULL 6987 NULL
7036 }; 6988 };
7037 6989
7038 static const ParserFlag always_flags[] = { 6990 static const ParserFlag always_flags[] = {
7039 kAllowHarmonyArrowFunctions,
7040 kAllowHarmonyNewTarget, 6991 kAllowHarmonyNewTarget,
7041 kAllowHarmonySloppy, 6992 kAllowHarmonySloppy,
7042 }; 6993 };
7043 // clang-format on 6994 // clang-format on
7044 6995
7045 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, 6996 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags,
7046 arraysize(always_flags)); 6997 arraysize(always_flags));
7047 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, 6998 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags,
7048 arraysize(always_flags)); 6999 arraysize(always_flags));
7049 } 7000 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
7195 "initializer = true", 7146 "initializer = true",
7196 "a, b, c = 1", 7147 "a, b, c = 1",
7197 "...args", 7148 "...args",
7198 "a, b, ...rest", 7149 "a, b, ...rest",
7199 "[a, b, ...rest]", 7150 "[a, b, ...rest]",
7200 "{ bindingPattern = {} }", 7151 "{ bindingPattern = {} }",
7201 "{ initializedBindingPattern } = { initializedBindingPattern: true }", 7152 "{ initializedBindingPattern } = { initializedBindingPattern: true }",
7202 NULL}; 7153 NULL};
7203 7154
7204 static const ParserFlag always_flags[] = { 7155 static const ParserFlag always_flags[] = {
7205 kAllowHarmonyArrowFunctions, kAllowHarmonyDefaultParameters, 7156 kAllowHarmonyDefaultParameters, kAllowHarmonyDestructuring,
7206 kAllowHarmonyDestructuring, kAllowHarmonyRestParameters, 7157 kAllowHarmonyRestParameters, kAllowHarmonySloppy, kAllowStrongMode};
7207 kAllowHarmonySloppy, kAllowStrongMode
7208 };
7209 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 7158 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
7210 arraysize(always_flags)); 7159 arraysize(always_flags));
7211 } 7160 }
7212 7161
7213 7162
7214 TEST(LetSloppyOnly) { 7163 TEST(LetSloppyOnly) {
7215 // clang-format off 7164 // clang-format off
7216 const char* context_data[][2] = { 7165 const char* context_data[][2] = {
7217 {"", ""}, 7166 {"", ""},
7218 {"{", "}"}, 7167 {"{", "}"},
(...skipping 12 matching lines...) Expand all
7231 "for (let in {}) {}", 7180 "for (let in {}) {}",
7232 NULL 7181 NULL
7233 }; 7182 };
7234 // clang-format on 7183 // clang-format on
7235 7184
7236 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, 7185 static const ParserFlag always_flags[] = {kAllowHarmonySloppy,
7237 kAllowHarmonySloppyLet}; 7186 kAllowHarmonySloppyLet};
7238 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, 7187 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
7239 arraysize(always_flags)); 7188 arraysize(always_flags));
7240 } 7189 }
OLDNEW
« no previous file with comments | « test/cctest/test-ast-expression-visitor.cc ('k') | test/cctest/test-typing-reset.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698