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

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: ...and uncomment the previously failing tests... 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
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 8133 matching lines...) Expand 10 before | Expand all | Expand 10 after
9442 DCHECK_NULL(scope->sibling()); 9446 DCHECK_NULL(scope->sibling());
9443 DCHECK(scope->is_function_scope()); 9447 DCHECK(scope->is_function_scope());
9444 const i::AstRawString* var_name = 9448 const i::AstRawString* var_name =
9445 info.ast_value_factory()->GetOneByteString("my_var"); 9449 info.ast_value_factory()->GetOneByteString("my_var");
9446 i::Variable* var = scope->Lookup(var_name); 9450 i::Variable* var = scope->Lookup(var_name);
9447 CHECK_EQ(inners[i].ctxt_allocate, 9451 CHECK_EQ(inners[i].ctxt_allocate,
9448 i::ScopeTestHelper::MustAllocateInContext(var)); 9452 i::ScopeTestHelper::MustAllocateInContext(var));
9449 } 9453 }
9450 } 9454 }
9451 } 9455 }
9456
9457 TEST(ForAwaitOf) {
9458 // clang-format off
9459 const char* context_data[][2] = {
9460 { "async function f() { for await ", " ; }" },
9461 { "async function f() { for await ", " { } }" },
9462 { "async function f() { 'use strict'; for await ", " ; }" },
9463 { "async function f() { 'use strict'; for await ", " { } }" },
9464 { "async function f() { for\nawait ", " ; }" },
9465 { "async function f() { for\nawait ", " { } }" },
9466 { "async function f() { 'use strict'; for\nawait ", " ; }" },
9467 { "async function f() { 'use strict'; for\nawait ", " { } }" },
9468 { "async function f() { 'use strict'; for\nawait ", " { } }" },
9469 { "async function f() { for await\n", " ; }" },
9470 { "async function f() { for await\n", " { } }" },
9471 { "async function f() { 'use strict'; for await\n", " ; }" },
9472 { "async function f() { 'use strict'; for await\n", " { } }" },
9473 { NULL, NULL }
9474 };
9475
9476 const char* context_data2[][2] = {
9477 { "async function f() { let a; for await ", " ; }" },
9478 { "async function f() { let a; for await ", " { } }" },
9479 { "async function f() { 'use strict'; let a; for await ", " ; }" },
9480 { "async function f() { 'use strict'; let a; for await ", " { } }" },
9481 { "async function f() { let a; for\nawait ", " ; }" },
9482 { "async function f() { let a; for\nawait ", " { } }" },
9483 { "async function f() { 'use strict'; let a; for\nawait ", " ; }" },
9484 { "async function f() { 'use strict'; let a; for\nawait ", " { } }" },
9485 { "async function f() { 'use strict'; let a; for\nawait ", " { } }" },
9486 { "async function f() { let a; for await\n", " ; }" },
9487 { "async function f() { let a; for await\n", " { } }" },
9488 { "async function f() { 'use strict'; let a; for await\n", " ; }" },
9489 { "async function f() { 'use strict'; let a; for await\n", " { } }" },
9490 { NULL, NULL }
9491 };
9492
9493 const char* expr_data[] = {
9494 // Primary Expressions
9495 "(a of [])",
9496 "(a.b of [])",
9497 "([a] of [])",
9498 "([a = 1] of [])",
9499 "([a = 1, ...b] of [])",
9500 "({a} of [])",
9501 "({a: a} of [])",
9502 "({'a': a} of [])",
9503 "({\"a\": a} of [])",
9504 "({[Symbol.iterator]: a} of [])",
9505 "({0: a} of [])",
9506 "({a = 1} of [])",
9507 "({a: a = 1} of [])",
9508 "({'a': a = 1} of [])",
9509 "({\"a\": a = 1} of [])",
9510 "({[Symbol.iterator]: a = 1} of [])",
9511 "({0: a = 1} of [])",
9512 NULL
9513 };
9514
9515 const char* var_data[] = {
9516 // VarDeclarations
9517 "(var a of [])",
9518 "(var [a] of [])",
9519 "(var [a = 1] of [])",
9520 "(var [a = 1, ...b] of [])",
9521 "(var {a} of [])",
9522 "(var {a: a} of [])",
9523 "(var {'a': a} of [])",
9524 "(var {\"a\": a} of [])",
9525 "(var {[Symbol.iterator]: a} of [])",
9526 "(var {0: a} of [])",
9527 "(var {a = 1} of [])",
9528 "(var {a: a = 1} of [])",
9529 "(var {'a': a = 1} of [])",
9530 "(var {\"a\": a = 1} of [])",
9531 "(var {[Symbol.iterator]: a = 1} of [])",
9532 "(var {0: a = 1} of [])",
9533 NULL
9534 };
9535
9536 const char* lexical_data[] = {
9537 // LexicalDeclartions
9538 "(let a of [])",
9539 "(let [a] of [])",
9540 "(let [a = 1] of [])",
9541 "(let [a = 1, ...b] of [])",
9542 "(let {a} of [])",
9543 "(let {a: a} of [])",
9544 "(let {'a': a} of [])",
9545 "(let {\"a\": a} of [])",
9546 "(let {[Symbol.iterator]: a} of [])",
9547 "(let {0: a} of [])",
9548 "(let {a = 1} of [])",
9549 "(let {a: a = 1} of [])",
9550 "(let {'a': a = 1} of [])",
9551 "(let {\"a\": a = 1} of [])",
9552 "(let {[Symbol.iterator]: a = 1} of [])",
9553 "(let {0: a = 1} of [])",
9554
9555 "(const a of [])",
9556 "(const [a] of [])",
9557 "(const [a = 1] of [])",
9558 "(const [a = 1, ...b] of [])",
9559 "(const {a} of [])",
9560 "(const {a: a} of [])",
9561 "(const {'a': a} of [])",
9562 "(const {\"a\": a} of [])",
9563 "(const {[Symbol.iterator]: a} of [])",
9564 "(const {0: a} of [])",
9565 "(const {a = 1} of [])",
9566 "(const {a: a = 1} of [])",
9567 "(const {'a': a = 1} of [])",
9568 "(const {\"a\": a = 1} of [])",
9569 "(const {[Symbol.iterator]: a = 1} of [])",
9570 "(const {0: a = 1} of [])",
9571 NULL
9572 };
9573 // clang-format on
9574 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncIteration};
9575 RunParserSyncTest(context_data, expr_data, kSuccess, NULL, 0, always_flags,
9576 arraysize(always_flags));
9577 RunParserSyncTest(context_data2, expr_data, kSuccess, NULL, 0, always_flags,
9578 arraysize(always_flags));
9579
9580 RunParserSyncTest(context_data, var_data, kSuccess, NULL, 0, always_flags,
9581 arraysize(always_flags));
9582 // TODO(marja): PreParser doesn't report early errors.
9583 // (https://bugs.chromium.org/p/v8/issues/detail?id=2728)
9584 // RunParserSyncTest(context_data2, var_data, kError, NULL, 0, always_flags,
9585 // arraysize(always_flags));
9586
9587 RunParserSyncTest(context_data, lexical_data, kSuccess, NULL, 0, always_flags,
9588 arraysize(always_flags));
9589 RunParserSyncTest(context_data2, lexical_data, kSuccess, NULL, 0,
9590 always_flags, arraysize(always_flags));
9591 }
9592
9593 TEST(ForAwaitOfErrors) {
9594 // clang-format off
9595 const char* context_data[][2] = {
9596 { "async function f() { for await ", " ; }" },
9597 { "async function f() { for await ", " { } }" },
9598 { "async function f() { 'use strict'; for await ", " ; }" },
9599 { "async function f() { 'use strict'; for await ", " { } }" },
9600 { NULL, NULL }
9601 };
9602
9603 const char* data[] = {
9604 // Primary Expressions
9605 "(a = 1 of [])",
9606 "(a = 1) of [])",
9607 "(a.b = 1 of [])",
9608 "((a.b = 1) of [])",
9609 "([a] = 1 of [])",
9610 "(([a] = 1) of [])",
9611 "([a = 1] = 1 of [])",
9612 "(([a = 1] = 1) of [])",
9613 "([a = 1 = 1, ...b] = 1 of [])",
9614 "(([a = 1 = 1, ...b] = 1) of [])",
9615 "({a} = 1 of [])",
9616 "(({a} = 1) of [])",
9617 "({a: a} = 1 of [])",
9618 "(({a: a} = 1) of [])",
9619 "({'a': a} = 1 of [])",
9620 "(({'a': a} = 1) of [])",
9621 "({\"a\": a} = 1 of [])",
9622 "(({\"a\": a} = 1) of [])",
9623 "({[Symbol.iterator]: a} = 1 of [])",
9624 "(({[Symbol.iterator]: a} = 1) of [])",
9625 "({0: a} = 1 of [])",
9626 "(({0: a} = 1) of [])",
9627 "({a = 1} = 1 of [])",
9628 "(({a = 1} = 1) of [])",
9629 "({a: a = 1} = 1 of [])",
9630 "(({a: a = 1} = 1) of [])",
9631 "({'a': a = 1} = 1 of [])",
9632 "(({'a': a = 1} = 1) of [])",
9633 "({\"a\": a = 1} = 1 of [])",
9634 "(({\"a\": a = 1} = 1) of [])",
9635 "({[Symbol.iterator]: a = 1} = 1 of [])",
9636 "(({[Symbol.iterator]: a = 1} = 1) of [])",
9637 "({0: a = 1} = 1 of [])",
9638 "(({0: a = 1} = 1) of [])",
9639 "(function a() {} of [])",
9640 "([1] of [])",
9641 "({a: 1} of [])"
9642
9643 // VarDeclarations
9644 "(var a = 1 of [])",
9645 "(var a, b of [])",
9646 "(var [a] = 1 of [])",
9647 "(var [a], b of [])",
9648 "(var [a = 1] = 1 of [])",
9649 "(var [a = 1], b of [])",
9650 "(var [a = 1 = 1, ...b] of [])",
9651 "(var [a = 1, ...b], c of [])",
9652 "(var {a} = 1 of [])",
9653 "(var {a}, b of [])",
9654 "(var {a: a} = 1 of [])",
9655 "(var {a: a}, b of [])",
9656 "(var {'a': a} = 1 of [])",
9657 "(var {'a': a}, b of [])",
9658 "(var {\"a\": a} = 1 of [])",
9659 "(var {\"a\": a}, b of [])",
9660 "(var {[Symbol.iterator]: a} = 1 of [])",
9661 "(var {[Symbol.iterator]: a}, b of [])",
9662 "(var {0: a} = 1 of [])",
9663 "(var {0: a}, b of [])",
9664 "(var {a = 1} = 1 of [])",
9665 "(var {a = 1}, b of [])",
9666 "(var {a: a = 1} = 1 of [])",
9667 "(var {a: a = 1}, b of [])",
9668 "(var {'a': a = 1} = 1 of [])",
9669 "(var {'a': a = 1}, b of [])",
9670 "(var {\"a\": a = 1} = 1 of [])",
9671 "(var {\"a\": a = 1}, b of [])",
9672 "(var {[Symbol.iterator]: a = 1} = 1 of [])",
9673 "(var {[Symbol.iterator]: a = 1}, b of [])",
9674 "(var {0: a = 1} = 1 of [])",
9675 "(var {0: a = 1}, b of [])",
9676
9677 // LexicalDeclartions
9678 "(let a = 1 of [])",
9679 "(let a, b of [])",
9680 "(let [a] = 1 of [])",
9681 "(let [a], b of [])",
9682 "(let [a = 1] = 1 of [])",
9683 "(let [a = 1], b of [])",
9684 "(let [a = 1, ...b] = 1 of [])",
9685 "(let [a = 1, ...b], c of [])",
9686 "(let {a} = 1 of [])",
9687 "(let {a}, b of [])",
9688 "(let {a: a} = 1 of [])",
9689 "(let {a: a}, b of [])",
9690 "(let {'a': a} = 1 of [])",
9691 "(let {'a': a}, b of [])",
9692 "(let {\"a\": a} = 1 of [])",
9693 "(let {\"a\": a}, b of [])",
9694 "(let {[Symbol.iterator]: a} = 1 of [])",
9695 "(let {[Symbol.iterator]: a}, b of [])",
9696 "(let {0: a} = 1 of [])",
9697 "(let {0: a}, b of [])",
9698 "(let {a = 1} = 1 of [])",
9699 "(let {a = 1}, b of [])",
9700 "(let {a: a = 1} = 1 of [])",
9701 "(let {a: a = 1}, b of [])",
9702 "(let {'a': a = 1} = 1 of [])",
9703 "(let {'a': a = 1}, b of [])",
9704 "(let {\"a\": a = 1} = 1 of [])",
9705 "(let {\"a\": a = 1}, b of [])",
9706 "(let {[Symbol.iterator]: a = 1} = 1 of [])",
9707 "(let {[Symbol.iterator]: a = 1}, b of [])",
9708 "(let {0: a = 1} = 1 of [])",
9709 "(let {0: a = 1}, b of [])",
9710
9711 "(const a = 1 of [])",
9712 "(const a, b of [])",
9713 "(const [a] = 1 of [])",
9714 "(const [a], b of [])",
9715 "(const [a = 1] = 1 of [])",
9716 "(const [a = 1], b of [])",
9717 "(const [a = 1, ...b] = 1 of [])",
9718 "(const [a = 1, ...b], b of [])",
9719 "(const {a} = 1 of [])",
9720 "(const {a}, b of [])",
9721 "(const {a: a} = 1 of [])",
9722 "(const {a: a}, b of [])",
9723 "(const {'a': a} = 1 of [])",
9724 "(const {'a': a}, b of [])",
9725 "(const {\"a\": a} = 1 of [])",
9726 "(const {\"a\": a}, b of [])",
9727 "(const {[Symbol.iterator]: a} = 1 of [])",
9728 "(const {[Symbol.iterator]: a}, b of [])",
9729 "(const {0: a} = 1 of [])",
9730 "(const {0: a}, b of [])",
9731 "(const {a = 1} = 1 of [])",
9732 "(const {a = 1}, b of [])",
9733 "(const {a: a = 1} = 1 of [])",
9734 "(const {a: a = 1}, b of [])",
9735 "(const {'a': a = 1} = 1 of [])",
9736 "(const {'a': a = 1}, b of [])",
9737 "(const {\"a\": a = 1} = 1 of [])",
9738 "(const {\"a\": a = 1}, b of [])",
9739 "(const {[Symbol.iterator]: a = 1} = 1 of [])",
9740 "(const {[Symbol.iterator]: a = 1}, b of [])",
9741 "(const {0: a = 1} = 1 of [])",
9742 "(const {0: a = 1}, b of [])",
9743
9744 NULL
9745 };
9746 // clang-format on
9747 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncIteration};
9748 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
9749 arraysize(always_flags));
9750 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698