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

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

Issue 1841543003: [esnext] implement frontend changes for async/await proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase for dependent CLs Created 4 years, 7 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
« src/parsing/scanner.cc ('K') | « src/parsing/scanner.cc ('k') | no next file » | 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 1490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 data.Dispose(); 1501 data.Dispose();
1502 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); 1502 return i::MessageTemplate::FormatMessage(isolate, message, arg_object);
1503 } 1503 }
1504 1504
1505 enum ParserFlag { 1505 enum ParserFlag {
1506 kAllowLazy, 1506 kAllowLazy,
1507 kAllowNatives, 1507 kAllowNatives,
1508 kAllowHarmonyFunctionSent, 1508 kAllowHarmonyFunctionSent,
1509 kAllowHarmonyRestrictiveDeclarations, 1509 kAllowHarmonyRestrictiveDeclarations,
1510 kAllowHarmonyExponentiationOperator, 1510 kAllowHarmonyExponentiationOperator,
1511 kAllowHarmonyForIn 1511 kAllowHarmonyForIn,
1512 kAllowHarmonyAsyncAwait
1512 }; 1513 };
1513 1514
1514 enum ParserSyncTestResult { 1515 enum ParserSyncTestResult {
1515 kSuccessOrError, 1516 kSuccessOrError,
1516 kSuccess, 1517 kSuccess,
1517 kError 1518 kError
1518 }; 1519 };
1519 1520
1520 template <typename Traits> 1521 template <typename Traits>
1521 void SetParserFlags(i::ParserBase<Traits>* parser, 1522 void SetParserFlags(i::ParserBase<Traits>* parser,
1522 i::EnumSet<ParserFlag> flags) { 1523 i::EnumSet<ParserFlag> flags) {
1523 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1524 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1524 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1525 parser->set_allow_natives(flags.Contains(kAllowNatives));
1525 parser->set_allow_harmony_function_sent( 1526 parser->set_allow_harmony_function_sent(
1526 flags.Contains(kAllowHarmonyFunctionSent)); 1527 flags.Contains(kAllowHarmonyFunctionSent));
1527 parser->set_allow_harmony_restrictive_declarations( 1528 parser->set_allow_harmony_restrictive_declarations(
1528 flags.Contains(kAllowHarmonyRestrictiveDeclarations)); 1529 flags.Contains(kAllowHarmonyRestrictiveDeclarations));
1529 parser->set_allow_harmony_exponentiation_operator( 1530 parser->set_allow_harmony_exponentiation_operator(
1530 flags.Contains(kAllowHarmonyExponentiationOperator)); 1531 flags.Contains(kAllowHarmonyExponentiationOperator));
1531 parser->set_allow_harmony_for_in(flags.Contains(kAllowHarmonyForIn)); 1532 parser->set_allow_harmony_for_in(flags.Contains(kAllowHarmonyForIn));
1533 parser->set_allow_harmony_async_await(
1534 flags.Contains(kAllowHarmonyAsyncAwait));
1532 } 1535 }
1533 1536
1534 1537
1535 void TestParserSyncWithFlags(i::Handle<i::String> source, 1538 void TestParserSyncWithFlags(i::Handle<i::String> source,
1536 i::EnumSet<ParserFlag> flags, 1539 i::EnumSet<ParserFlag> flags,
1537 ParserSyncTestResult result, 1540 ParserSyncTestResult result,
1538 bool is_module = false, 1541 bool is_module = false,
1539 bool test_preparser = true) { 1542 bool test_preparser = true) {
1540 i::Isolate* isolate = CcTest::i_isolate(); 1543 i::Isolate* isolate = CcTest::i_isolate();
1541 i::Factory* factory = isolate->factory(); 1544 i::Factory* factory = isolate->factory();
(...skipping 5892 matching lines...) Expand 10 before | Expand all | Expand 10 after
7434 NULL 7437 NULL
7435 }; 7438 };
7436 // clang-format on 7439 // clang-format on
7437 7440
7438 static const ParserFlag always_flags[] = { 7441 static const ParserFlag always_flags[] = {
7439 kAllowHarmonyExponentiationOperator}; 7442 kAllowHarmonyExponentiationOperator};
7440 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, 7443 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
7441 arraysize(always_flags)); 7444 arraysize(always_flags));
7442 } 7445 }
7443 7446
7447 TEST(AsyncAwait) {
7448 // clang-format off
7449 const char* context_data[][2] = {
7450 { "'use strict';", "" },
7451 { "", "" },
7452 { NULL, NULL }
7453 };
7454
7455 const char* data[] = {
7456 "var asyncFn = async function() { await 1; };",
7457 "var asyncFn = async function withName() { await 1; };",
7458 "var asyncFn = async () => await 'test';",
7459 "var asyncFn = async x => await x + 'test';",
7460 "async function asyncFn() { await 1; }",
7461 "var O = { async method() { await 1; } }",
7462 "var O = { async ['meth' + 'od']() { await 1; } }",
7463 "var O = { async 'method'() { await 1; } }",
7464 "var O = { async 0() { await 1; } }",
Dan Ehrenberg 2016/05/05 01:14:40 Maybe some tests which check that - async is a con
caitp (gmail) 2016/05/05 01:36:57 Acknowledged --- Sounds good.
7465 NULL
7466 };
7467 // clang-format on
7468
7469 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait};
7470 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
7471 arraysize(always_flags));
7472 }
7473
7474 TEST(AsyncAwaitErrors) {
7475 // clang-format off
7476 const char* context_data[][2] = {
7477 { "'use strict';", "" },
7478 { "", "" },
7479 { NULL, NULL }
7480 };
7481
7482 const char* strict_context_data[][2] = {
7483 { "'use strict';", "" },
7484 { NULL, NULL }
7485 };
7486
7487 const char* error_data[] = {
7488 "var asyncFn = async function() { var await = 1; };",
7489 "var asyncFn = async function() { var { await } = 1; };",
7490 "var asyncFn = async function() { var [ await ] = 1; };",
7491 "var asyncFn = async function await() {};",
7492 "var asyncFn = async () => var await = 'test';",
7493 "var asyncFn = async await => await + 'test';",
7494 "var asyncFn = async function(await) {};",
7495 "var asyncFn = async function() { return async (await) => {}; }",
7496 "var asyncFn = async (await) => 'test';",
7497 "var asyncFn = async x => { var await = 1; }",
7498 "var asyncFn = async x => { var { await } = 1; }",
7499 "var asyncFn = async x => { var [ await ] = 1; }",
7500 "async function f(await) {}",
7501 "async function f() { var await = 1; }",
7502 "async function f() { var { await } = 1; }",
7503 "async function f() { var [ await ] = 1; }",
7504
7505 "var O = { async method(a, a) {} }",
7506 "var O = { async ['meth' + 'od'](a, a) {} }",
7507 "var O = { async 'method'(a, a) {} }",
7508 "var O = { async 0(a, a) {} }",
7509
7510 "async function f() { var O = { async [await](a, a) {} } }",
Dan Ehrenberg 2016/05/05 01:14:40 - async generators and constructors are a syntax e
caitp (gmail) 2016/05/05 21:49:36 Added a bunch of these
7511 NULL
7512 };
7513
7514 const char* strict_error_data[] = {
7515 "var O = { async method(eval) {} }",
7516 "var O = { async ['meth' + 'od'](eval) {} }",
7517 "var O = { async 'method'(eval) {} }",
7518 "var O = { async 0(eval) {} }",
7519
7520 "var O = { async method(arguments) {} }",
7521 "var O = { async ['meth' + 'od'](arguments) {} }",
7522 "var O = { async 'method'(arguments) {} }",
7523 "var O = { async 0(arguments) {} }",
Dan Ehrenberg 2016/05/05 01:14:40 - async(a, a) => a (For this one in particular, I'
caitp (gmail) 2016/05/05 21:49:36 Duplicate parameters in async arrow functions beha
7524 NULL
7525 };
7526 // clang-format on
7527
7528 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait};
7529 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
7530 arraysize(always_flags));
7531 RunParserSyncTest(strict_context_data, strict_error_data, kError, NULL, 0,
7532 always_flags, arraysize(always_flags));
7533 }
7534
7444 TEST(RestrictiveForInErrors) { 7535 TEST(RestrictiveForInErrors) {
7445 // clang-format off 7536 // clang-format off
7446 const char* context_data[][2] = { 7537 const char* context_data[][2] = {
7447 { "'use strict'", "" }, 7538 { "'use strict'", "" },
7448 { "", "" }, 7539 { "", "" },
7449 { NULL, NULL } 7540 { NULL, NULL }
7450 }; 7541 };
7451 const char* error_data[] = { 7542 const char* error_data[] = {
7452 "for (var x = 0 in {});", 7543 "for (var x = 0 in {});",
7453 "for (const x = 0 in {});", 7544 "for (const x = 0 in {});",
7454 "for (let x = 0 in {});", 7545 "for (let x = 0 in {});",
7455 NULL 7546 NULL
7456 }; 7547 };
7457 // clang-format on 7548 // clang-format on
7458 7549
7459 static const ParserFlag always_flags[] = {kAllowHarmonyForIn}; 7550 static const ParserFlag always_flags[] = {kAllowHarmonyForIn};
7460 RunParserSyncTest(context_data, error_data, kError, nullptr, 0, always_flags, 7551 RunParserSyncTest(context_data, error_data, kError, nullptr, 0, always_flags,
7461 arraysize(always_flags)); 7552 arraysize(always_flags));
7462 } 7553 }
OLDNEW
« src/parsing/scanner.cc ('K') | « src/parsing/scanner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698