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

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: Fix more problems 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/globals.h ('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 5899 matching lines...) Expand 10 before | Expand all | Expand 10 after
7441 NULL 7444 NULL
7442 }; 7445 };
7443 // clang-format on 7446 // clang-format on
7444 7447
7445 static const ParserFlag always_flags[] = { 7448 static const ParserFlag always_flags[] = {
7446 kAllowHarmonyExponentiationOperator}; 7449 kAllowHarmonyExponentiationOperator};
7447 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, 7450 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
7448 arraysize(always_flags)); 7451 arraysize(always_flags));
7449 } 7452 }
7450 7453
7454 TEST(AsyncAwait) {
7455 // clang-format off
7456 const char* context_data[][2] = {
7457 { "'use strict';", "" },
7458 { "", "" },
7459 { NULL, NULL }
7460 };
7461
7462 const char* data[] = {
7463 "var asyncFn = async function() { await 1; };",
7464 "var asyncFn = async function withName() { await 1; };",
7465 "var asyncFn = async () => await 'test';",
7466 "var asyncFn = async x => await x + 'test';",
7467 "async function asyncFn() { await 1; }",
7468 "var O = { async method() { await 1; } }",
7469 "var O = { async ['meth' + 'od']() { await 1; } }",
7470 "var O = { async 'method'() { await 1; } }",
7471 "var O = { async 0() { await 1; } }",
7472 "async function await() {}",
7473 NULL
7474 };
7475 // clang-format on
7476
7477 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait};
7478 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
7479 arraysize(always_flags));
7480
7481 // clang-format off
7482 const char* async_body_context_data[][2] = {
7483 { "async function f() {", "}" },
7484 { "var f = async function() {", "}" },
7485 { "var f = async() => {", "}" },
7486 { "var O = { async method() {", "} }" },
7487 { "'use strict'; async function f() {", "}" },
7488 { "'use strict'; var f = async function() {", "}" },
7489 { "'use strict'; var f = async() => {", "}" },
7490 { "'use strict'; var O = { async method() {", "} }" },
7491 { NULL, NULL }
7492 };
7493
7494 const char* body_context_data[][2] = {
7495 { "function f() {", "}" },
7496 { "function* g() {", "}" },
7497 { "var f = function() {", "}" },
7498 { "var g = function*() {", "}" },
7499 { "var O = { method() {", "} }" },
7500 { "var O = { *method() {", "} }" },
7501 { "var f = () => {", "}" },
7502 { "'use strict'; function f() {", "}" },
7503 { "'use strict'; function* g() {", "}" },
7504 { "'use strict'; var f = function() {", "}" },
7505 { "'use strict'; var g = function*() {", "}" },
7506 { "'use strict'; var O = { method() {", "} }" },
7507 { "'use strict'; var O = { *method() {", "} }" },
7508 { "'use strict'; var f = () => {", "}" },
7509 { NULL, NULL }
7510 };
7511
7512 const char* body_data[] = {
7513 "var async = 1; return async;",
7514 "let async = 1; return async;",
7515 "const async = 1; return async;",
7516 "function async() {} return async();",
7517 "var async = async => async; return async();",
7518 "function foo() { var await = 1; return await; }",
7519 "function foo(await) { return await; }",
7520 "function* foo() { var await = 1; return await; }",
7521 "function* foo(await) { return await; }",
7522 "var f = (await) => await;",
7523 "var f = () => { var await = 1; return await; }",
7524 "var O = { method() { var await = 1; return await; } };",
7525 "var O = { method(await) { return await; } };",
7526 "var O = { *method() { var await = 1; return await; } };",
7527 "var O = { *method(await) { return await; } };",
7528 NULL
7529 };
7530 // clang-format on
7531
7532 RunParserSyncTest(async_body_context_data, body_data, kSuccess, NULL, 0,
7533 always_flags, arraysize(always_flags));
7534 RunParserSyncTest(body_context_data, body_data, kSuccess, NULL, 0,
7535 always_flags, arraysize(always_flags));
7536 }
7537
7538 TEST(AsyncAwaitErrors) {
7539 // clang-format off
7540 const char* context_data[][2] = {
7541 { "'use strict';", "" },
7542 { "", "" },
7543 { NULL, NULL }
7544 };
7545
7546 const char* strict_context_data[][2] = {
7547 { "'use strict';", "" },
7548 { NULL, NULL }
7549 };
7550
7551 const char* error_data[] = {
7552 "var asyncFn = async function() { var await = 1; };",
7553 "var asyncFn = async function() { var { await } = 1; };",
7554 "var asyncFn = async function() { var [ await ] = 1; };",
7555 "var asyncFn = async function await() {};",
7556 "var asyncFn = async () => var await = 'test';",
7557 "var asyncFn = async await => await + 'test';",
7558 "var asyncFn = async function(await) {};",
7559 "var asyncFn = async function() { return async (await) => {}; }",
7560 "var asyncFn = async (await) => 'test';",
7561 "var asyncFn = async x => { var await = 1; }",
7562 "var asyncFn = async x => { var { await } = 1; }",
7563 "var asyncFn = async x => { var [ await ] = 1; }",
7564 "async function f(await) {}",
7565 "async function f() { var await = 1; }",
7566 "async function f() { var { await } = 1; }",
7567 "async function f() { var [ await ] = 1; }",
7568
7569 "var O = { async method(a, a) {} }",
7570 "var O = { async ['meth' + 'od'](a, a) {} }",
7571 "var O = { async 'method'(a, a) {} }",
7572 "var O = { async 0(a, a) {} }",
7573
7574 "async function f() { var O = { async [await](a, a) {} } }",
7575
7576 "var asyncFn = async function() { await; }",
7577 "async function f() { await; }",
7578 "var O = { async method() { await; } };",
7579 "var f = async() => await;",
7580 "var f = async() => { await; };",
7581
7582 "var asyncFn = async function*() {}",
7583 "async function* f() {}",
7584 "var O = { *async method() {} };",
7585 "var O = { async *method() {} };",
7586 "var O = { async method*() {} };",
7587
7588 "var asyncFn = async function(x = await 1) { return x; }",
7589 "async function f(x = await 1) { return x; }",
7590 "var f = async(x = await 1) => x;",
7591 "var O = { async method(x = await 1) { return x; } };",
7592
7593 "var f = async(x = await) => 1;",
7594
7595 "class C { async constructor() {} }",
7596 "class C {}; class C2 extends C { async constructor() {} }",
7597 "class C { static async prototype() {} }",
7598 "class C {}; class C2 extends C { static async prototype() {} }",
7599 NULL
7600 };
7601
7602 const char* strict_error_data[] = {
7603 "var O = { async method(eval) {} }",
7604 "var O = { async ['meth' + 'od'](eval) {} }",
7605 "var O = { async 'method'(eval) {} }",
7606 "var O = { async 0(eval) {} }",
7607
7608 "var O = { async method(arguments) {} }",
7609 "var O = { async ['meth' + 'od'](arguments) {} }",
7610 "var O = { async 'method'(arguments) {} }",
7611 "var O = { async 0(arguments) {} }",
7612
7613 // TODO(caitp): preparser needs to report duplicadte parameter errors.
7614 // "var O = { async method(dupe, dupe) {} }",
7615 // "var f = async(dupe, dupe) => {}",
7616 NULL
7617 };
7618 // clang-format on
7619
7620 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait};
7621 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
7622 arraysize(always_flags));
7623 RunParserSyncTest(strict_context_data, strict_error_data, kError, NULL, 0,
7624 always_flags, arraysize(always_flags));
7625 }
7626
7451 TEST(RestrictiveForInErrors) { 7627 TEST(RestrictiveForInErrors) {
7452 // clang-format off 7628 // clang-format off
7453 const char* context_data[][2] = { 7629 const char* context_data[][2] = {
7454 { "'use strict'", "" }, 7630 { "'use strict'", "" },
7455 { "", "" }, 7631 { "", "" },
7456 { NULL, NULL } 7632 { NULL, NULL }
7457 }; 7633 };
7458 const char* error_data[] = { 7634 const char* error_data[] = {
7459 "for (var x = 0 in {});", 7635 "for (var x = 0 in {});",
7460 "for (const x = 0 in {});", 7636 "for (const x = 0 in {});",
7461 "for (let x = 0 in {});", 7637 "for (let x = 0 in {});",
7462 NULL 7638 NULL
7463 }; 7639 };
7464 // clang-format on 7640 // clang-format on
7465 7641
7466 static const ParserFlag always_flags[] = {kAllowHarmonyForIn}; 7642 static const ParserFlag always_flags[] = {kAllowHarmonyForIn};
7467 RunParserSyncTest(context_data, error_data, kError, nullptr, 0, always_flags, 7643 RunParserSyncTest(context_data, error_data, kError, nullptr, 0, always_flags,
7468 arraysize(always_flags)); 7644 arraysize(always_flags));
7469 } 7645 }
OLDNEW
« src/globals.h ('K') | « src/parsing/scanner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698