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