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 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 | 1291 |
1292 data.Dispose(); | 1292 data.Dispose(); |
1293 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); | 1293 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); |
1294 } | 1294 } |
1295 | 1295 |
1296 enum ParserFlag { | 1296 enum ParserFlag { |
1297 kAllowLazy, | 1297 kAllowLazy, |
1298 kAllowNatives, | 1298 kAllowNatives, |
1299 kAllowHarmonyFunctionSent, | 1299 kAllowHarmonyFunctionSent, |
1300 kAllowHarmonyRestrictiveDeclarations, | 1300 kAllowHarmonyRestrictiveDeclarations, |
1301 kAllowHarmonyForIn, | |
1302 kAllowHarmonyAsyncAwait, | 1301 kAllowHarmonyAsyncAwait, |
1303 kAllowHarmonyRestrictiveGenerators, | 1302 kAllowHarmonyRestrictiveGenerators, |
1304 kAllowHarmonyTrailingCommas, | 1303 kAllowHarmonyTrailingCommas, |
1305 kAllowHarmonyClassFields, | 1304 kAllowHarmonyClassFields, |
1306 }; | 1305 }; |
1307 | 1306 |
1308 enum ParserSyncTestResult { | 1307 enum ParserSyncTestResult { |
1309 kSuccessOrError, | 1308 kSuccessOrError, |
1310 kSuccess, | 1309 kSuccess, |
1311 kError | 1310 kError |
1312 }; | 1311 }; |
1313 | 1312 |
1314 template <typename Traits> | 1313 template <typename Traits> |
1315 void SetParserFlags(i::ParserBase<Traits>* parser, | 1314 void SetParserFlags(i::ParserBase<Traits>* parser, |
1316 i::EnumSet<ParserFlag> flags) { | 1315 i::EnumSet<ParserFlag> flags) { |
1317 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1316 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
1318 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1317 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
1319 parser->set_allow_harmony_function_sent( | 1318 parser->set_allow_harmony_function_sent( |
1320 flags.Contains(kAllowHarmonyFunctionSent)); | 1319 flags.Contains(kAllowHarmonyFunctionSent)); |
1321 parser->set_allow_harmony_restrictive_declarations( | 1320 parser->set_allow_harmony_restrictive_declarations( |
1322 flags.Contains(kAllowHarmonyRestrictiveDeclarations)); | 1321 flags.Contains(kAllowHarmonyRestrictiveDeclarations)); |
1323 parser->set_allow_harmony_for_in(flags.Contains(kAllowHarmonyForIn)); | |
1324 parser->set_allow_harmony_async_await( | 1322 parser->set_allow_harmony_async_await( |
1325 flags.Contains(kAllowHarmonyAsyncAwait)); | 1323 flags.Contains(kAllowHarmonyAsyncAwait)); |
1326 parser->set_allow_harmony_restrictive_generators( | 1324 parser->set_allow_harmony_restrictive_generators( |
1327 flags.Contains(kAllowHarmonyRestrictiveGenerators)); | 1325 flags.Contains(kAllowHarmonyRestrictiveGenerators)); |
1328 parser->set_allow_harmony_trailing_commas( | 1326 parser->set_allow_harmony_trailing_commas( |
1329 flags.Contains(kAllowHarmonyTrailingCommas)); | 1327 flags.Contains(kAllowHarmonyTrailingCommas)); |
1330 parser->set_allow_harmony_class_fields( | 1328 parser->set_allow_harmony_class_fields( |
1331 flags.Contains(kAllowHarmonyClassFields)); | 1329 flags.Contains(kAllowHarmonyClassFields)); |
1332 } | 1330 } |
1333 | 1331 |
(...skipping 6775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8109 // clang-format on | 8107 // clang-format on |
8110 | 8108 |
8111 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait}; | 8109 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait}; |
8112 RunModuleParserSyncTest(context_data, error_data, kError, NULL, 0, | 8110 RunModuleParserSyncTest(context_data, error_data, kError, NULL, 0, |
8113 always_flags, arraysize(always_flags), NULL, 0, | 8111 always_flags, arraysize(always_flags), NULL, 0, |
8114 false); | 8112 false); |
8115 } | 8113 } |
8116 | 8114 |
8117 TEST(RestrictiveForInErrors) { | 8115 TEST(RestrictiveForInErrors) { |
8118 // clang-format off | 8116 // clang-format off |
8119 const char* context_data[][2] = { | 8117 const char* strict_context_data[][2] = { |
8120 { "'use strict'", "" }, | 8118 { "'use strict'", "" }, |
| 8119 { NULL, NULL } |
| 8120 }; |
| 8121 const char* sloppy_context_data[][2] = { |
8121 { "", "" }, | 8122 { "", "" }, |
8122 { NULL, NULL } | 8123 { NULL, NULL } |
8123 }; | 8124 }; |
8124 const char* error_data[] = { | 8125 const char* error_data[] = { |
8125 "for (var x = 0 in {});", | |
8126 "for (const x = 0 in {});", | 8126 "for (const x = 0 in {});", |
8127 "for (let x = 0 in {});", | 8127 "for (let x = 0 in {});", |
8128 NULL | 8128 NULL |
8129 }; | 8129 }; |
| 8130 const char* sloppy_data[] = { |
| 8131 "for (var x = 0 in {});", |
| 8132 NULL |
| 8133 }; |
8130 // clang-format on | 8134 // clang-format on |
8131 | 8135 |
8132 static const ParserFlag always_flags[] = {kAllowHarmonyForIn}; | 8136 RunParserSyncTest(strict_context_data, error_data, kError); |
8133 RunParserSyncTest(context_data, error_data, kError, nullptr, 0, always_flags, | 8137 RunParserSyncTest(strict_context_data, sloppy_data, kError); |
8134 arraysize(always_flags)); | 8138 RunParserSyncTest(sloppy_context_data, error_data, kError); |
| 8139 RunParserSyncTest(sloppy_context_data, sloppy_data, kSuccess); |
8135 } | 8140 } |
8136 | 8141 |
8137 TEST(NoDuplicateGeneratorsInBlock) { | 8142 TEST(NoDuplicateGeneratorsInBlock) { |
8138 const char* block_context_data[][2] = { | 8143 const char* block_context_data[][2] = { |
8139 {"'use strict'; {", "}"}, | 8144 {"'use strict'; {", "}"}, |
8140 {"{", "}"}, | 8145 {"{", "}"}, |
8141 {"(function() { {", "} })()"}, | 8146 {"(function() { {", "} })()"}, |
8142 {"(function() {'use strict'; {", "} })()"}, | 8147 {"(function() {'use strict'; {", "} })()"}, |
8143 {NULL, NULL}}; | 8148 {NULL, NULL}}; |
8144 const char* top_level_context_data[][2] = { | 8149 const char* top_level_context_data[][2] = { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8322 const char* data[] = { | 8327 const char* data[] = { |
8323 "const arguments = 1", | 8328 "const arguments = 1", |
8324 "let arguments", | 8329 "let arguments", |
8325 "var arguments", | 8330 "var arguments", |
8326 NULL | 8331 NULL |
8327 }; | 8332 }; |
8328 // clang-format on | 8333 // clang-format on |
8329 RunParserSyncTest(context_data, data, kSuccess); | 8334 RunParserSyncTest(context_data, data, kSuccess); |
8330 } | 8335 } |
8331 } | 8336 } |
OLD | NEW |