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

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: [async-iteration] add support for for-await-of loops in Async Functions Created 3 years, 11 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 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 } 1275 }
1276 1276
1277 enum ParserFlag { 1277 enum ParserFlag {
1278 kAllowLazy, 1278 kAllowLazy,
1279 kAllowNatives, 1279 kAllowNatives,
1280 kAllowHarmonyFunctionSent, 1280 kAllowHarmonyFunctionSent,
1281 kAllowHarmonyRestrictiveGenerators, 1281 kAllowHarmonyRestrictiveGenerators,
1282 kAllowHarmonyTrailingCommas, 1282 kAllowHarmonyTrailingCommas,
1283 kAllowHarmonyClassFields, 1283 kAllowHarmonyClassFields,
1284 kAllowHarmonyObjectRestSpread, 1284 kAllowHarmonyObjectRestSpread,
1285 kAllowHarmonyAsyncIteration
1285 }; 1286 };
1286 1287
1287 enum ParserSyncTestResult { 1288 enum ParserSyncTestResult {
1288 kSuccessOrError, 1289 kSuccessOrError,
1289 kSuccess, 1290 kSuccess,
1290 kError 1291 kError
1291 }; 1292 };
1292 1293
1293 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) { 1294 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) {
1294 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives); 1295 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives);
1295 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent); 1296 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent);
1296 i::FLAG_harmony_restrictive_generators = 1297 i::FLAG_harmony_restrictive_generators =
1297 flags.Contains(kAllowHarmonyRestrictiveGenerators); 1298 flags.Contains(kAllowHarmonyRestrictiveGenerators);
1298 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas); 1299 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas);
1299 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields); 1300 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields);
1300 i::FLAG_harmony_object_rest_spread = 1301 i::FLAG_harmony_object_rest_spread =
1301 flags.Contains(kAllowHarmonyObjectRestSpread); 1302 flags.Contains(kAllowHarmonyObjectRestSpread);
1303 i::FLAG_harmony_async_iteration = flags.Contains(kAllowHarmonyAsyncIteration);
1302 } 1304 }
1303 1305
1304 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { 1306 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) {
1305 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1307 parser->set_allow_natives(flags.Contains(kAllowNatives));
1306 parser->set_allow_harmony_function_sent( 1308 parser->set_allow_harmony_function_sent(
1307 flags.Contains(kAllowHarmonyFunctionSent)); 1309 flags.Contains(kAllowHarmonyFunctionSent));
1308 parser->set_allow_harmony_restrictive_generators( 1310 parser->set_allow_harmony_restrictive_generators(
1309 flags.Contains(kAllowHarmonyRestrictiveGenerators)); 1311 flags.Contains(kAllowHarmonyRestrictiveGenerators));
1310 parser->set_allow_harmony_trailing_commas( 1312 parser->set_allow_harmony_trailing_commas(
1311 flags.Contains(kAllowHarmonyTrailingCommas)); 1313 flags.Contains(kAllowHarmonyTrailingCommas));
1312 parser->set_allow_harmony_class_fields( 1314 parser->set_allow_harmony_class_fields(
1313 flags.Contains(kAllowHarmonyClassFields)); 1315 flags.Contains(kAllowHarmonyClassFields));
1314 parser->set_allow_harmony_object_rest_spread( 1316 parser->set_allow_harmony_object_rest_spread(
1315 flags.Contains(kAllowHarmonyObjectRestSpread)); 1317 flags.Contains(kAllowHarmonyObjectRestSpread));
1318 parser->set_allow_harmony_async_iteration(
1319 flags.Contains(kAllowHarmonyAsyncIteration));
1316 } 1320 }
1317 1321
1318 void TestParserSyncWithFlags(i::Handle<i::String> source, 1322 void TestParserSyncWithFlags(i::Handle<i::String> source,
1319 i::EnumSet<ParserFlag> flags, 1323 i::EnumSet<ParserFlag> flags,
1320 ParserSyncTestResult result, 1324 ParserSyncTestResult result,
1321 bool is_module = false, 1325 bool is_module = false,
1322 bool test_preparser = true) { 1326 bool test_preparser = true) {
1323 i::Isolate* isolate = CcTest::i_isolate(); 1327 i::Isolate* isolate = CcTest::i_isolate();
1324 i::Factory* factory = isolate->factory(); 1328 i::Factory* factory = isolate->factory();
1325 1329
(...skipping 7600 matching lines...) Expand 10 before | Expand all | Expand 10 after
8926 DCHECK_NULL(scope->sibling()); 8930 DCHECK_NULL(scope->sibling());
8927 DCHECK(scope->is_function_scope()); 8931 DCHECK(scope->is_function_scope());
8928 const i::AstRawString* var_name = 8932 const i::AstRawString* var_name =
8929 info.ast_value_factory()->GetOneByteString("my_var"); 8933 info.ast_value_factory()->GetOneByteString("my_var");
8930 i::Variable* var = scope->Lookup(var_name); 8934 i::Variable* var = scope->Lookup(var_name);
8931 CHECK_EQ(inners[i].ctxt_allocate, 8935 CHECK_EQ(inners[i].ctxt_allocate,
8932 i::ScopeTestHelper::MustAllocateInContext(var)); 8936 i::ScopeTestHelper::MustAllocateInContext(var));
8933 } 8937 }
8934 } 8938 }
8935 } 8939 }
8940
8941 TEST(ForAwaitOf) {
8942 // clang-format off
8943 const char* context_data[][2] = {
8944 { "async function f() { for await ", " ; }" },
8945 { "async function f() { for await ", " { } }" },
8946 { "async function f() { 'use strict'; for await ", " ; }" },
8947 { "async function f() { 'use strict'; for await ", " { } }" },
8948 { "async function f() { for\nawait ", " ; }" },
8949 { "async function f() { for\nawait ", " { } }" },
8950 { "async function f() { 'use strict'; for\nawait ", " ; }" },
8951 { "async function f() { 'use strict'; for\nawait ", " { } }" },
8952 { "async function f() { 'use strict'; for\nawait ", " { } }" },
8953 { "async function f() { for await\n", " ; }" },
8954 { "async function f() { for await\n", " { } }" },
8955 { "async function f() { 'use strict'; for await\n", " ; }" },
8956 { "async function f() { 'use strict'; for await\n", " { } }" },
8957 { NULL, NULL }
8958 };
8959
8960 const char* context_data2[][2] = {
8961 { "async function f() { let a; for await ", " ; }" },
8962 { "async function f() { let a; for await ", " { } }" },
8963 { "async function f() { 'use strict'; let a; for await ", " ; }" },
8964 { "async function f() { 'use strict'; let a; for await ", " { } }" },
8965 { "async function f() { let a; for\nawait ", " ; }" },
8966 { "async function f() { let a; for\nawait ", " { } }" },
8967 { "async function f() { 'use strict'; let a; for\nawait ", " ; }" },
8968 { "async function f() { 'use strict'; let a; for\nawait ", " { } }" },
8969 { "async function f() { 'use strict'; let a; for\nawait ", " { } }" },
8970 { "async function f() { let a; for await\n", " ; }" },
8971 { "async function f() { let a; for await\n", " { } }" },
8972 { "async function f() { 'use strict'; let a; for await\n", " ; }" },
8973 { "async function f() { 'use strict'; let a; for await\n", " { } }" },
8974 { NULL, NULL }
8975 };
8976
8977 const char* expr_data[] = {
8978 // Primary Expressions
8979 "(a of [])",
8980 "(a.b of [])",
8981 "([a] of [])",
8982 "([a = 1] of [])",
8983 "([a = 1, ...b] of [])",
8984 "({a} of [])",
8985 "({a: a} of [])",
8986 "({'a': a} of [])",
8987 "({\"a\": a} of [])",
8988 "({[Symbol.iterator]: a} of [])",
8989 "({0: a} of [])",
8990 "({a = 1} of [])",
8991 "({a: a = 1} of [])",
8992 "({'a': a = 1} of [])",
8993 "({\"a\": a = 1} of [])",
8994 "({[Symbol.iterator]: a = 1} of [])",
8995 "({0: a = 1} of [])",
8996 NULL
8997 };
8998
8999 const char* var_data[] = {
9000 // VarDeclarations
9001 "(var a of [])",
9002 "(var [a] of [])",
9003 "(var [a = 1] of [])",
9004 "(var [a = 1, ...b] of [])",
9005 "(var {a} of [])",
9006 "(var {a: a} of [])",
9007 "(var {'a': a} of [])",
9008 "(var {\"a\": a} of [])",
9009 "(var {[Symbol.iterator]: a} of [])",
9010 "(var {0: a} of [])",
9011 "(var {a = 1} of [])",
9012 "(var {a: a = 1} of [])",
9013 "(var {'a': a = 1} of [])",
9014 "(var {\"a\": a = 1} of [])",
9015 "(var {[Symbol.iterator]: a = 1} of [])",
9016 "(var {0: a = 1} of [])",
9017 NULL
9018 };
9019
9020 const char* lexical_data[] = {
9021 // LexicalDeclartions
9022 "(let a of [])",
9023 "(let [a] of [])",
9024 "(let [a = 1] of [])",
9025 "(let [a = 1, ...b] of [])",
9026 "(let {a} of [])",
9027 "(let {a: a} of [])",
9028 "(let {'a': a} of [])",
9029 "(let {\"a\": a} of [])",
9030 "(let {[Symbol.iterator]: a} of [])",
9031 "(let {0: a} of [])",
9032 "(let {a = 1} of [])",
9033 "(let {a: a = 1} of [])",
9034 "(let {'a': a = 1} of [])",
9035 "(let {\"a\": a = 1} of [])",
9036 "(let {[Symbol.iterator]: a = 1} of [])",
9037 "(let {0: a = 1} of [])",
9038
9039 "(const a of [])",
9040 "(const [a] of [])",
9041 "(const [a = 1] of [])",
9042 "(const [a = 1, ...b] of [])",
9043 "(const {a} of [])",
9044 "(const {a: a} of [])",
9045 "(const {'a': a} of [])",
9046 "(const {\"a\": a} of [])",
9047 "(const {[Symbol.iterator]: a} of [])",
9048 "(const {0: a} of [])",
9049 "(const {a = 1} of [])",
9050 "(const {a: a = 1} of [])",
9051 "(const {'a': a = 1} of [])",
9052 "(const {\"a\": a = 1} of [])",
9053 "(const {[Symbol.iterator]: a = 1} of [])",
9054 "(const {0: a = 1} of [])",
9055 NULL
9056 };
9057 // clang-format on
9058 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncIteration};
9059 RunParserSyncTest(context_data, expr_data, kSuccess, NULL, 0, always_flags,
9060 arraysize(always_flags));
9061 RunParserSyncTest(context_data2, expr_data, kSuccess, NULL, 0, always_flags,
9062 arraysize(always_flags));
9063
9064 RunParserSyncTest(context_data, var_data, kSuccess, NULL, 0, always_flags,
9065 arraysize(always_flags));
9066 // TODO(marja): PreParser doesn't report early errors.
9067 // (https://bugs.chromium.org/p/v8/issues/detail?id=2728)
9068 // RunParserSyncTest(context_data2, var_data, kError, NULL, 0, always_flags,
9069 // arraysize(always_flags));
9070
9071 RunParserSyncTest(context_data, lexical_data, kSuccess, NULL, 0, always_flags,
9072 arraysize(always_flags));
9073 RunParserSyncTest(context_data2, lexical_data, kSuccess, NULL, 0,
9074 always_flags, arraysize(always_flags));
9075 }
9076
9077 TEST(ForAwaitOfErrors) {
9078 // clang-format off
9079 const char* context_data[][2] = {
9080 { "async function f() { for await ", " ; }" },
9081 { "async function f() { for await ", " { } }" },
9082 { "async function f() { 'use strict'; for await ", " ; }" },
9083 { "async function f() { 'use strict'; for await ", " { } }" },
9084 { NULL, NULL }
9085 };
9086
9087 const char* data[] = {
9088 // Primary Expressions
9089 "(a = 1 of [])",
9090 "(a = 1) of [])",
9091 "(a.b = 1 of [])",
9092 "((a.b = 1) of [])",
9093 "([a] = 1 of [])",
9094 "(([a] = 1) of [])",
9095 "([a = 1] = 1 of [])",
9096 "(([a = 1] = 1) of [])",
9097 "([a = 1 = 1, ...b] = 1 of [])",
9098 "(([a = 1 = 1, ...b] = 1) of [])",
9099 "({a} = 1 of [])",
9100 "(({a} = 1) of [])",
9101 "({a: a} = 1 of [])",
9102 "(({a: a} = 1) of [])",
9103 "({'a': a} = 1 of [])",
9104 "(({'a': a} = 1) of [])",
9105 "({\"a\": a} = 1 of [])",
9106 "(({\"a\": a} = 1) of [])",
9107 "({[Symbol.iterator]: a} = 1 of [])",
9108 "(({[Symbol.iterator]: a} = 1) of [])",
9109 "({0: a} = 1 of [])",
9110 "(({0: a} = 1) of [])",
9111 "({a = 1} = 1 of [])",
9112 "(({a = 1} = 1) of [])",
9113 "({a: a = 1} = 1 of [])",
9114 "(({a: a = 1} = 1) of [])",
9115 "({'a': a = 1} = 1 of [])",
9116 "(({'a': a = 1} = 1) of [])",
9117 "({\"a\": a = 1} = 1 of [])",
9118 "(({\"a\": a = 1} = 1) of [])",
9119 "({[Symbol.iterator]: a = 1} = 1 of [])",
9120 "(({[Symbol.iterator]: a = 1} = 1) of [])",
9121 "({0: a = 1} = 1 of [])",
9122 "(({0: a = 1} = 1) of [])",
9123 "(function a() {} of [])",
9124 "([1] of [])",
9125 "({a: 1} of [])"
9126
9127 // VarDeclarations
9128 "(var a = 1 of [])",
9129 "(var a, b of [])",
9130 "(var [a] = 1 of [])",
9131 "(var [a], b of [])",
9132 "(var [a = 1] = 1 of [])",
9133 "(var [a = 1], b of [])",
9134 "(var [a = 1 = 1, ...b] of [])",
9135 "(var [a = 1, ...b], c of [])",
9136 "(var {a} = 1 of [])",
9137 "(var {a}, b of [])",
9138 "(var {a: a} = 1 of [])",
9139 "(var {a: a}, b of [])",
9140 "(var {'a': a} = 1 of [])",
9141 "(var {'a': a}, b of [])",
9142 "(var {\"a\": a} = 1 of [])",
9143 "(var {\"a\": a}, b of [])",
9144 "(var {[Symbol.iterator]: a} = 1 of [])",
9145 "(var {[Symbol.iterator]: a}, b of [])",
9146 "(var {0: a} = 1 of [])",
9147 "(var {0: a}, b of [])",
9148 "(var {a = 1} = 1 of [])",
9149 "(var {a = 1}, b of [])",
9150 "(var {a: a = 1} = 1 of [])",
9151 "(var {a: a = 1}, b of [])",
9152 "(var {'a': a = 1} = 1 of [])",
9153 "(var {'a': a = 1}, b of [])",
9154 "(var {\"a\": a = 1} = 1 of [])",
9155 "(var {\"a\": a = 1}, b of [])",
9156 "(var {[Symbol.iterator]: a = 1} = 1 of [])",
9157 "(var {[Symbol.iterator]: a = 1}, b of [])",
9158 "(var {0: a = 1} = 1 of [])",
9159 "(var {0: a = 1}, b of [])",
9160
9161 // LexicalDeclartions
9162 "(let a = 1 of [])",
9163 "(let a, b of [])",
9164 "(let [a] = 1 of [])",
9165 "(let [a], b of [])",
9166 "(let [a = 1] = 1 of [])",
9167 "(let [a = 1], b of [])",
9168 "(let [a = 1, ...b] = 1 of [])",
9169 "(let [a = 1, ...b], c of [])",
9170 "(let {a} = 1 of [])",
9171 "(let {a}, b of [])",
9172 "(let {a: a} = 1 of [])",
9173 "(let {a: a}, b of [])",
9174 "(let {'a': a} = 1 of [])",
9175 "(let {'a': a}, b of [])",
9176 "(let {\"a\": a} = 1 of [])",
9177 "(let {\"a\": a}, b of [])",
9178 "(let {[Symbol.iterator]: a} = 1 of [])",
9179 "(let {[Symbol.iterator]: a}, b of [])",
9180 "(let {0: a} = 1 of [])",
9181 "(let {0: a}, b of [])",
9182 "(let {a = 1} = 1 of [])",
9183 "(let {a = 1}, b of [])",
9184 "(let {a: a = 1} = 1 of [])",
9185 "(let {a: a = 1}, b of [])",
9186 "(let {'a': a = 1} = 1 of [])",
9187 "(let {'a': a = 1}, b of [])",
9188 "(let {\"a\": a = 1} = 1 of [])",
9189 "(let {\"a\": a = 1}, b of [])",
9190 "(let {[Symbol.iterator]: a = 1} = 1 of [])",
9191 "(let {[Symbol.iterator]: a = 1}, b of [])",
9192 "(let {0: a = 1} = 1 of [])",
9193 "(let {0: a = 1}, b of [])",
9194
9195 "(const a = 1 of [])",
9196 "(const a, b of [])",
9197 "(const [a] = 1 of [])",
9198 "(const [a], b of [])",
9199 "(const [a = 1] = 1 of [])",
9200 "(const [a = 1], b of [])",
9201 "(const [a = 1, ...b] = 1 of [])",
9202 "(const [a = 1, ...b], b of [])",
9203 "(const {a} = 1 of [])",
9204 "(const {a}, b of [])",
9205 "(const {a: a} = 1 of [])",
9206 "(const {a: a}, b of [])",
9207 "(const {'a': a} = 1 of [])",
9208 "(const {'a': a}, b of [])",
9209 "(const {\"a\": a} = 1 of [])",
9210 "(const {\"a\": a}, b of [])",
9211 "(const {[Symbol.iterator]: a} = 1 of [])",
9212 "(const {[Symbol.iterator]: a}, b of [])",
9213 "(const {0: a} = 1 of [])",
9214 "(const {0: a}, b of [])",
9215 "(const {a = 1} = 1 of [])",
9216 "(const {a = 1}, b of [])",
9217 "(const {a: a = 1} = 1 of [])",
9218 "(const {a: a = 1}, b of [])",
9219 "(const {'a': a = 1} = 1 of [])",
9220 "(const {'a': a = 1}, b of [])",
9221 "(const {\"a\": a = 1} = 1 of [])",
9222 "(const {\"a\": a = 1}, b of [])",
9223 "(const {[Symbol.iterator]: a = 1} = 1 of [])",
9224 "(const {[Symbol.iterator]: a = 1}, b of [])",
9225 "(const {0: a = 1} = 1 of [])",
9226 "(const {0: a = 1}, b of [])",
9227
9228 NULL
9229 };
9230 // clang-format on
9231 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncIteration};
9232 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
9233 arraysize(always_flags));
9234 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698