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

Side by Side Diff: src/parsing/parser.cc

Issue 1841543003: [esnext] implement frontend changes for async/await proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: A bunch more tests, some fixes, ExpressionClassifier gets fatter :( Created 4 years, 7 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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 323
324 324
325 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const { 325 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const {
326 return IsEval(identifier) || IsArguments(identifier); 326 return IsEval(identifier) || IsArguments(identifier);
327 } 327 }
328 328
329 bool ParserTraits::IsUndefined(const AstRawString* identifier) const { 329 bool ParserTraits::IsUndefined(const AstRawString* identifier) const {
330 return identifier == parser_->ast_value_factory()->undefined_string(); 330 return identifier == parser_->ast_value_factory()->undefined_string();
331 } 331 }
332 332
333 bool ParserTraits::IsAwait(const AstRawString* identifier) const {
334 return identifier == parser_->ast_value_factory()->await_string();
335 }
336
333 bool ParserTraits::IsPrototype(const AstRawString* identifier) const { 337 bool ParserTraits::IsPrototype(const AstRawString* identifier) const {
334 return identifier == parser_->ast_value_factory()->prototype_string(); 338 return identifier == parser_->ast_value_factory()->prototype_string();
335 } 339 }
336 340
337 341
338 bool ParserTraits::IsConstructor(const AstRawString* identifier) const { 342 bool ParserTraits::IsConstructor(const AstRawString* identifier) const {
339 return identifier == parser_->ast_value_factory()->constructor_string(); 343 return identifier == parser_->ast_value_factory()->constructor_string();
340 } 344 }
341 345
342 346
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && 795 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() &&
792 info->isolate()->is_tail_call_elimination_enabled()); 796 info->isolate()->is_tail_call_elimination_enabled());
793 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); 797 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions);
794 set_allow_harmony_for_in(FLAG_harmony_for_in); 798 set_allow_harmony_for_in(FLAG_harmony_for_in);
795 set_allow_harmony_function_name(FLAG_harmony_function_name); 799 set_allow_harmony_function_name(FLAG_harmony_function_name);
796 set_allow_harmony_function_sent(FLAG_harmony_function_sent); 800 set_allow_harmony_function_sent(FLAG_harmony_function_sent);
797 set_allow_harmony_restrictive_declarations( 801 set_allow_harmony_restrictive_declarations(
798 FLAG_harmony_restrictive_declarations); 802 FLAG_harmony_restrictive_declarations);
799 set_allow_harmony_exponentiation_operator( 803 set_allow_harmony_exponentiation_operator(
800 FLAG_harmony_exponentiation_operator); 804 FLAG_harmony_exponentiation_operator);
805 set_allow_harmony_async_await(FLAG_harmony_async_await);
801 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 806 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
802 ++feature) { 807 ++feature) {
803 use_counts_[feature] = 0; 808 use_counts_[feature] = 0;
804 } 809 }
805 if (info->ast_value_factory() == NULL) { 810 if (info->ast_value_factory() == NULL) {
806 // info takes ownership of AstValueFactory. 811 // info takes ownership of AstValueFactory.
807 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); 812 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed()));
808 info->set_ast_value_factory_owned(); 813 info->set_ast_value_factory_owned();
809 ast_value_factory_ = info->ast_value_factory(); 814 ast_value_factory_ = info->ast_value_factory();
810 } 815 }
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 FunctionState function_state(&function_state_, &scope_, scope, 1071 FunctionState function_state(&function_state_, &scope_, scope,
1067 shared_info->kind(), &function_factory); 1072 shared_info->kind(), &function_factory);
1068 DCHECK(is_sloppy(scope->language_mode()) || 1073 DCHECK(is_sloppy(scope->language_mode()) ||
1069 is_strict(info->language_mode())); 1074 is_strict(info->language_mode()));
1070 DCHECK(info->language_mode() == shared_info->language_mode()); 1075 DCHECK(info->language_mode() == shared_info->language_mode());
1071 FunctionLiteral::FunctionType function_type = 1076 FunctionLiteral::FunctionType function_type =
1072 ComputeFunctionType(shared_info); 1077 ComputeFunctionType(shared_info);
1073 bool ok = true; 1078 bool ok = true;
1074 1079
1075 if (shared_info->is_arrow()) { 1080 if (shared_info->is_arrow()) {
1081 bool is_async = allow_harmony_async_await() &&
1082 peek() == Token::IDENTIFIER &&
1083 PeekContextualKeyword(CStrVector("async")) &&
1084 !scanner()->HasAnyLineTerminatorAfterNext();
1085
1086 if (is_async) {
1087 Consume(Token::IDENTIFIER);
1088 DCHECK(peek_any_identifier() || peek() == Token::LPAREN);
1089 }
1090
1076 // TODO(adamk): We should construct this scope from the ScopeInfo. 1091 // TODO(adamk): We should construct this scope from the ScopeInfo.
1077 Scope* scope = 1092 Scope* scope =
1078 NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction); 1093 NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction);
1079 1094
1080 // These two bits only need to be explicitly set because we're 1095 // These two bits only need to be explicitly set because we're
1081 // not passing the ScopeInfo to the Scope constructor. 1096 // not passing the ScopeInfo to the Scope constructor.
1082 // TODO(adamk): Remove these calls once the above NewScope call 1097 // TODO(adamk): Remove these calls once the above NewScope call
1083 // passes the ScopeInfo. 1098 // passes the ScopeInfo.
1084 if (shared_info->scope_info()->CallsEval()) { 1099 if (shared_info->scope_info()->CallsEval()) {
1085 scope->RecordEvalCall(); 1100 scope->RecordEvalCall();
(...skipping 20 matching lines...) Expand all
1106 DeclareFormalParameter(formals.scope, formals.at(0), 1121 DeclareFormalParameter(formals.scope, formals.at(0),
1107 &formals_classifier); 1122 &formals_classifier);
1108 } 1123 }
1109 } 1124 }
1110 } 1125 }
1111 1126
1112 if (ok) { 1127 if (ok) {
1113 checkpoint.Restore(&formals.materialized_literals_count); 1128 checkpoint.Restore(&formals.materialized_literals_count);
1114 // Pass `accept_IN=true` to ParseArrowFunctionLiteral --- This should 1129 // Pass `accept_IN=true` to ParseArrowFunctionLiteral --- This should
1115 // not be observable, or else the preparser would have failed. 1130 // not be observable, or else the preparser would have failed.
1116 Expression* expression = 1131 Expression* expression = ParseArrowFunctionLiteral(
1117 ParseArrowFunctionLiteral(true, formals, formals_classifier, &ok); 1132 true, formals, is_async, formals_classifier, &ok);
1118 if (ok) { 1133 if (ok) {
1119 // Scanning must end at the same position that was recorded 1134 // Scanning must end at the same position that was recorded
1120 // previously. If not, parsing has been interrupted due to a stack 1135 // previously. If not, parsing has been interrupted due to a stack
1121 // overflow, at which point the partially parsed arrow function 1136 // overflow, at which point the partially parsed arrow function
1122 // concise body happens to be a valid expression. This is a problem 1137 // concise body happens to be a valid expression. This is a problem
1123 // only for arrow functions with single expression bodies, since there 1138 // only for arrow functions with single expression bodies, since there
1124 // is no end token such as "}" for normal functions. 1139 // is no end token such as "}" for normal functions.
1125 if (scanner()->location().end_pos == shared_info->end_position()) { 1140 if (scanner()->location().end_pos == shared_info->end_position()) {
1126 // The pre-parser saw an arrow function here, so the full parser 1141 // The pre-parser saw an arrow function here, so the full parser
1127 // must produce a FunctionLiteral. 1142 // must produce a FunctionLiteral.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 1261
1247 return 0; 1262 return 0;
1248 } 1263 }
1249 1264
1250 1265
1251 Statement* Parser::ParseStatementListItem(bool* ok) { 1266 Statement* Parser::ParseStatementListItem(bool* ok) {
1252 // (Ecma 262 6th Edition, 13.1): 1267 // (Ecma 262 6th Edition, 13.1):
1253 // StatementListItem: 1268 // StatementListItem:
1254 // Statement 1269 // Statement
1255 // Declaration 1270 // Declaration
1256 1271 const Token::Value peeked = peek();
1257 switch (peek()) { 1272 switch (peeked) {
1258 case Token::FUNCTION: 1273 case Token::FUNCTION:
1259 return ParseHoistableDeclaration(NULL, ok); 1274 return ParseHoistableDeclaration(NULL, ok);
1260 case Token::CLASS: 1275 case Token::CLASS:
1261 Consume(Token::CLASS); 1276 Consume(Token::CLASS);
1262 return ParseClassDeclaration(NULL, ok); 1277 return ParseClassDeclaration(NULL, ok);
1263 case Token::CONST: 1278 case Token::CONST:
1264 return ParseVariableStatement(kStatementListItem, NULL, ok); 1279 return ParseVariableStatement(kStatementListItem, NULL, ok);
1265 case Token::VAR: 1280 case Token::VAR:
1266 return ParseVariableStatement(kStatementListItem, NULL, ok); 1281 return ParseVariableStatement(kStatementListItem, NULL, ok);
1267 case Token::LET: 1282 case Token::LET:
1268 if (IsNextLetKeyword()) { 1283 if (IsNextLetKeyword()) {
1269 return ParseVariableStatement(kStatementListItem, NULL, ok); 1284 return ParseVariableStatement(kStatementListItem, NULL, ok);
1270 } 1285 }
1271 break; 1286 break;
1287 case Token::IDENTIFIER:
1288 if (allow_harmony_async_await() &&
1289 PeekContextualKeyword(CStrVector("async")) &&
1290 PeekAhead() == Token::FUNCTION &&
1291 !scanner()->HasAnyLineTerminatorAfterNext()) {
1292 Consume(Token::IDENTIFIER);
1293 return ParseAsyncFunctionDeclaration(NULL, ok);
1294 }
1295 /* falls through */
1272 default: 1296 default:
1273 break; 1297 break;
1274 } 1298 }
1275 return ParseStatement(NULL, kAllowLabelledFunctionStatement, ok); 1299 return ParseStatement(NULL, kAllowLabelledFunctionStatement, ok);
1276 } 1300 }
1277 1301
1278 1302
1279 Statement* Parser::ParseModuleItem(bool* ok) { 1303 Statement* Parser::ParseModuleItem(bool* ok) {
1280 // (Ecma 262 6th Edition, 15.2): 1304 // (Ecma 262 6th Edition, 15.2):
1281 // ModuleItem : 1305 // ModuleItem :
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 // GeneratorDeclaration[+Default] :: 1575 // GeneratorDeclaration[+Default] ::
1552 // 'function' '*' '(' FormalParameters ')' '{' FunctionBody '}' 1576 // 'function' '*' '(' FormalParameters ')' '{' FunctionBody '}'
1553 default_export = ParseFunctionLiteral( 1577 default_export = ParseFunctionLiteral(
1554 default_string, Scanner::Location::invalid(), 1578 default_string, Scanner::Location::invalid(),
1555 kSkipFunctionNameCheck, 1579 kSkipFunctionNameCheck,
1556 is_generator ? FunctionKind::kGeneratorFunction 1580 is_generator ? FunctionKind::kGeneratorFunction
1557 : FunctionKind::kNormalFunction, 1581 : FunctionKind::kNormalFunction,
1558 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); 1582 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK);
1559 result = factory()->NewEmptyStatement(RelocInfo::kNoPosition); 1583 result = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
1560 } else { 1584 } else {
1561 result = ParseHoistableDeclaration(pos, is_generator, &names, CHECK_OK); 1585 result = ParseHoistableDeclaration(
1586 pos, is_generator ? ParseFunctionFlags::kIsGenerator
1587 : ParseFunctionFlags::kIsNormal,
1588 &names, CHECK_OK);
1562 } 1589 }
1563 break; 1590 break;
1564 } 1591 }
1565 1592
1566 case Token::CLASS: 1593 case Token::CLASS:
1567 Consume(Token::CLASS); 1594 Consume(Token::CLASS);
1568 if (peek() == Token::EXTENDS || peek() == Token::LBRACE) { 1595 if (peek() == Token::EXTENDS || peek() == Token::LBRACE) {
1569 // ClassDeclaration[+Default] :: 1596 // ClassDeclaration[+Default] ::
1570 // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}' 1597 // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}'
1571 default_export = ParseClassLiteral(nullptr, default_string, 1598 default_export = ParseClassLiteral(nullptr, default_string,
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
2053 return factory()->NewExpressionStatement( 2080 return factory()->NewExpressionStatement(
2054 factory()->NewAssignment(Token::INIT, proxy, lit, RelocInfo::kNoPosition), 2081 factory()->NewAssignment(Token::INIT, proxy, lit, RelocInfo::kNoPosition),
2055 pos); 2082 pos);
2056 } 2083 }
2057 2084
2058 2085
2059 Statement* Parser::ParseHoistableDeclaration( 2086 Statement* Parser::ParseHoistableDeclaration(
2060 ZoneList<const AstRawString*>* names, bool* ok) { 2087 ZoneList<const AstRawString*>* names, bool* ok) {
2061 Expect(Token::FUNCTION, CHECK_OK); 2088 Expect(Token::FUNCTION, CHECK_OK);
2062 int pos = position(); 2089 int pos = position();
2063 bool is_generator = Check(Token::MUL); 2090 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
2064 return ParseHoistableDeclaration(pos, is_generator, names, ok); 2091 if (Check(Token::MUL)) {
2092 flags |= ParseFunctionFlags::kIsGenerator;
2093 }
2094 return ParseHoistableDeclaration(pos, flags, names, ok);
2065 } 2095 }
2066 2096
2097 Statement* Parser::ParseAsyncFunctionDeclaration(
2098 ZoneList<const AstRawString*>* names, bool* ok) {
2099 DCHECK_EQ(scanner()->current_token(), Token::IDENTIFIER);
2100 DCHECK(scanner()->is_literal_contextual_keyword(CStrVector("async")));
2101 int pos = position();
2102 Expect(Token::FUNCTION, CHECK_OK);
2103 ParseFunctionFlags flags = ParseFunctionFlags::kIsAsync;
2104 return ParseHoistableDeclaration(pos, flags, names, ok);
2105 }
2067 2106
2068 Statement* Parser::ParseHoistableDeclaration( 2107 Statement* Parser::ParseHoistableDeclaration(
2069 int pos, bool is_generator, ZoneList<const AstRawString*>* names, 2108 int pos, ParseFunctionFlags flags, ZoneList<const AstRawString*>* names,
2070 bool* ok) { 2109 bool* ok) {
2071 // FunctionDeclaration :: 2110 // FunctionDeclaration ::
2072 // 'function' Identifier '(' FormalParameters ')' '{' FunctionBody '}' 2111 // 'function' Identifier '(' FormalParameters ')' '{' FunctionBody '}'
2073 // GeneratorDeclaration :: 2112 // GeneratorDeclaration ::
2074 // 'function' '*' Identifier '(' FormalParameters ')' '{' FunctionBody '}' 2113 // 'function' '*' Identifier '(' FormalParameters ')' '{' FunctionBody '}'
2075 // 2114 //
2076 // 'function' and '*' (if present) have been consumed by the caller. 2115 // 'function' and '*' (if present) have been consumed by the caller.
2116 const bool is_generator = flags & ParseFunctionFlags::kIsGenerator;
2117 const bool is_async = flags & ParseFunctionFlags::kIsAsync;
2118 DCHECK(!is_generator || !is_async);
2119
2077 bool is_strict_reserved = false; 2120 bool is_strict_reserved = false;
2078 const AstRawString* name = ParseIdentifierOrStrictReservedWord( 2121 const AstRawString* name = ParseIdentifierOrStrictReservedWord(
2079 &is_strict_reserved, CHECK_OK); 2122 &is_strict_reserved, CHECK_OK);
2080 2123
2124 if (V8_UNLIKELY(is_async_function() && is_async && this->IsAwait(name))) {
2125 ReportMessageAt(scanner()->location(),
2126 MessageTemplate::kAwaitBindingIdentifier);
2127 *ok = false;
2128 return nullptr;
2129 }
2130
2081 FuncNameInferrer::State fni_state(fni_); 2131 FuncNameInferrer::State fni_state(fni_);
2082 if (fni_ != NULL) fni_->PushEnclosingName(name); 2132 if (fni_ != NULL) fni_->PushEnclosingName(name);
2083 FunctionLiteral* fun = ParseFunctionLiteral( 2133 FunctionLiteral* fun = ParseFunctionLiteral(
2084 name, scanner()->location(), 2134 name, scanner()->location(),
2085 is_strict_reserved ? kFunctionNameIsStrictReserved 2135 is_strict_reserved ? kFunctionNameIsStrictReserved
2086 : kFunctionNameValidityUnknown, 2136 : kFunctionNameValidityUnknown,
2087 is_generator ? FunctionKind::kGeneratorFunction 2137 is_generator ? FunctionKind::kGeneratorFunction
2088 : FunctionKind::kNormalFunction, 2138 : is_async ? FunctionKind::kAsyncFunction
2139 : FunctionKind::kNormalFunction,
2089 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); 2140 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK);
2090 2141
2091 // Even if we're not at the top-level of the global or a function 2142 // Even if we're not at the top-level of the global or a function
2092 // scope, we treat it as such and introduce the function with its 2143 // scope, we treat it as such and introduce the function with its
2093 // initial value upon entering the corresponding scope. 2144 // initial value upon entering the corresponding scope.
2094 // In ES6, a function behaves as a lexical binding, except in 2145 // In ES6, a function behaves as a lexical binding, except in
2095 // a script scope, or the initial scope of eval or another function. 2146 // a script scope, or the initial scope of eval or another function.
2096 VariableMode mode = 2147 VariableMode mode =
2097 (!scope_->is_declaration_scope() || scope_->is_module_scope()) ? LET 2148 (!scope_->is_declaration_scope() || scope_->is_module_scope()) ? LET
2098 : VAR; 2149 : VAR;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
2391 return true; 2442 return true;
2392 } 2443 }
2393 } 2444 }
2394 } 2445 }
2395 return false; 2446 return false;
2396 } 2447 }
2397 2448
2398 Statement* Parser::ParseFunctionDeclaration(bool* ok) { 2449 Statement* Parser::ParseFunctionDeclaration(bool* ok) {
2399 Consume(Token::FUNCTION); 2450 Consume(Token::FUNCTION);
2400 int pos = position(); 2451 int pos = position();
2401 bool is_generator = Check(Token::MUL); 2452 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
2402 if (allow_harmony_restrictive_declarations() && is_generator) { 2453 if (Check(Token::MUL)) {
2403 ParserTraits::ReportMessageAt( 2454 flags |= ParseFunctionFlags::kIsGenerator;
2404 scanner()->location(), 2455 if (allow_harmony_restrictive_declarations()) {
2405 MessageTemplate::kGeneratorInLegacyContext); 2456 ParserTraits::ReportMessageAt(scanner()->location(),
2406 *ok = false; 2457 MessageTemplate::kGeneratorInLegacyContext);
2407 return nullptr; 2458 *ok = false;
2459 return nullptr;
2460 }
2408 } 2461 }
2409 return ParseHoistableDeclaration(pos, is_generator, nullptr, CHECK_OK); 2462
2463 return ParseHoistableDeclaration(pos, flags, nullptr, CHECK_OK);
2410 } 2464 }
2411 2465
2412 Statement* Parser::ParseExpressionOrLabelledStatement( 2466 Statement* Parser::ParseExpressionOrLabelledStatement(
2413 ZoneList<const AstRawString*>* labels, 2467 ZoneList<const AstRawString*>* labels,
2414 AllowLabelledFunctionStatement allow_function, bool* ok) { 2468 AllowLabelledFunctionStatement allow_function, bool* ok) {
2415 // ExpressionStatement | LabelledStatement :: 2469 // ExpressionStatement | LabelledStatement ::
2416 // Expression ';' 2470 // Expression ';'
2417 // Identifier ':' Statement 2471 // Identifier ':' Statement
2418 // 2472 //
2419 // ExpressionStatement[Yield] : 2473 // ExpressionStatement[Yield] :
(...skipping 1779 matching lines...) Expand 10 before | Expand all | Expand 10 after
4199 expected_property_count, arity, duplicate_parameters, function_type, 4253 expected_property_count, arity, duplicate_parameters, function_type,
4200 eager_compile_hint, kind, pos); 4254 eager_compile_hint, kind, pos);
4201 function_literal->set_function_token_position(function_token_pos); 4255 function_literal->set_function_token_position(function_token_pos);
4202 if (should_be_used_once_hint) 4256 if (should_be_used_once_hint)
4203 function_literal->set_should_be_used_once_hint(); 4257 function_literal->set_should_be_used_once_hint();
4204 4258
4205 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); 4259 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal);
4206 return function_literal; 4260 return function_literal;
4207 } 4261 }
4208 4262
4263 Expression* Parser::ParseAsyncFunctionExpression(bool* ok) {
4264 // AsyncFunctionDeclaration ::
4265 // async [no LineTerminator here] function ( FormalParameters[Await] )
4266 // { AsyncFunctionBody }
4267 //
4268 // async [no LineTerminator here] function BindingIdentifier[Await]
4269 // ( FormalParameters[Await] ) { AsyncFunctionBody }
4270 DCHECK_EQ(scanner()->current_token(), Token::IDENTIFIER);
4271 DCHECK(scanner()->is_literal_contextual_keyword(CStrVector("async")));
4272 int pos = position();
4273 Expect(Token::FUNCTION, CHECK_OK);
4274 bool is_strict_reserved = false;
4275 const AstRawString* name = nullptr;
4276 FunctionLiteral::FunctionType type = FunctionLiteral::kAnonymousExpression;
4277
4278 if (peek_any_identifier()) {
4279 type = FunctionLiteral::kNamedExpression;
4280 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
4281 if (this->IsAwait(name)) {
4282 ReportMessageAt(scanner()->location(),
4283 MessageTemplate::kAwaitBindingIdentifier);
4284 *ok = false;
4285 return nullptr;
4286 }
4287 }
4288 return ParseFunctionLiteral(name, scanner()->location(),
4289 is_strict_reserved ? kFunctionNameIsStrictReserved
4290 : kFunctionNameValidityUnknown,
4291 FunctionKind::kAsyncFunction, pos, type,
4292 language_mode(), CHECK_OK);
4293 }
4209 4294
4210 void Parser::SkipLazyFunctionBody(int* materialized_literal_count, 4295 void Parser::SkipLazyFunctionBody(int* materialized_literal_count,
4211 int* expected_property_count, bool* ok, 4296 int* expected_property_count, bool* ok,
4212 Scanner::BookmarkScope* bookmark) { 4297 Scanner::BookmarkScope* bookmark) {
4213 DCHECK_IMPLIES(bookmark, bookmark->HasBeenSet()); 4298 DCHECK_IMPLIES(bookmark, bookmark->HasBeenSet());
4214 if (produce_cached_parse_data()) CHECK(log_); 4299 if (produce_cached_parse_data()) CHECK(log_);
4215 4300
4216 int function_block_pos = position(); 4301 int function_block_pos = position();
4217 if (consume_cached_parse_data() && !cached_parse_data_->rejected()) { 4302 if (consume_cached_parse_data() && !cached_parse_data_->rejected()) {
4218 // If we have cached data, we use it to skip parsing the function body. The 4303 // If we have cached data, we use it to skip parsing the function body. The
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
4598 NULL, stack_limit_); 4683 NULL, stack_limit_);
4599 reusable_preparser_->set_allow_lazy(true); 4684 reusable_preparser_->set_allow_lazy(true);
4600 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); 4685 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
4601 SET_ALLOW(natives); 4686 SET_ALLOW(natives);
4602 SET_ALLOW(harmony_do_expressions); 4687 SET_ALLOW(harmony_do_expressions);
4603 SET_ALLOW(harmony_for_in); 4688 SET_ALLOW(harmony_for_in);
4604 SET_ALLOW(harmony_function_name); 4689 SET_ALLOW(harmony_function_name);
4605 SET_ALLOW(harmony_function_sent); 4690 SET_ALLOW(harmony_function_sent);
4606 SET_ALLOW(harmony_exponentiation_operator); 4691 SET_ALLOW(harmony_exponentiation_operator);
4607 SET_ALLOW(harmony_restrictive_declarations); 4692 SET_ALLOW(harmony_restrictive_declarations);
4693 SET_ALLOW(harmony_async_await);
4608 #undef SET_ALLOW 4694 #undef SET_ALLOW
4609 } 4695 }
4610 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4696 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4611 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), 4697 language_mode(), function_state_->kind(), scope_->has_simple_parameters(),
4612 parsing_module_, logger, bookmark, use_counts_); 4698 parsing_module_, logger, bookmark, use_counts_);
4613 if (pre_parse_timer_ != NULL) { 4699 if (pre_parse_timer_ != NULL) {
4614 pre_parse_timer_->Stop(); 4700 pre_parse_timer_->Stop();
4615 } 4701 }
4616 return result; 4702 return result;
4617 } 4703 }
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
5305 for (int i = 0; i < tail_call_expressions.length(); ++i) { 5391 for (int i = 0; i < tail_call_expressions.length(); ++i) {
5306 Expression* expression = tail_call_expressions[i]; 5392 Expression* expression = tail_call_expressions[i];
5307 // If only FLAG_harmony_explicit_tailcalls is enabled then expression 5393 // If only FLAG_harmony_explicit_tailcalls is enabled then expression
5308 // must be a Call expression. 5394 // must be a Call expression.
5309 DCHECK(FLAG_harmony_tailcalls || !FLAG_harmony_explicit_tailcalls || 5395 DCHECK(FLAG_harmony_tailcalls || !FLAG_harmony_explicit_tailcalls ||
5310 expression->IsCall()); 5396 expression->IsCall());
5311 MarkTailPosition(expression); 5397 MarkTailPosition(expression);
5312 } 5398 }
5313 } 5399 }
5314 5400
5401 Expression* ParserTraits::ExpressionListToExpression(
5402 ZoneList<Expression*>* args) {
5403 AstNodeFactory* factory = parser_->factory();
5404 Expression* expr = args->at(0);
5405 for (int i = 1; i < args->length(); ++i) {
5406 expr = factory->NewBinaryOperation(Token::COMMA, expr, args->at(i),
5407 expr->position());
5408 }
5409 return expr;
5410 }
5411
5315 void ParserTraits::RewriteDestructuringAssignments() { 5412 void ParserTraits::RewriteDestructuringAssignments() {
5316 parser_->RewriteDestructuringAssignments(); 5413 parser_->RewriteDestructuringAssignments();
5317 } 5414 }
5318 5415
5319 Expression* ParserTraits::RewriteExponentiation(Expression* left, 5416 Expression* ParserTraits::RewriteExponentiation(Expression* left,
5320 Expression* right, int pos) { 5417 Expression* right, int pos) {
5321 return parser_->RewriteExponentiation(left, right, pos); 5418 return parser_->RewriteExponentiation(left, right, pos);
5322 } 5419 }
5323 5420
5324 Expression* ParserTraits::RewriteAssignExponentiation(Expression* left, 5421 Expression* ParserTraits::RewriteAssignExponentiation(Expression* left,
5325 Expression* right, 5422 Expression* right,
5326 int pos) { 5423 int pos) {
5327 return parser_->RewriteAssignExponentiation(left, right, pos); 5424 return parser_->RewriteAssignExponentiation(left, right, pos);
5328 } 5425 }
5329 5426
5330 void ParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, 5427 void ParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier,
5331 bool* ok) { 5428 bool* ok) {
5332 parser_->RewriteNonPattern(classifier, ok); 5429 parser_->RewriteNonPattern(classifier, ok);
5333 } 5430 }
5334 5431
5432 Expression* ParserTraits::RewriteAwaitExpression(Expression* value, int pos) {
5433 // TODO(caitp): Implement AsyncFunctionAwait()
5434 // per tc39.github.io/ecmascript-asyncawait/#abstract-ops-async-function-await
5435 return value;
5436 }
5335 5437
5336 Zone* ParserTraits::zone() const { 5438 Zone* ParserTraits::zone() const {
5337 return parser_->function_state_->scope()->zone(); 5439 return parser_->function_state_->scope()->zone();
5338 } 5440 }
5339 5441
5340 5442
5341 ZoneList<Expression*>* ParserTraits::GetNonPatternList() const { 5443 ZoneList<Expression*>* ParserTraits::GetNonPatternList() const {
5342 return parser_->function_state_->non_patterns_to_rewrite(); 5444 return parser_->function_state_->non_patterns_to_rewrite();
5343 } 5445 }
5344 5446
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after
6817 try_block, target); 6919 try_block, target);
6818 final_loop = target; 6920 final_loop = target;
6819 } 6921 }
6820 6922
6821 return final_loop; 6923 return final_loop;
6822 } 6924 }
6823 6925
6824 6926
6825 } // namespace internal 6927 } // namespace internal
6826 } // namespace v8 6928 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698