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

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

Issue 2637403008: [async-iteration] add support for for-await-of loops in Async Functions (Closed)
Patch Set: remove that comment Created 3 years, 10 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 | « src/runtime/runtime-internal.cc ('k') | test/mjsunit/harmony/for-await-of.js » ('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 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 1255
1256 enum ParserFlag { 1256 enum ParserFlag {
1257 kAllowLazy, 1257 kAllowLazy,
1258 kAllowNatives, 1258 kAllowNatives,
1259 kAllowHarmonyFunctionSent, 1259 kAllowHarmonyFunctionSent,
1260 kAllowHarmonyRestrictiveGenerators, 1260 kAllowHarmonyRestrictiveGenerators,
1261 kAllowHarmonyTrailingCommas, 1261 kAllowHarmonyTrailingCommas,
1262 kAllowHarmonyClassFields, 1262 kAllowHarmonyClassFields,
1263 kAllowHarmonyObjectRestSpread, 1263 kAllowHarmonyObjectRestSpread,
1264 kAllowHarmonyDynamicImport, 1264 kAllowHarmonyDynamicImport,
1265 kAllowHarmonyAsyncIteration,
1265 }; 1266 };
1266 1267
1267 enum ParserSyncTestResult { 1268 enum ParserSyncTestResult {
1268 kSuccessOrError, 1269 kSuccessOrError,
1269 kSuccess, 1270 kSuccess,
1270 kError 1271 kError
1271 }; 1272 };
1272 1273
1273 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) { 1274 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) {
1274 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives); 1275 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives);
1275 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent); 1276 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent);
1276 i::FLAG_harmony_restrictive_generators = 1277 i::FLAG_harmony_restrictive_generators =
1277 flags.Contains(kAllowHarmonyRestrictiveGenerators); 1278 flags.Contains(kAllowHarmonyRestrictiveGenerators);
1278 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas); 1279 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas);
1279 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields); 1280 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields);
1280 i::FLAG_harmony_object_rest_spread = 1281 i::FLAG_harmony_object_rest_spread =
1281 flags.Contains(kAllowHarmonyObjectRestSpread); 1282 flags.Contains(kAllowHarmonyObjectRestSpread);
1282 i::FLAG_harmony_dynamic_import = flags.Contains(kAllowHarmonyDynamicImport); 1283 i::FLAG_harmony_dynamic_import = flags.Contains(kAllowHarmonyDynamicImport);
1284 i::FLAG_harmony_async_iteration = flags.Contains(kAllowHarmonyAsyncIteration);
1283 } 1285 }
1284 1286
1285 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { 1287 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) {
1286 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1288 parser->set_allow_natives(flags.Contains(kAllowNatives));
1287 parser->set_allow_harmony_function_sent( 1289 parser->set_allow_harmony_function_sent(
1288 flags.Contains(kAllowHarmonyFunctionSent)); 1290 flags.Contains(kAllowHarmonyFunctionSent));
1289 parser->set_allow_harmony_restrictive_generators( 1291 parser->set_allow_harmony_restrictive_generators(
1290 flags.Contains(kAllowHarmonyRestrictiveGenerators)); 1292 flags.Contains(kAllowHarmonyRestrictiveGenerators));
1291 parser->set_allow_harmony_trailing_commas( 1293 parser->set_allow_harmony_trailing_commas(
1292 flags.Contains(kAllowHarmonyTrailingCommas)); 1294 flags.Contains(kAllowHarmonyTrailingCommas));
1293 parser->set_allow_harmony_class_fields( 1295 parser->set_allow_harmony_class_fields(
1294 flags.Contains(kAllowHarmonyClassFields)); 1296 flags.Contains(kAllowHarmonyClassFields));
1295 parser->set_allow_harmony_object_rest_spread( 1297 parser->set_allow_harmony_object_rest_spread(
1296 flags.Contains(kAllowHarmonyObjectRestSpread)); 1298 flags.Contains(kAllowHarmonyObjectRestSpread));
1297 parser->set_allow_harmony_dynamic_import( 1299 parser->set_allow_harmony_dynamic_import(
1298 flags.Contains(kAllowHarmonyDynamicImport)); 1300 flags.Contains(kAllowHarmonyDynamicImport));
1301 parser->set_allow_harmony_async_iteration(
1302 flags.Contains(kAllowHarmonyAsyncIteration));
1299 } 1303 }
1300 1304
1301 void TestParserSyncWithFlags(i::Handle<i::String> source, 1305 void TestParserSyncWithFlags(i::Handle<i::String> source,
1302 i::EnumSet<ParserFlag> flags, 1306 i::EnumSet<ParserFlag> flags,
1303 ParserSyncTestResult result, 1307 ParserSyncTestResult result,
1304 bool is_module = false, bool test_preparser = true, 1308 bool is_module = false, bool test_preparser = true,
1305 bool ignore_error_msg = false) { 1309 bool ignore_error_msg = false) {
1306 i::Isolate* isolate = CcTest::i_isolate(); 1310 i::Isolate* isolate = CcTest::i_isolate();
1307 i::Factory* factory = isolate->factory(); 1311 i::Factory* factory = isolate->factory();
1308 1312
(...skipping 8150 matching lines...) Expand 10 before | Expand all | Expand 10 after
9459 "function l\u0065t() { }", 9463 "function l\u0065t() { }",
9460 "(function l\u0065t() { })", 9464 "(function l\u0065t() { })",
9461 "async function l\u0065t() { }", 9465 "async function l\u0065t() { }",
9462 "(async function l\u0065t() { })", 9466 "(async function l\u0065t() { })",
9463 "l\u0065t => 42", 9467 "l\u0065t => 42",
9464 "async l\u0065t => 42", 9468 "async l\u0065t => 42",
9465 NULL}; 9469 NULL};
9466 9470
9467 RunParserSyncTest(context_data, statement_data, kSuccess); 9471 RunParserSyncTest(context_data, statement_data, kSuccess);
9468 } 9472 }
9473
9474 TEST(ForAwaitOf) {
9475 // clang-format off
9476 const char* context_data[][2] = {
9477 { "async function f() { for await ", " ; }" },
9478 { "async function f() { for await ", " { } }" },
9479 { "async function f() { 'use strict'; for await ", " ; }" },
9480 { "async function f() { 'use strict'; for await ", " { } }" },
9481 { "async function f() { for\nawait ", " ; }" },
9482 { "async function f() { for\nawait ", " { } }" },
9483 { "async function f() { 'use strict'; for\nawait ", " ; }" },
9484 { "async function f() { 'use strict'; for\nawait ", " { } }" },
9485 { "async function f() { 'use strict'; for\nawait ", " { } }" },
9486 { "async function f() { for await\n", " ; }" },
9487 { "async function f() { for await\n", " { } }" },
9488 { "async function f() { 'use strict'; for await\n", " ; }" },
9489 { "async function f() { 'use strict'; for await\n", " { } }" },
9490 { NULL, NULL }
9491 };
9492
9493 const char* context_data2[][2] = {
9494 { "async function f() { let a; for await ", " ; }" },
9495 { "async function f() { let a; for await ", " { } }" },
9496 { "async function f() { 'use strict'; let a; for await ", " ; }" },
9497 { "async function f() { 'use strict'; let a; for await ", " { } }" },
9498 { "async function f() { let a; for\nawait ", " ; }" },
9499 { "async function f() { let a; for\nawait ", " { } }" },
9500 { "async function f() { 'use strict'; let a; for\nawait ", " ; }" },
9501 { "async function f() { 'use strict'; let a; for\nawait ", " { } }" },
9502 { "async function f() { 'use strict'; let a; for\nawait ", " { } }" },
9503 { "async function f() { let a; for await\n", " ; }" },
9504 { "async function f() { let a; for await\n", " { } }" },
9505 { "async function f() { 'use strict'; let a; for await\n", " ; }" },
9506 { "async function f() { 'use strict'; let a; for await\n", " { } }" },
9507 { NULL, NULL }
9508 };
9509
9510 const char* expr_data[] = {
9511 // Primary Expressions
9512 "(a of [])",
9513 "(a.b of [])",
9514 "([a] of [])",
9515 "([a = 1] of [])",
9516 "([a = 1, ...b] of [])",
9517 "({a} of [])",
9518 "({a: a} of [])",
9519 "({'a': a} of [])",
9520 "({\"a\": a} of [])",
9521 "({[Symbol.iterator]: a} of [])",
9522 "({0: a} of [])",
9523 "({a = 1} of [])",
9524 "({a: a = 1} of [])",
9525 "({'a': a = 1} of [])",
9526 "({\"a\": a = 1} of [])",
9527 "({[Symbol.iterator]: a = 1} of [])",
9528 "({0: a = 1} of [])",
9529 NULL
9530 };
9531
9532 const char* var_data[] = {
9533 // VarDeclarations
9534 "(var a of [])",
9535 "(var [a] of [])",
9536 "(var [a = 1] of [])",
9537 "(var [a = 1, ...b] of [])",
9538 "(var {a} of [])",
9539 "(var {a: a} of [])",
9540 "(var {'a': a} of [])",
9541 "(var {\"a\": a} of [])",
9542 "(var {[Symbol.iterator]: a} of [])",
9543 "(var {0: a} of [])",
9544 "(var {a = 1} of [])",
9545 "(var {a: a = 1} of [])",
9546 "(var {'a': a = 1} of [])",
9547 "(var {\"a\": a = 1} of [])",
9548 "(var {[Symbol.iterator]: a = 1} of [])",
9549 "(var {0: a = 1} of [])",
9550 NULL
9551 };
9552
9553 const char* lexical_data[] = {
9554 // LexicalDeclartions
9555 "(let a of [])",
9556 "(let [a] of [])",
9557 "(let [a = 1] of [])",
9558 "(let [a = 1, ...b] of [])",
9559 "(let {a} of [])",
9560 "(let {a: a} of [])",
9561 "(let {'a': a} of [])",
9562 "(let {\"a\": a} of [])",
9563 "(let {[Symbol.iterator]: a} of [])",
9564 "(let {0: a} of [])",
9565 "(let {a = 1} of [])",
9566 "(let {a: a = 1} of [])",
9567 "(let {'a': a = 1} of [])",
9568 "(let {\"a\": a = 1} of [])",
9569 "(let {[Symbol.iterator]: a = 1} of [])",
9570 "(let {0: a = 1} of [])",
9571
9572 "(const a of [])",
9573 "(const [a] of [])",
9574 "(const [a = 1] of [])",
9575 "(const [a = 1, ...b] of [])",
9576 "(const {a} of [])",
9577 "(const {a: a} of [])",
9578 "(const {'a': a} of [])",
9579 "(const {\"a\": a} of [])",
9580 "(const {[Symbol.iterator]: a} of [])",
9581 "(const {0: a} of [])",
9582 "(const {a = 1} of [])",
9583 "(const {a: a = 1} of [])",
9584 "(const {'a': a = 1} of [])",
9585 "(const {\"a\": a = 1} of [])",
9586 "(const {[Symbol.iterator]: a = 1} of [])",
9587 "(const {0: a = 1} of [])",
9588 NULL
9589 };
9590 // clang-format on
9591 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncIteration};
9592 RunParserSyncTest(context_data, expr_data, kSuccess, NULL, 0, always_flags,
9593 arraysize(always_flags));
9594 RunParserSyncTest(context_data2, expr_data, kSuccess, NULL, 0, always_flags,
9595 arraysize(always_flags));
9596
9597 RunParserSyncTest(context_data, var_data, kSuccess, NULL, 0, always_flags,
9598 arraysize(always_flags));
9599 // TODO(marja): PreParser doesn't report early errors.
9600 // (https://bugs.chromium.org/p/v8/issues/detail?id=2728)
9601 // RunParserSyncTest(context_data2, var_data, kError, NULL, 0, always_flags,
9602 // arraysize(always_flags));
9603
9604 RunParserSyncTest(context_data, lexical_data, kSuccess, NULL, 0, always_flags,
9605 arraysize(always_flags));
9606 RunParserSyncTest(context_data2, lexical_data, kSuccess, NULL, 0,
9607 always_flags, arraysize(always_flags));
9608 }
9609
9610 TEST(ForAwaitOfErrors) {
9611 // clang-format off
9612 const char* context_data[][2] = {
9613 { "async function f() { for await ", " ; }" },
9614 { "async function f() { for await ", " { } }" },
9615 { "async function f() { 'use strict'; for await ", " ; }" },
9616 { "async function f() { 'use strict'; for await ", " { } }" },
9617 { NULL, NULL }
9618 };
9619
9620 const char* data[] = {
9621 // Primary Expressions
9622 "(a = 1 of [])",
9623 "(a = 1) of [])",
9624 "(a.b = 1 of [])",
9625 "((a.b = 1) of [])",
9626 "([a] = 1 of [])",
9627 "(([a] = 1) of [])",
9628 "([a = 1] = 1 of [])",
9629 "(([a = 1] = 1) of [])",
9630 "([a = 1 = 1, ...b] = 1 of [])",
9631 "(([a = 1 = 1, ...b] = 1) of [])",
9632 "({a} = 1 of [])",
9633 "(({a} = 1) of [])",
9634 "({a: a} = 1 of [])",
9635 "(({a: a} = 1) of [])",
9636 "({'a': a} = 1 of [])",
9637 "(({'a': a} = 1) of [])",
9638 "({\"a\": a} = 1 of [])",
9639 "(({\"a\": a} = 1) of [])",
9640 "({[Symbol.iterator]: a} = 1 of [])",
9641 "(({[Symbol.iterator]: a} = 1) of [])",
9642 "({0: a} = 1 of [])",
9643 "(({0: a} = 1) of [])",
9644 "({a = 1} = 1 of [])",
9645 "(({a = 1} = 1) of [])",
9646 "({a: a = 1} = 1 of [])",
9647 "(({a: a = 1} = 1) of [])",
9648 "({'a': a = 1} = 1 of [])",
9649 "(({'a': a = 1} = 1) of [])",
9650 "({\"a\": a = 1} = 1 of [])",
9651 "(({\"a\": a = 1} = 1) of [])",
9652 "({[Symbol.iterator]: a = 1} = 1 of [])",
9653 "(({[Symbol.iterator]: a = 1} = 1) of [])",
9654 "({0: a = 1} = 1 of [])",
9655 "(({0: a = 1} = 1) of [])",
9656 "(function a() {} of [])",
9657 "([1] of [])",
9658 "({a: 1} of [])"
9659
9660 // VarDeclarations
9661 "(var a = 1 of [])",
9662 "(var a, b of [])",
9663 "(var [a] = 1 of [])",
9664 "(var [a], b of [])",
9665 "(var [a = 1] = 1 of [])",
9666 "(var [a = 1], b of [])",
9667 "(var [a = 1 = 1, ...b] of [])",
9668 "(var [a = 1, ...b], c of [])",
9669 "(var {a} = 1 of [])",
9670 "(var {a}, b of [])",
9671 "(var {a: a} = 1 of [])",
9672 "(var {a: a}, b of [])",
9673 "(var {'a': a} = 1 of [])",
9674 "(var {'a': a}, b of [])",
9675 "(var {\"a\": a} = 1 of [])",
9676 "(var {\"a\": a}, b of [])",
9677 "(var {[Symbol.iterator]: a} = 1 of [])",
9678 "(var {[Symbol.iterator]: a}, b of [])",
9679 "(var {0: a} = 1 of [])",
9680 "(var {0: a}, b of [])",
9681 "(var {a = 1} = 1 of [])",
9682 "(var {a = 1}, b of [])",
9683 "(var {a: a = 1} = 1 of [])",
9684 "(var {a: a = 1}, b of [])",
9685 "(var {'a': a = 1} = 1 of [])",
9686 "(var {'a': a = 1}, b of [])",
9687 "(var {\"a\": a = 1} = 1 of [])",
9688 "(var {\"a\": a = 1}, b of [])",
9689 "(var {[Symbol.iterator]: a = 1} = 1 of [])",
9690 "(var {[Symbol.iterator]: a = 1}, b of [])",
9691 "(var {0: a = 1} = 1 of [])",
9692 "(var {0: a = 1}, b of [])",
9693
9694 // LexicalDeclartions
9695 "(let a = 1 of [])",
9696 "(let a, b of [])",
9697 "(let [a] = 1 of [])",
9698 "(let [a], b of [])",
9699 "(let [a = 1] = 1 of [])",
9700 "(let [a = 1], b of [])",
9701 "(let [a = 1, ...b] = 1 of [])",
9702 "(let [a = 1, ...b], c of [])",
9703 "(let {a} = 1 of [])",
9704 "(let {a}, b of [])",
9705 "(let {a: a} = 1 of [])",
9706 "(let {a: a}, b of [])",
9707 "(let {'a': a} = 1 of [])",
9708 "(let {'a': a}, b of [])",
9709 "(let {\"a\": a} = 1 of [])",
9710 "(let {\"a\": a}, b of [])",
9711 "(let {[Symbol.iterator]: a} = 1 of [])",
9712 "(let {[Symbol.iterator]: a}, b of [])",
9713 "(let {0: a} = 1 of [])",
9714 "(let {0: a}, b of [])",
9715 "(let {a = 1} = 1 of [])",
9716 "(let {a = 1}, b of [])",
9717 "(let {a: a = 1} = 1 of [])",
9718 "(let {a: a = 1}, b of [])",
9719 "(let {'a': a = 1} = 1 of [])",
9720 "(let {'a': a = 1}, b of [])",
9721 "(let {\"a\": a = 1} = 1 of [])",
9722 "(let {\"a\": a = 1}, b of [])",
9723 "(let {[Symbol.iterator]: a = 1} = 1 of [])",
9724 "(let {[Symbol.iterator]: a = 1}, b of [])",
9725 "(let {0: a = 1} = 1 of [])",
9726 "(let {0: a = 1}, b of [])",
9727
9728 "(const a = 1 of [])",
9729 "(const a, b of [])",
9730 "(const [a] = 1 of [])",
9731 "(const [a], b of [])",
9732 "(const [a = 1] = 1 of [])",
9733 "(const [a = 1], b of [])",
9734 "(const [a = 1, ...b] = 1 of [])",
9735 "(const [a = 1, ...b], b of [])",
9736 "(const {a} = 1 of [])",
9737 "(const {a}, b of [])",
9738 "(const {a: a} = 1 of [])",
9739 "(const {a: a}, b of [])",
9740 "(const {'a': a} = 1 of [])",
9741 "(const {'a': a}, b of [])",
9742 "(const {\"a\": a} = 1 of [])",
9743 "(const {\"a\": a}, b of [])",
9744 "(const {[Symbol.iterator]: a} = 1 of [])",
9745 "(const {[Symbol.iterator]: a}, b of [])",
9746 "(const {0: a} = 1 of [])",
9747 "(const {0: a}, b of [])",
9748 "(const {a = 1} = 1 of [])",
9749 "(const {a = 1}, b of [])",
9750 "(const {a: a = 1} = 1 of [])",
9751 "(const {a: a = 1}, b of [])",
9752 "(const {'a': a = 1} = 1 of [])",
9753 "(const {'a': a = 1}, b of [])",
9754 "(const {\"a\": a = 1} = 1 of [])",
9755 "(const {\"a\": a = 1}, b of [])",
9756 "(const {[Symbol.iterator]: a = 1} = 1 of [])",
9757 "(const {[Symbol.iterator]: a = 1}, b of [])",
9758 "(const {0: a = 1} = 1 of [])",
9759 "(const {0: a = 1}, b of [])",
9760
9761 NULL
9762 };
9763 // clang-format on
9764 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncIteration};
9765 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
9766 arraysize(always_flags));
9767 }
9768
9769 TEST(ForAwaitOfFunctionDeclaration) {
9770 // clang-format off
9771 const char* context_data[][2] = {
9772 { "async function f() {", "}" },
9773 { "async function f() { 'use strict'; ", "}" },
9774 { NULL, NULL }
9775 };
9776
9777 const char* data[] = {
9778 "for await (x of []) function d() {};",
9779 "for await (x of []) function d() {}; return d;",
9780 "for await (x of []) function* g() {};",
9781 "for await (x of []) function* g() {}; return g;",
9782 // TODO(caitp): handle async function declarations in ParseScopedStatement.
9783 // "for await (x of []) async function a() {};",
9784 // "for await (x of []) async function a() {}; return a;",
9785 NULL
9786 };
9787
9788 // clang-format on
9789 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncIteration};
9790 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
9791 arraysize(always_flags));
9792 }
OLDNEW
« no previous file with comments | « src/runtime/runtime-internal.cc ('k') | test/mjsunit/harmony/for-await-of.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698