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

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: 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 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 if (scanner->UnescapedLiteralMatches("undefined", 9)) { 61 if (scanner->UnescapedLiteralMatches("undefined", 9)) {
62 return PreParserIdentifier::Undefined(); 62 return PreParserIdentifier::Undefined();
63 } 63 }
64 if (scanner->LiteralMatches("prototype", 9)) { 64 if (scanner->LiteralMatches("prototype", 9)) {
65 return PreParserIdentifier::Prototype(); 65 return PreParserIdentifier::Prototype();
66 } 66 }
67 if (scanner->LiteralMatches("constructor", 11)) { 67 if (scanner->LiteralMatches("constructor", 11)) {
68 return PreParserIdentifier::Constructor(); 68 return PreParserIdentifier::Constructor();
69 } 69 }
70 if (scanner->LiteralMatches("async", 5)) {
71 return PreParserIdentifier::Async();
72 }
Dan Ehrenberg 2016/05/06 00:08:56 My hunch is that the parser and preparser would wo
caitp (gmail) 2016/05/06 00:31:03 Im not entirely sure this change is really needed
73 if (scanner->LiteralMatches("await", 5)) {
74 return PreParserIdentifier::Await();
75 }
Dan Ehrenberg 2016/05/06 00:08:56 This looks like dead code. I think this case is ha
caitp (gmail) 2016/05/06 00:31:03 yes, its no longer needed since Mikes CL, will del
70 return PreParserIdentifier::Default(); 76 return PreParserIdentifier::Default();
71 } 77 }
72 78
73 79
74 PreParserIdentifier PreParserTraits::GetNumberAsSymbol(Scanner* scanner) { 80 PreParserIdentifier PreParserTraits::GetNumberAsSymbol(Scanner* scanner) {
75 return PreParserIdentifier::Default(); 81 return PreParserIdentifier::Default();
76 } 82 }
77 83
78 84
79 PreParserExpression PreParserTraits::ExpressionFromString( 85 PreParserExpression PreParserTraits::ExpressionFromString(
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 return ParseHoistableDeclaration(ok); 192 return ParseHoistableDeclaration(ok);
187 case Token::CLASS: 193 case Token::CLASS:
188 return ParseClassDeclaration(ok); 194 return ParseClassDeclaration(ok);
189 case Token::CONST: 195 case Token::CONST:
190 return ParseVariableStatement(kStatementListItem, ok); 196 return ParseVariableStatement(kStatementListItem, ok);
191 case Token::LET: 197 case Token::LET:
192 if (IsNextLetKeyword()) { 198 if (IsNextLetKeyword()) {
193 return ParseVariableStatement(kStatementListItem, ok); 199 return ParseVariableStatement(kStatementListItem, ok);
194 } 200 }
195 break; 201 break;
202 case Token::IDENTIFIER:
203 if (allow_harmony_async_await() &&
204 PeekContextualKeyword(CStrVector("async")) &&
205 PeekAhead() == Token::FUNCTION &&
206 !scanner()->HasAnyLineTerminatorAfterNext()) {
207 Consume(Token::IDENTIFIER);
208 return ParseAsyncFunctionDeclaration(ok);
209 }
210 /* falls through */
196 default: 211 default:
197 break; 212 break;
198 } 213 }
199 return ParseStatement(kAllowLabelledFunctionStatement, ok); 214 return ParseStatement(kAllowLabelledFunctionStatement, ok);
200 } 215 }
201 216
202 217
203 void PreParser::ParseStatementList(int end_token, bool* ok, 218 void PreParser::ParseStatementList(int end_token, bool* ok,
204 Scanner::BookmarkScope* bookmark) { 219 Scanner::BookmarkScope* bookmark) {
205 // SourceElements :: 220 // SourceElements ::
(...skipping 184 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::ParseHoistableDeclaration(bool* ok) { 441 PreParser::Statement PreParser::ParseHoistableDeclaration(bool* ok) {
402 // FunctionDeclaration :: 442 // FunctionDeclaration ::
403 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' 443 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
404 // GeneratorDeclaration :: 444 // GeneratorDeclaration ::
405 // 'function' '*' Identifier '(' FormalParameterListopt ')' 445 // 'function' '*' Identifier '(' FormalParameterListopt ')'
406 // '{' FunctionBody '}' 446 // '{' FunctionBody '}'
407 Expect(Token::FUNCTION, CHECK_OK); 447 Expect(Token::FUNCTION, CHECK_OK);
408 int pos = position(); 448 int pos = position();
409 bool is_generator = Check(Token::MUL); 449 bool is_generator = Check(Token::MUL);
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 allow_duplicate_parameters, CHECK_OK); 1144 allow_duplicate_parameters, CHECK_OK);
1105 1145
1106 if (is_strict(language_mode)) { 1146 if (is_strict(language_mode)) {
1107 int end_position = scanner()->location().end_pos; 1147 int end_position = scanner()->location().end_pos;
1108 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); 1148 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK);
1109 } 1149 }
1110 1150
1111 return Expression::Default(); 1151 return Expression::Default();
1112 } 1152 }
1113 1153
1154 PreParser::Expression PreParser::ParseAsyncFunctionExpression(bool* ok) {
1155 // AsyncFunctionDeclaration ::
1156 // async [no LineTerminator here] function ( FormalParameters[Await] )
1157 // { AsyncFunctionBody }
1158 //
1159 // async [no LineTerminator here] function BindingIdentifier[Await]
1160 // ( FormalParameters[Await] ) { AsyncFunctionBody }
1161 int pos = position();
1162 Expect(Token::FUNCTION, CHECK_OK);
1163 bool is_strict_reserved = false;
1164 Identifier name;
1165 FunctionLiteral::FunctionType type = FunctionLiteral::kAnonymousExpression;
1166
1167 if (peek_any_identifier()) {
1168 type = FunctionLiteral::kNamedExpression;
1169 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
1170 if (this->IsAwait(name)) {
1171 ReportMessageAt(scanner()->location(),
1172 MessageTemplate::kAwaitBindingIdentifier);
1173 *ok = false;
1174 return Expression::Default();
1175 }
1176 }
1177
1178 ParseFunctionLiteral(name, scanner()->location(),
1179 is_strict_reserved ? kFunctionNameIsStrictReserved
1180 : kFunctionNameValidityUnknown,
1181 FunctionKind::kAsyncFunction, pos, type, language_mode(),
1182 CHECK_OK);
1183 return Expression::Default();
1184 }
1114 1185
1115 void PreParser::ParseLazyFunctionLiteralBody(bool* ok, 1186 void PreParser::ParseLazyFunctionLiteralBody(bool* ok,
1116 Scanner::BookmarkScope* bookmark) { 1187 Scanner::BookmarkScope* bookmark) {
1117 int body_start = position(); 1188 int body_start = position();
1118 ParseStatementList(Token::RBRACE, ok, bookmark); 1189 ParseStatementList(Token::RBRACE, ok, bookmark);
1119 if (!*ok) return; 1190 if (!*ok) return;
1120 if (bookmark && bookmark->HasBeenReset()) return; 1191 if (bookmark && bookmark->HasBeenReset()) return;
1121 1192
1122 // Position right after terminal '}'. 1193 // Position right after terminal '}'.
1123 DCHECK_EQ(Token::RBRACE, scanner()->peek()); 1194 DCHECK_EQ(Token::RBRACE, scanner()->peek());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 } 1295 }
1225 Expect(Token::RBRACE, CHECK_OK); 1296 Expect(Token::RBRACE, CHECK_OK);
1226 return PreParserExpression::Default(); 1297 return PreParserExpression::Default();
1227 } 1298 }
1228 1299
1229 #undef CHECK_OK 1300 #undef CHECK_OK
1230 1301
1231 1302
1232 } // namespace internal 1303 } // namespace internal
1233 } // namespace v8 1304 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698