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

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

Issue 1841543003: [esnext] implement frontend changes for async/await proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase over generator change cl Created 4 years, 8 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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 <cmath> 5 #include <cmath>
6 6
7 #include "src/allocation.h" 7 #include "src/allocation.h"
8 #include "src/base/logging.h" 8 #include "src/base/logging.h"
9 #include "src/conversions-inl.h" 9 #include "src/conversions-inl.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 if (scanner->UnescapedLiteralMatches("undefined", 9)) { 59 if (scanner->UnescapedLiteralMatches("undefined", 9)) {
60 return PreParserIdentifier::Undefined(); 60 return PreParserIdentifier::Undefined();
61 } 61 }
62 if (scanner->LiteralMatches("prototype", 9)) { 62 if (scanner->LiteralMatches("prototype", 9)) {
63 return PreParserIdentifier::Prototype(); 63 return PreParserIdentifier::Prototype();
64 } 64 }
65 if (scanner->LiteralMatches("constructor", 11)) { 65 if (scanner->LiteralMatches("constructor", 11)) {
66 return PreParserIdentifier::Constructor(); 66 return PreParserIdentifier::Constructor();
67 } 67 }
68 if (scanner->LiteralMatches("async", 5)) {
69 return PreParserIdentifier::Async();
70 }
71 if (scanner->LiteralMatches("await", 5)) {
72 return PreParserIdentifier::Await();
73 }
68 return PreParserIdentifier::Default(); 74 return PreParserIdentifier::Default();
69 } 75 }
70 76
71 77
72 PreParserIdentifier PreParserTraits::GetNumberAsSymbol(Scanner* scanner) { 78 PreParserIdentifier PreParserTraits::GetNumberAsSymbol(Scanner* scanner) {
73 return PreParserIdentifier::Default(); 79 return PreParserIdentifier::Default();
74 } 80 }
75 81
76 82
77 PreParserExpression PreParserTraits::ExpressionFromString( 83 PreParserExpression PreParserTraits::ExpressionFromString(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 return ParseFunctionDeclaration(ok); 187 return ParseFunctionDeclaration(ok);
182 case Token::CLASS: 188 case Token::CLASS:
183 return ParseClassDeclaration(ok); 189 return ParseClassDeclaration(ok);
184 case Token::CONST: 190 case Token::CONST:
185 return ParseVariableStatement(kStatementListItem, ok); 191 return ParseVariableStatement(kStatementListItem, ok);
186 case Token::LET: 192 case Token::LET:
187 if (IsNextLetKeyword()) { 193 if (IsNextLetKeyword()) {
188 return ParseVariableStatement(kStatementListItem, ok); 194 return ParseVariableStatement(kStatementListItem, ok);
189 } 195 }
190 break; 196 break;
197 case Token::IDENTIFIER:
198 if (allow_harmony_async_await() &&
199 PeekContextualKeyword(CStrVector("async")) &&
200 PeekAhead() == Token::FUNCTION &&
201 !scanner()->HasAnyLineTerminatorAfterNext()) {
202 Consume(Token::IDENTIFIER);
203 return ParseAsyncFunctionDeclaration(ok);
204 }
205 /* falls through */
191 default: 206 default:
192 break; 207 break;
193 } 208 }
194 return ParseStatement(kAllowLabelledFunctionStatement, ok); 209 return ParseStatement(kAllowLabelledFunctionStatement, ok);
195 } 210 }
196 211
197 212
198 void PreParser::ParseStatementList(int end_token, bool* ok, 213 void PreParser::ParseStatementList(int end_token, bool* ok,
199 Scanner::BookmarkScope* bookmark) { 214 Scanner::BookmarkScope* bookmark) {
200 // SourceElements :: 215 // SourceElements ::
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 ParseFunctionLiteral(name, scanner()->location(), 405 ParseFunctionLiteral(name, scanner()->location(),
391 is_strict_reserved ? kFunctionNameIsStrictReserved 406 is_strict_reserved ? kFunctionNameIsStrictReserved
392 : kFunctionNameValidityUnknown, 407 : kFunctionNameValidityUnknown,
393 is_generator ? FunctionKind::kGeneratorFunction 408 is_generator ? FunctionKind::kGeneratorFunction
394 : FunctionKind::kNormalFunction, 409 : FunctionKind::kNormalFunction,
395 pos, FunctionLiteral::kDeclaration, language_mode(), 410 pos, FunctionLiteral::kDeclaration, language_mode(),
396 CHECK_OK); 411 CHECK_OK);
397 return Statement::FunctionDeclaration(); 412 return Statement::FunctionDeclaration();
398 } 413 }
399 414
415 PreParser::Statement PreParser::ParseAsyncFunctionDeclaration(bool* ok) {
416 // AsyncFunctionDeclaration ::
417 // async [no LineTerminator here] function BindingIdentifier[Await]
418 // ( FormalParameters[Await] ) { AsyncFunctionBody }
419 DCHECK_EQ(scanner()->current_token(), Token::IDENTIFIER);
420 DCHECK(scanner()->is_literal_contextual_keyword(CStrVector("async")));
421 int pos = position();
422 Expect(Token::FUNCTION, CHECK_OK);
423 bool is_strict_reserved = false;
424 Identifier name =
425 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
426 if (V8_UNLIKELY(is_async_function() && this->IsAwait(name))) {
427 ReportMessageAt(scanner()->location(),
428 MessageTemplate::kAwaitBindingIdentifier);
429 *ok = false;
430 return Statement::Default();
431 }
432 ParseFunctionLiteral(name, scanner()->location(),
433 is_strict_reserved ? kFunctionNameIsStrictReserved
434 : kFunctionNameValidityUnknown,
435 FunctionKind::kAsyncFunction, pos,
436 FunctionLiteral::kDeclaration, language_mode(),
437 CHECK_OK);
438 return Statement::FunctionDeclaration();
439 }
400 440
401 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) { 441 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) {
402 Expect(Token::CLASS, CHECK_OK); 442 Expect(Token::CLASS, CHECK_OK);
403 443
404 int pos = position(); 444 int pos = position();
405 bool is_strict_reserved = false; 445 bool is_strict_reserved = false;
406 Identifier name = 446 Identifier name =
407 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 447 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
408 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, 448 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos,
409 CHECK_OK); 449 CHECK_OK);
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 allow_duplicate_parameters, CHECK_OK); 1049 allow_duplicate_parameters, CHECK_OK);
1010 1050
1011 if (is_strict(language_mode)) { 1051 if (is_strict(language_mode)) {
1012 int end_position = scanner()->location().end_pos; 1052 int end_position = scanner()->location().end_pos;
1013 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); 1053 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK);
1014 } 1054 }
1015 1055
1016 return Expression::Default(); 1056 return Expression::Default();
1017 } 1057 }
1018 1058
1059 PreParser::Expression PreParser::ParseAsyncFunctionExpression(bool* ok) {
1060 // AsyncFunctionDeclaration ::
1061 // async [no LineTerminator here] function ( FormalParameters[Await] )
1062 // { AsyncFunctionBody }
1063 //
1064 // async [no LineTerminator here] function BindingIdentifier[Await]
1065 // ( FormalParameters[Await] ) { AsyncFunctionBody }
1066 int pos = position();
1067 Expect(Token::FUNCTION, CHECK_OK);
1068 bool is_strict_reserved = false;
1069 Identifier name;
1070 FunctionLiteral::FunctionType type = FunctionLiteral::kAnonymousExpression;
1071
1072 if (peek_any_identifier()) {
1073 type = FunctionLiteral::kNamedExpression;
1074 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
1075 if (this->IsAwait(name)) {
1076 ReportMessageAt(scanner()->location(),
1077 MessageTemplate::kAwaitBindingIdentifier);
1078 *ok = false;
1079 return Expression::Default();
1080 }
1081 }
1082
1083 ParseFunctionLiteral(name, scanner()->location(),
1084 is_strict_reserved ? kFunctionNameIsStrictReserved
1085 : kFunctionNameValidityUnknown,
1086 FunctionKind::kAsyncFunction, pos, type, language_mode(),
1087 CHECK_OK);
1088 return Expression::Default();
1089 }
1019 1090
1020 void PreParser::ParseLazyFunctionLiteralBody(bool* ok, 1091 void PreParser::ParseLazyFunctionLiteralBody(bool* ok,
1021 Scanner::BookmarkScope* bookmark) { 1092 Scanner::BookmarkScope* bookmark) {
1022 int body_start = position(); 1093 int body_start = position();
1023 ParseStatementList(Token::RBRACE, ok, bookmark); 1094 ParseStatementList(Token::RBRACE, ok, bookmark);
1024 if (!*ok) return; 1095 if (!*ok) return;
1025 if (bookmark && bookmark->HasBeenReset()) return; 1096 if (bookmark && bookmark->HasBeenReset()) return;
1026 1097
1027 // Position right after terminal '}'. 1098 // Position right after terminal '}'.
1028 DCHECK_EQ(Token::RBRACE, scanner()->peek()); 1099 DCHECK_EQ(Token::RBRACE, scanner()->peek());
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 Expect(Token::RBRACE, CHECK_OK); 1195 Expect(Token::RBRACE, CHECK_OK);
1125 return PreParserExpression::Default(); 1196 return PreParserExpression::Default();
1126 } 1197 }
1127 } 1198 }
1128 1199
1129 #undef CHECK_OK 1200 #undef CHECK_OK
1130 1201
1131 1202
1132 } // namespace internal 1203 } // namespace internal
1133 } // namespace v8 1204 } // namespace v8
OLDNEW
« src/parsing/parser.cc ('K') | « src/parsing/preparser.h ('k') | src/parsing/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698