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

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: frontend-side prep 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
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 FunctionState function_state(&function_state_, &scope_, scope, 1073 FunctionState function_state(&function_state_, &scope_, scope,
1069 shared_info->kind(), &function_factory); 1074 shared_info->kind(), &function_factory);
1070 DCHECK(is_sloppy(scope->language_mode()) || 1075 DCHECK(is_sloppy(scope->language_mode()) ||
1071 is_strict(info->language_mode())); 1076 is_strict(info->language_mode()));
1072 DCHECK(info->language_mode() == shared_info->language_mode()); 1077 DCHECK(info->language_mode() == shared_info->language_mode());
1073 FunctionLiteral::FunctionType function_type = 1078 FunctionLiteral::FunctionType function_type =
1074 ComputeFunctionType(shared_info); 1079 ComputeFunctionType(shared_info);
1075 bool ok = true; 1080 bool ok = true;
1076 1081
1077 if (shared_info->is_arrow()) { 1082 if (shared_info->is_arrow()) {
1083 bool is_async = allow_harmony_async_await() && shared_info->is_async();
1084 if (is_async) {
1085 DCHECK(!scanner()->HasAnyLineTerminatorAfterNext());
1086 Consume(Token::ASYNC);
1087 DCHECK(peek_any_identifier() || peek() == Token::LPAREN);
1088 }
1089
1078 // TODO(adamk): We should construct this scope from the ScopeInfo. 1090 // TODO(adamk): We should construct this scope from the ScopeInfo.
1079 Scope* scope = 1091 Scope* scope =
1080 NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction); 1092 NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction);
1081 1093
1082 // These two bits only need to be explicitly set because we're 1094 // These two bits only need to be explicitly set because we're
1083 // not passing the ScopeInfo to the Scope constructor. 1095 // not passing the ScopeInfo to the Scope constructor.
1084 // TODO(adamk): Remove these calls once the above NewScope call 1096 // TODO(adamk): Remove these calls once the above NewScope call
1085 // passes the ScopeInfo. 1097 // passes the ScopeInfo.
1086 if (shared_info->scope_info()->CallsEval()) { 1098 if (shared_info->scope_info()->CallsEval()) {
1087 scope->RecordEvalCall(); 1099 scope->RecordEvalCall();
(...skipping 20 matching lines...) Expand all
1108 DeclareFormalParameter(formals.scope, formals.at(0), 1120 DeclareFormalParameter(formals.scope, formals.at(0),
1109 &formals_classifier); 1121 &formals_classifier);
1110 } 1122 }
1111 } 1123 }
1112 } 1124 }
1113 1125
1114 if (ok) { 1126 if (ok) {
1115 checkpoint.Restore(&formals.materialized_literals_count); 1127 checkpoint.Restore(&formals.materialized_literals_count);
1116 // Pass `accept_IN=true` to ParseArrowFunctionLiteral --- This should 1128 // Pass `accept_IN=true` to ParseArrowFunctionLiteral --- This should
1117 // not be observable, or else the preparser would have failed. 1129 // not be observable, or else the preparser would have failed.
1118 Expression* expression = 1130 Expression* expression = ParseArrowFunctionLiteral(
1119 ParseArrowFunctionLiteral(true, formals, formals_classifier, &ok); 1131 true, formals, is_async, formals_classifier, &ok);
1120 if (ok) { 1132 if (ok) {
1121 // Scanning must end at the same position that was recorded 1133 // Scanning must end at the same position that was recorded
1122 // previously. If not, parsing has been interrupted due to a stack 1134 // previously. If not, parsing has been interrupted due to a stack
1123 // overflow, at which point the partially parsed arrow function 1135 // overflow, at which point the partially parsed arrow function
1124 // concise body happens to be a valid expression. This is a problem 1136 // concise body happens to be a valid expression. This is a problem
1125 // only for arrow functions with single expression bodies, since there 1137 // only for arrow functions with single expression bodies, since there
1126 // is no end token such as "}" for normal functions. 1138 // is no end token such as "}" for normal functions.
1127 if (scanner()->location().end_pos == shared_info->end_position()) { 1139 if (scanner()->location().end_pos == shared_info->end_position()) {
1128 // The pre-parser saw an arrow function here, so the full parser 1140 // The pre-parser saw an arrow function here, so the full parser
1129 // must produce a FunctionLiteral. 1141 // must produce a FunctionLiteral.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 1260
1249 return 0; 1261 return 0;
1250 } 1262 }
1251 1263
1252 1264
1253 Statement* Parser::ParseStatementListItem(bool* ok) { 1265 Statement* Parser::ParseStatementListItem(bool* ok) {
1254 // (Ecma 262 6th Edition, 13.1): 1266 // (Ecma 262 6th Edition, 13.1):
1255 // StatementListItem: 1267 // StatementListItem:
1256 // Statement 1268 // Statement
1257 // Declaration 1269 // Declaration
1258 1270 const Token::Value peeked = peek();
1259 switch (peek()) { 1271 switch (peeked) {
1260 case Token::FUNCTION: 1272 case Token::FUNCTION:
1261 return ParseHoistableDeclaration(NULL, ok); 1273 return ParseHoistableDeclaration(NULL, ok);
1262 case Token::CLASS: 1274 case Token::CLASS:
1263 Consume(Token::CLASS); 1275 Consume(Token::CLASS);
1264 return ParseClassDeclaration(NULL, ok); 1276 return ParseClassDeclaration(NULL, ok);
1265 case Token::CONST: 1277 case Token::CONST:
1266 return ParseVariableStatement(kStatementListItem, NULL, ok); 1278 return ParseVariableStatement(kStatementListItem, NULL, ok);
1267 case Token::VAR: 1279 case Token::VAR:
1268 return ParseVariableStatement(kStatementListItem, NULL, ok); 1280 return ParseVariableStatement(kStatementListItem, NULL, ok);
1269 case Token::LET: 1281 case Token::LET:
1270 if (IsNextLetKeyword()) { 1282 if (IsNextLetKeyword()) {
1271 return ParseVariableStatement(kStatementListItem, NULL, ok); 1283 return ParseVariableStatement(kStatementListItem, NULL, ok);
1272 } 1284 }
1273 break; 1285 break;
1286 case Token::ASYNC:
1287 if (allow_harmony_async_await() && PeekAhead() == Token::FUNCTION &&
1288 !scanner()->HasAnyLineTerminatorAfterNext()) {
1289 Consume(Token::ASYNC);
1290 return ParseAsyncFunctionDeclaration(NULL, ok);
1291 }
1292 /* falls through */
1274 default: 1293 default:
1275 break; 1294 break;
1276 } 1295 }
1277 return ParseStatement(NULL, kAllowLabelledFunctionStatement, ok); 1296 return ParseStatement(NULL, kAllowLabelledFunctionStatement, ok);
1278 } 1297 }
1279 1298
1280 1299
1281 Statement* Parser::ParseModuleItem(bool* ok) { 1300 Statement* Parser::ParseModuleItem(bool* ok) {
1282 // (Ecma 262 6th Edition, 15.2): 1301 // (Ecma 262 6th Edition, 15.2):
1283 // ModuleItem : 1302 // ModuleItem :
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 // GeneratorDeclaration[+Default] :: 1572 // GeneratorDeclaration[+Default] ::
1554 // 'function' '*' '(' FormalParameters ')' '{' FunctionBody '}' 1573 // 'function' '*' '(' FormalParameters ')' '{' FunctionBody '}'
1555 default_export = ParseFunctionLiteral( 1574 default_export = ParseFunctionLiteral(
1556 default_string, Scanner::Location::invalid(), 1575 default_string, Scanner::Location::invalid(),
1557 kSkipFunctionNameCheck, 1576 kSkipFunctionNameCheck,
1558 is_generator ? FunctionKind::kGeneratorFunction 1577 is_generator ? FunctionKind::kGeneratorFunction
1559 : FunctionKind::kNormalFunction, 1578 : FunctionKind::kNormalFunction,
1560 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); 1579 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK);
1561 result = factory()->NewEmptyStatement(RelocInfo::kNoPosition); 1580 result = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
1562 } else { 1581 } else {
1563 result = ParseHoistableDeclaration(pos, is_generator, &names, CHECK_OK); 1582 result = ParseHoistableDeclaration(
1583 pos, is_generator ? ParseFunctionFlags::kIsGenerator
1584 : ParseFunctionFlags::kIsNormal,
1585 &names, CHECK_OK);
1564 } 1586 }
1565 break; 1587 break;
1566 } 1588 }
1567 1589
1568 case Token::CLASS: 1590 case Token::CLASS:
1569 Consume(Token::CLASS); 1591 Consume(Token::CLASS);
1570 if (peek() == Token::EXTENDS || peek() == Token::LBRACE) { 1592 if (peek() == Token::EXTENDS || peek() == Token::LBRACE) {
1571 // ClassDeclaration[+Default] :: 1593 // ClassDeclaration[+Default] ::
1572 // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}' 1594 // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}'
1573 default_export = ParseClassLiteral(nullptr, default_string, 1595 default_export = ParseClassLiteral(nullptr, default_string,
1574 Scanner::Location::invalid(), false, 1596 Scanner::Location::invalid(), false,
1575 position(), CHECK_OK); 1597 position(), CHECK_OK);
1576 result = factory()->NewEmptyStatement(RelocInfo::kNoPosition); 1598 result = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
1577 } else { 1599 } else {
1578 result = ParseClassDeclaration(&names, CHECK_OK); 1600 result = ParseClassDeclaration(&names, CHECK_OK);
1579 } 1601 }
1580 break; 1602 break;
1581 1603
1582 default: { 1604 default: {
Dan Ehrenberg 2016/05/16 20:38:37 What about export default async function foo() {}
1583 int pos = peek_position(); 1605 int pos = peek_position();
1584 ExpressionClassifier classifier(this); 1606 ExpressionClassifier classifier(this);
1585 Expression* expr = ParseAssignmentExpression(true, &classifier, CHECK_OK); 1607 Expression* expr = ParseAssignmentExpression(true, &classifier, CHECK_OK);
1586 RewriteNonPattern(&classifier, CHECK_OK); 1608 RewriteNonPattern(&classifier, CHECK_OK);
1587 1609
1588 ExpectSemicolon(CHECK_OK); 1610 ExpectSemicolon(CHECK_OK);
1589 result = factory()->NewExpressionStatement(expr, pos); 1611 result = factory()->NewExpressionStatement(expr, pos);
1590 break; 1612 break;
1591 } 1613 }
1592 } 1614 }
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 return factory()->NewExpressionStatement( 2077 return factory()->NewExpressionStatement(
2056 factory()->NewAssignment(Token::INIT, proxy, lit, RelocInfo::kNoPosition), 2078 factory()->NewAssignment(Token::INIT, proxy, lit, RelocInfo::kNoPosition),
2057 pos); 2079 pos);
2058 } 2080 }
2059 2081
2060 2082
2061 Statement* Parser::ParseHoistableDeclaration( 2083 Statement* Parser::ParseHoistableDeclaration(
2062 ZoneList<const AstRawString*>* names, bool* ok) { 2084 ZoneList<const AstRawString*>* names, bool* ok) {
2063 Expect(Token::FUNCTION, CHECK_OK); 2085 Expect(Token::FUNCTION, CHECK_OK);
2064 int pos = position(); 2086 int pos = position();
2065 bool is_generator = Check(Token::MUL); 2087 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
2066 return ParseHoistableDeclaration(pos, is_generator, names, ok); 2088 if (Check(Token::MUL)) {
2089 flags |= ParseFunctionFlags::kIsGenerator;
2090 }
2091 return ParseHoistableDeclaration(pos, flags, names, ok);
2067 } 2092 }
2068 2093
2094 Statement* Parser::ParseAsyncFunctionDeclaration(
2095 ZoneList<const AstRawString*>* names, bool* ok) {
2096 DCHECK_EQ(scanner()->current_token(), Token::ASYNC);
2097 int pos = position();
2098 Expect(Token::FUNCTION, CHECK_OK);
2099 ParseFunctionFlags flags = ParseFunctionFlags::kIsAsync;
2100 return ParseHoistableDeclaration(pos, flags, names, ok);
2101 }
2069 2102
2070 Statement* Parser::ParseHoistableDeclaration( 2103 Statement* Parser::ParseHoistableDeclaration(
2071 int pos, bool is_generator, ZoneList<const AstRawString*>* names, 2104 int pos, ParseFunctionFlags flags, ZoneList<const AstRawString*>* names,
2072 bool* ok) { 2105 bool* ok) {
2073 // FunctionDeclaration :: 2106 // FunctionDeclaration ::
2074 // 'function' Identifier '(' FormalParameters ')' '{' FunctionBody '}' 2107 // 'function' Identifier '(' FormalParameters ')' '{' FunctionBody '}'
2075 // GeneratorDeclaration :: 2108 // GeneratorDeclaration ::
2076 // 'function' '*' Identifier '(' FormalParameters ')' '{' FunctionBody '}' 2109 // 'function' '*' Identifier '(' FormalParameters ')' '{' FunctionBody '}'
2077 // 2110 //
2078 // 'function' and '*' (if present) have been consumed by the caller. 2111 // 'function' and '*' (if present) have been consumed by the caller.
2112 const bool is_generator = flags & ParseFunctionFlags::kIsGenerator;
2113 const bool is_async = flags & ParseFunctionFlags::kIsAsync;
2114 DCHECK(!is_generator || !is_async);
2115
2079 bool is_strict_reserved = false; 2116 bool is_strict_reserved = false;
2080 const AstRawString* name = ParseIdentifierOrStrictReservedWord( 2117 const AstRawString* name = ParseIdentifierOrStrictReservedWord(
2081 &is_strict_reserved, CHECK_OK); 2118 &is_strict_reserved, CHECK_OK);
2082 2119
2120 if (V8_UNLIKELY(is_async_function() && is_async && this->IsAwait(name))) {
2121 ReportMessageAt(scanner()->location(),
2122 MessageTemplate::kAwaitBindingIdentifier);
2123 *ok = false;
2124 return nullptr;
2125 }
2126
2083 FuncNameInferrer::State fni_state(fni_); 2127 FuncNameInferrer::State fni_state(fni_);
2084 if (fni_ != NULL) fni_->PushEnclosingName(name); 2128 if (fni_ != NULL) fni_->PushEnclosingName(name);
2085 FunctionLiteral* fun = ParseFunctionLiteral( 2129 FunctionLiteral* fun = ParseFunctionLiteral(
2086 name, scanner()->location(), 2130 name, scanner()->location(),
2087 is_strict_reserved ? kFunctionNameIsStrictReserved 2131 is_strict_reserved ? kFunctionNameIsStrictReserved
2088 : kFunctionNameValidityUnknown, 2132 : kFunctionNameValidityUnknown,
2089 is_generator ? FunctionKind::kGeneratorFunction 2133 is_generator ? FunctionKind::kGeneratorFunction
2090 : FunctionKind::kNormalFunction, 2134 : is_async ? FunctionKind::kAsyncFunction
2135 : FunctionKind::kNormalFunction,
2091 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); 2136 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK);
2092 2137
2093 // Even if we're not at the top-level of the global or a function 2138 // Even if we're not at the top-level of the global or a function
2094 // scope, we treat it as such and introduce the function with its 2139 // scope, we treat it as such and introduce the function with its
2095 // initial value upon entering the corresponding scope. 2140 // initial value upon entering the corresponding scope.
2096 // In ES6, a function behaves as a lexical binding, except in 2141 // In ES6, a function behaves as a lexical binding, except in
2097 // a script scope, or the initial scope of eval or another function. 2142 // a script scope, or the initial scope of eval or another function.
2098 VariableMode mode = 2143 VariableMode mode =
2099 (!scope_->is_declaration_scope() || scope_->is_module_scope()) ? LET 2144 (!scope_->is_declaration_scope() || scope_->is_module_scope()) ? LET
2100 : VAR; 2145 : VAR;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
2393 return true; 2438 return true;
2394 } 2439 }
2395 } 2440 }
2396 } 2441 }
2397 return false; 2442 return false;
2398 } 2443 }
2399 2444
2400 Statement* Parser::ParseFunctionDeclaration(bool* ok) { 2445 Statement* Parser::ParseFunctionDeclaration(bool* ok) {
2401 Consume(Token::FUNCTION); 2446 Consume(Token::FUNCTION);
2402 int pos = position(); 2447 int pos = position();
2403 bool is_generator = Check(Token::MUL); 2448 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
2404 if (allow_harmony_restrictive_declarations() && is_generator) { 2449 if (Check(Token::MUL)) {
2405 ParserTraits::ReportMessageAt( 2450 flags |= ParseFunctionFlags::kIsGenerator;
2406 scanner()->location(), 2451 if (allow_harmony_restrictive_declarations()) {
2407 MessageTemplate::kGeneratorInLegacyContext); 2452 ParserTraits::ReportMessageAt(scanner()->location(),
2408 *ok = false; 2453 MessageTemplate::kGeneratorInLegacyContext);
2409 return nullptr; 2454 *ok = false;
2455 return nullptr;
2456 }
2410 } 2457 }
2411 return ParseHoistableDeclaration(pos, is_generator, nullptr, CHECK_OK); 2458
2459 return ParseHoistableDeclaration(pos, flags, nullptr, CHECK_OK);
2412 } 2460 }
2413 2461
2414 Statement* Parser::ParseExpressionOrLabelledStatement( 2462 Statement* Parser::ParseExpressionOrLabelledStatement(
2415 ZoneList<const AstRawString*>* labels, 2463 ZoneList<const AstRawString*>* labels,
2416 AllowLabelledFunctionStatement allow_function, bool* ok) { 2464 AllowLabelledFunctionStatement allow_function, bool* ok) {
2417 // ExpressionStatement | LabelledStatement :: 2465 // ExpressionStatement | LabelledStatement ::
2418 // Expression ';' 2466 // Expression ';'
2419 // Identifier ':' Statement 2467 // Identifier ':' Statement
2420 // 2468 //
2421 // ExpressionStatement[Yield] : 2469 // ExpressionStatement[Yield] :
(...skipping 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after
4044 scope_->set_start_position(start_position); 4092 scope_->set_start_position(start_position);
4045 ParserFormalParameters formals(scope); 4093 ParserFormalParameters formals(scope);
4046 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); 4094 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK);
4047 arity = formals.Arity(); 4095 arity = formals.Arity();
4048 Expect(Token::RPAREN, CHECK_OK); 4096 Expect(Token::RPAREN, CHECK_OK);
4049 int formals_end_position = scanner()->location().end_pos; 4097 int formals_end_position = scanner()->location().end_pos;
4050 4098
4051 CheckArityRestrictions(arity, kind, formals.has_rest, start_position, 4099 CheckArityRestrictions(arity, kind, formals.has_rest, start_position,
4052 formals_end_position, CHECK_OK); 4100 formals_end_position, CHECK_OK);
4053 Expect(Token::LBRACE, CHECK_OK); 4101 Expect(Token::LBRACE, CHECK_OK);
4054
4055 // Don't include the rest parameter into the function's formal parameter 4102 // Don't include the rest parameter into the function's formal parameter
4056 // count (esp. the SharedFunctionInfo::internal_formal_parameter_count, 4103 // count (esp. the SharedFunctionInfo::internal_formal_parameter_count,
4057 // which says whether we need to create an arguments adaptor frame). 4104 // which says whether we need to create an arguments adaptor frame).
4058 if (formals.has_rest) arity--; 4105 if (formals.has_rest) arity--;
4059 4106
4060 // Determine if the function can be parsed lazily. Lazy parsing is different 4107 // Determine if the function can be parsed lazily. Lazy parsing is different
4061 // from lazy compilation; we need to parse more eagerly than we compile. 4108 // from lazy compilation; we need to parse more eagerly than we compile.
4062 4109
4063 // We can only parse lazily if we also compile lazily. The heuristics for 4110 // We can only parse lazily if we also compile lazily. The heuristics for
4064 // lazy compilation are: 4111 // lazy compilation are:
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
4200 expected_property_count, arity, duplicate_parameters, function_type, 4247 expected_property_count, arity, duplicate_parameters, function_type,
4201 eager_compile_hint, kind, pos); 4248 eager_compile_hint, kind, pos);
4202 function_literal->set_function_token_position(function_token_pos); 4249 function_literal->set_function_token_position(function_token_pos);
4203 if (should_be_used_once_hint) 4250 if (should_be_used_once_hint)
4204 function_literal->set_should_be_used_once_hint(); 4251 function_literal->set_should_be_used_once_hint();
4205 4252
4206 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); 4253 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal);
4207 return function_literal; 4254 return function_literal;
4208 } 4255 }
4209 4256
4257 Expression* Parser::ParseAsyncFunctionExpression(bool* ok) {
4258 // AsyncFunctionDeclaration ::
4259 // async [no LineTerminator here] function ( FormalParameters[Await] )
4260 // { AsyncFunctionBody }
4261 //
4262 // async [no LineTerminator here] function BindingIdentifier[Await]
4263 // ( FormalParameters[Await] ) { AsyncFunctionBody }
4264 DCHECK_EQ(scanner()->current_token(), Token::ASYNC);
4265 int pos = position();
4266 Expect(Token::FUNCTION, CHECK_OK);
4267 bool is_strict_reserved = false;
4268 const AstRawString* name = nullptr;
4269 FunctionLiteral::FunctionType type = FunctionLiteral::kAnonymousExpression;
4270
4271 if (peek_any_identifier()) {
4272 type = FunctionLiteral::kNamedExpression;
4273 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
4274 if (this->IsAwait(name)) {
4275 ReportMessageAt(scanner()->location(),
4276 MessageTemplate::kAwaitBindingIdentifier);
4277 *ok = false;
4278 return nullptr;
4279 }
4280 }
4281 return ParseFunctionLiteral(name, scanner()->location(),
4282 is_strict_reserved ? kFunctionNameIsStrictReserved
4283 : kFunctionNameValidityUnknown,
4284 FunctionKind::kAsyncFunction, pos, type,
4285 language_mode(), CHECK_OK);
4286 }
4210 4287
4211 void Parser::SkipLazyFunctionBody(int* materialized_literal_count, 4288 void Parser::SkipLazyFunctionBody(int* materialized_literal_count,
4212 int* expected_property_count, bool* ok, 4289 int* expected_property_count, bool* ok,
4213 Scanner::BookmarkScope* bookmark) { 4290 Scanner::BookmarkScope* bookmark) {
4214 DCHECK_IMPLIES(bookmark, bookmark->HasBeenSet()); 4291 DCHECK_IMPLIES(bookmark, bookmark->HasBeenSet());
4215 if (produce_cached_parse_data()) CHECK(log_); 4292 if (produce_cached_parse_data()) CHECK(log_);
4216 4293
4217 int function_block_pos = position(); 4294 int function_block_pos = position();
4218 if (consume_cached_parse_data() && !cached_parse_data_->rejected()) { 4295 if (consume_cached_parse_data() && !cached_parse_data_->rejected()) {
4219 // If we have cached data, we use it to skip parsing the function body. The 4296 // 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
4599 NULL, stack_limit_); 4676 NULL, stack_limit_);
4600 reusable_preparser_->set_allow_lazy(true); 4677 reusable_preparser_->set_allow_lazy(true);
4601 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); 4678 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
4602 SET_ALLOW(natives); 4679 SET_ALLOW(natives);
4603 SET_ALLOW(harmony_do_expressions); 4680 SET_ALLOW(harmony_do_expressions);
4604 SET_ALLOW(harmony_for_in); 4681 SET_ALLOW(harmony_for_in);
4605 SET_ALLOW(harmony_function_name); 4682 SET_ALLOW(harmony_function_name);
4606 SET_ALLOW(harmony_function_sent); 4683 SET_ALLOW(harmony_function_sent);
4607 SET_ALLOW(harmony_exponentiation_operator); 4684 SET_ALLOW(harmony_exponentiation_operator);
4608 SET_ALLOW(harmony_restrictive_declarations); 4685 SET_ALLOW(harmony_restrictive_declarations);
4686 SET_ALLOW(harmony_async_await);
4609 #undef SET_ALLOW 4687 #undef SET_ALLOW
4610 } 4688 }
4611 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4689 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4612 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), 4690 language_mode(), function_state_->kind(), scope_->has_simple_parameters(),
4613 parsing_module_, logger, bookmark, use_counts_); 4691 parsing_module_, logger, bookmark, use_counts_);
4614 if (pre_parse_timer_ != NULL) { 4692 if (pre_parse_timer_ != NULL) {
4615 pre_parse_timer_->Stop(); 4693 pre_parse_timer_->Stop();
4616 } 4694 }
4617 return result; 4695 return result;
4618 } 4696 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
4669 FunctionLiteral* constructor = NULL; 4747 FunctionLiteral* constructor = NULL;
4670 bool has_seen_constructor = false; 4748 bool has_seen_constructor = false;
4671 4749
4672 Expect(Token::LBRACE, CHECK_OK); 4750 Expect(Token::LBRACE, CHECK_OK);
4673 4751
4674 const bool has_extends = extends != nullptr; 4752 const bool has_extends = extends != nullptr;
4675 while (peek() != Token::RBRACE) { 4753 while (peek() != Token::RBRACE) {
4676 if (Check(Token::SEMICOLON)) continue; 4754 if (Check(Token::SEMICOLON)) continue;
4677 FuncNameInferrer::State fni_state(fni_); 4755 FuncNameInferrer::State fni_state(fni_);
4678 const bool in_class = true; 4756 const bool in_class = true;
4679 const bool is_static = false;
4680 bool is_computed_name = false; // Classes do not care about computed 4757 bool is_computed_name = false; // Classes do not care about computed
4681 // property names here. 4758 // property names here.
4682 ExpressionClassifier property_classifier(this); 4759 ExpressionClassifier property_classifier(this);
4683 const AstRawString* property_name = nullptr; 4760 const AstRawString* property_name = nullptr;
4684 ObjectLiteral::Property* property = ParsePropertyDefinition( 4761 ObjectLiteral::Property* property = ParsePropertyDefinition(
4685 &checker, in_class, has_extends, is_static, &is_computed_name, 4762 &checker, in_class, has_extends, MethodKind::Normal, &is_computed_name,
4686 &has_seen_constructor, &property_classifier, &property_name, CHECK_OK); 4763 &has_seen_constructor, &property_classifier, &property_name, CHECK_OK);
4687 RewriteNonPattern(&property_classifier, CHECK_OK); 4764 RewriteNonPattern(&property_classifier, CHECK_OK);
4688 if (classifier != nullptr) { 4765 if (classifier != nullptr) {
4689 classifier->Accumulate(&property_classifier, 4766 classifier->Accumulate(&property_classifier,
4690 ExpressionClassifier::ExpressionProductions); 4767 ExpressionClassifier::ExpressionProductions);
4691 } 4768 }
4692 4769
4693 if (has_seen_constructor && constructor == NULL) { 4770 if (has_seen_constructor && constructor == NULL) {
4694 constructor = GetPropertyValue(property)->AsFunctionLiteral(); 4771 constructor = GetPropertyValue(property)->AsFunctionLiteral();
4695 DCHECK_NOT_NULL(constructor); 4772 DCHECK_NOT_NULL(constructor);
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
5306 for (int i = 0; i < tail_call_expressions.length(); ++i) { 5383 for (int i = 0; i < tail_call_expressions.length(); ++i) {
5307 Expression* expression = tail_call_expressions[i]; 5384 Expression* expression = tail_call_expressions[i];
5308 // If only FLAG_harmony_explicit_tailcalls is enabled then expression 5385 // If only FLAG_harmony_explicit_tailcalls is enabled then expression
5309 // must be a Call expression. 5386 // must be a Call expression.
5310 DCHECK(FLAG_harmony_tailcalls || !FLAG_harmony_explicit_tailcalls || 5387 DCHECK(FLAG_harmony_tailcalls || !FLAG_harmony_explicit_tailcalls ||
5311 expression->IsCall()); 5388 expression->IsCall());
5312 MarkTailPosition(expression); 5389 MarkTailPosition(expression);
5313 } 5390 }
5314 } 5391 }
5315 5392
5393 Expression* ParserTraits::ExpressionListToExpression(
5394 ZoneList<Expression*>* args) {
5395 AstNodeFactory* factory = parser_->factory();
5396 Expression* expr = args->at(0);
5397 for (int i = 1; i < args->length(); ++i) {
5398 expr = factory->NewBinaryOperation(Token::COMMA, expr, args->at(i),
5399 expr->position());
5400 }
5401 return expr;
5402 }
5403
5316 void ParserTraits::RewriteDestructuringAssignments() { 5404 void ParserTraits::RewriteDestructuringAssignments() {
5317 parser_->RewriteDestructuringAssignments(); 5405 parser_->RewriteDestructuringAssignments();
5318 } 5406 }
5319 5407
5320 Expression* ParserTraits::RewriteExponentiation(Expression* left, 5408 Expression* ParserTraits::RewriteExponentiation(Expression* left,
5321 Expression* right, int pos) { 5409 Expression* right, int pos) {
5322 return parser_->RewriteExponentiation(left, right, pos); 5410 return parser_->RewriteExponentiation(left, right, pos);
5323 } 5411 }
5324 5412
5325 Expression* ParserTraits::RewriteAssignExponentiation(Expression* left, 5413 Expression* ParserTraits::RewriteAssignExponentiation(Expression* left,
5326 Expression* right, 5414 Expression* right,
5327 int pos) { 5415 int pos) {
5328 return parser_->RewriteAssignExponentiation(left, right, pos); 5416 return parser_->RewriteAssignExponentiation(left, right, pos);
5329 } 5417 }
5330 5418
5331 void ParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, 5419 void ParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier,
5332 bool* ok) { 5420 bool* ok) {
5333 parser_->RewriteNonPattern(classifier, ok); 5421 parser_->RewriteNonPattern(classifier, ok);
5334 } 5422 }
5335 5423
5424 Expression* ParserTraits::RewriteAwaitExpression(Expression* value, int pos) {
5425 // TODO(caitp): Implement AsyncFunctionAwait()
5426 // per tc39.github.io/ecmascript-asyncawait/#abstract-ops-async-function-await
5427 return value;
5428 }
5336 5429
5337 Zone* ParserTraits::zone() const { 5430 Zone* ParserTraits::zone() const {
5338 return parser_->function_state_->scope()->zone(); 5431 return parser_->function_state_->scope()->zone();
5339 } 5432 }
5340 5433
5341 5434
5342 ZoneList<Expression*>* ParserTraits::GetNonPatternList() const { 5435 ZoneList<Expression*>* ParserTraits::GetNonPatternList() const {
5343 return parser_->function_state_->non_patterns_to_rewrite(); 5436 return parser_->function_state_->non_patterns_to_rewrite();
5344 } 5437 }
5345 5438
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after
6818 try_block, target); 6911 try_block, target);
6819 final_loop = target; 6912 final_loop = target;
6820 } 6913 }
6821 6914
6822 return final_loop; 6915 return final_loop;
6823 } 6916 }
6824 6917
6825 6918
6826 } // namespace internal 6919 } // namespace internal
6827 } // namespace v8 6920 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698