| OLD | NEW |
| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 return ParseHoistableDeclaration(ok); | 186 return ParseHoistableDeclaration(ok); |
| 187 case Token::CLASS: | 187 case Token::CLASS: |
| 188 return ParseClassDeclaration(ok); | 188 return ParseClassDeclaration(ok); |
| 189 case Token::CONST: | 189 case Token::CONST: |
| 190 return ParseVariableStatement(kStatementListItem, ok); | 190 return ParseVariableStatement(kStatementListItem, ok); |
| 191 case Token::LET: | 191 case Token::LET: |
| 192 if (IsNextLetKeyword()) { | 192 if (IsNextLetKeyword()) { |
| 193 return ParseVariableStatement(kStatementListItem, ok); | 193 return ParseVariableStatement(kStatementListItem, ok); |
| 194 } | 194 } |
| 195 break; | 195 break; |
| 196 case Token::IDENTIFIER: |
| 197 if (allow_harmony_async_await() && |
| 198 PeekContextualKeyword(CStrVector("async")) && |
| 199 PeekAhead() == Token::FUNCTION && |
| 200 !scanner()->HasAnyLineTerminatorAfterNext()) { |
| 201 Consume(Token::IDENTIFIER); |
| 202 return ParseAsyncFunctionDeclaration(ok); |
| 203 } |
| 204 /* falls through */ |
| 196 default: | 205 default: |
| 197 break; | 206 break; |
| 198 } | 207 } |
| 199 return ParseStatement(kAllowLabelledFunctionStatement, ok); | 208 return ParseStatement(kAllowLabelledFunctionStatement, ok); |
| 200 } | 209 } |
| 201 | 210 |
| 202 | 211 |
| 203 void PreParser::ParseStatementList(int end_token, bool* ok, | 212 void PreParser::ParseStatementList(int end_token, bool* ok, |
| 204 Scanner::BookmarkScope* bookmark) { | 213 Scanner::BookmarkScope* bookmark) { |
| 205 // SourceElements :: | 214 // SourceElements :: |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 ParseFunctionLiteral(name, scanner()->location(), | 399 ParseFunctionLiteral(name, scanner()->location(), |
| 391 is_strict_reserved ? kFunctionNameIsStrictReserved | 400 is_strict_reserved ? kFunctionNameIsStrictReserved |
| 392 : kFunctionNameValidityUnknown, | 401 : kFunctionNameValidityUnknown, |
| 393 is_generator ? FunctionKind::kGeneratorFunction | 402 is_generator ? FunctionKind::kGeneratorFunction |
| 394 : FunctionKind::kNormalFunction, | 403 : FunctionKind::kNormalFunction, |
| 395 pos, FunctionLiteral::kDeclaration, language_mode(), | 404 pos, FunctionLiteral::kDeclaration, language_mode(), |
| 396 CHECK_OK); | 405 CHECK_OK); |
| 397 return Statement::FunctionDeclaration(); | 406 return Statement::FunctionDeclaration(); |
| 398 } | 407 } |
| 399 | 408 |
| 409 PreParser::Statement PreParser::ParseAsyncFunctionDeclaration(bool* ok) { |
| 410 // AsyncFunctionDeclaration :: |
| 411 // async [no LineTerminator here] function BindingIdentifier[Await] |
| 412 // ( FormalParameters[Await] ) { AsyncFunctionBody } |
| 413 DCHECK_EQ(scanner()->current_token(), Token::IDENTIFIER); |
| 414 DCHECK(scanner()->is_literal_contextual_keyword(CStrVector("async"))); |
| 415 int pos = position(); |
| 416 Expect(Token::FUNCTION, CHECK_OK); |
| 417 bool is_strict_reserved = false; |
| 418 Identifier name = |
| 419 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
| 420 if (V8_UNLIKELY(is_async_function() && this->IsAwait(name))) { |
| 421 ReportMessageAt(scanner()->location(), |
| 422 MessageTemplate::kAwaitBindingIdentifier); |
| 423 *ok = false; |
| 424 return Statement::Default(); |
| 425 } |
| 426 ParseFunctionLiteral(name, scanner()->location(), |
| 427 is_strict_reserved ? kFunctionNameIsStrictReserved |
| 428 : kFunctionNameValidityUnknown, |
| 429 FunctionKind::kAsyncFunction, pos, |
| 430 FunctionLiteral::kDeclaration, language_mode(), |
| 431 CHECK_OK); |
| 432 return Statement::FunctionDeclaration(); |
| 433 } |
| 400 | 434 |
| 401 PreParser::Statement PreParser::ParseHoistableDeclaration(bool* ok) { | 435 PreParser::Statement PreParser::ParseHoistableDeclaration(bool* ok) { |
| 402 // FunctionDeclaration :: | 436 // FunctionDeclaration :: |
| 403 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' | 437 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' |
| 404 // GeneratorDeclaration :: | 438 // GeneratorDeclaration :: |
| 405 // 'function' '*' Identifier '(' FormalParameterListopt ')' | 439 // 'function' '*' Identifier '(' FormalParameterListopt ')' |
| 406 // '{' FunctionBody '}' | 440 // '{' FunctionBody '}' |
| 407 Expect(Token::FUNCTION, CHECK_OK); | 441 Expect(Token::FUNCTION, CHECK_OK); |
| 408 int pos = position(); | 442 int pos = position(); |
| 409 bool is_generator = Check(Token::MUL); | 443 bool is_generator = Check(Token::MUL); |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 allow_duplicate_parameters, CHECK_OK); | 1138 allow_duplicate_parameters, CHECK_OK); |
| 1105 | 1139 |
| 1106 if (is_strict(language_mode)) { | 1140 if (is_strict(language_mode)) { |
| 1107 int end_position = scanner()->location().end_pos; | 1141 int end_position = scanner()->location().end_pos; |
| 1108 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); | 1142 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); |
| 1109 } | 1143 } |
| 1110 | 1144 |
| 1111 return Expression::Default(); | 1145 return Expression::Default(); |
| 1112 } | 1146 } |
| 1113 | 1147 |
| 1148 PreParser::Expression PreParser::ParseAsyncFunctionExpression(bool* ok) { |
| 1149 // AsyncFunctionDeclaration :: |
| 1150 // async [no LineTerminator here] function ( FormalParameters[Await] ) |
| 1151 // { AsyncFunctionBody } |
| 1152 // |
| 1153 // async [no LineTerminator here] function BindingIdentifier[Await] |
| 1154 // ( FormalParameters[Await] ) { AsyncFunctionBody } |
| 1155 int pos = position(); |
| 1156 Expect(Token::FUNCTION, CHECK_OK); |
| 1157 bool is_strict_reserved = false; |
| 1158 Identifier name; |
| 1159 FunctionLiteral::FunctionType type = FunctionLiteral::kAnonymousExpression; |
| 1160 |
| 1161 if (peek_any_identifier()) { |
| 1162 type = FunctionLiteral::kNamedExpression; |
| 1163 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
| 1164 if (this->IsAwait(name)) { |
| 1165 ReportMessageAt(scanner()->location(), |
| 1166 MessageTemplate::kAwaitBindingIdentifier); |
| 1167 *ok = false; |
| 1168 return Expression::Default(); |
| 1169 } |
| 1170 } |
| 1171 |
| 1172 ParseFunctionLiteral(name, scanner()->location(), |
| 1173 is_strict_reserved ? kFunctionNameIsStrictReserved |
| 1174 : kFunctionNameValidityUnknown, |
| 1175 FunctionKind::kAsyncFunction, pos, type, language_mode(), |
| 1176 CHECK_OK); |
| 1177 return Expression::Default(); |
| 1178 } |
| 1114 | 1179 |
| 1115 void PreParser::ParseLazyFunctionLiteralBody(bool* ok, | 1180 void PreParser::ParseLazyFunctionLiteralBody(bool* ok, |
| 1116 Scanner::BookmarkScope* bookmark) { | 1181 Scanner::BookmarkScope* bookmark) { |
| 1117 int body_start = position(); | 1182 int body_start = position(); |
| 1118 ParseStatementList(Token::RBRACE, ok, bookmark); | 1183 ParseStatementList(Token::RBRACE, ok, bookmark); |
| 1119 if (!*ok) return; | 1184 if (!*ok) return; |
| 1120 if (bookmark && bookmark->HasBeenReset()) return; | 1185 if (bookmark && bookmark->HasBeenReset()) return; |
| 1121 | 1186 |
| 1122 // Position right after terminal '}'. | 1187 // Position right after terminal '}'. |
| 1123 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 1188 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 } | 1230 } |
| 1166 } | 1231 } |
| 1167 | 1232 |
| 1168 ClassLiteralChecker checker(this); | 1233 ClassLiteralChecker checker(this); |
| 1169 bool has_seen_constructor = false; | 1234 bool has_seen_constructor = false; |
| 1170 | 1235 |
| 1171 Expect(Token::LBRACE, CHECK_OK); | 1236 Expect(Token::LBRACE, CHECK_OK); |
| 1172 while (peek() != Token::RBRACE) { | 1237 while (peek() != Token::RBRACE) { |
| 1173 if (Check(Token::SEMICOLON)) continue; | 1238 if (Check(Token::SEMICOLON)) continue; |
| 1174 const bool in_class = true; | 1239 const bool in_class = true; |
| 1175 const bool is_static = false; | |
| 1176 bool is_computed_name = false; // Classes do not care about computed | 1240 bool is_computed_name = false; // Classes do not care about computed |
| 1177 // property names here. | 1241 // property names here. |
| 1178 Identifier name; | 1242 Identifier name; |
| 1179 ExpressionClassifier property_classifier(this); | 1243 ExpressionClassifier property_classifier(this); |
| 1180 ParsePropertyDefinition(&checker, in_class, has_extends, is_static, | 1244 ParsePropertyDefinition(&checker, in_class, has_extends, MethodKind::None, |
| 1181 &is_computed_name, &has_seen_constructor, | 1245 &is_computed_name, &has_seen_constructor, |
| 1182 &property_classifier, &name, CHECK_OK); | 1246 &property_classifier, &name, CHECK_OK); |
| 1183 ValidateExpression(&property_classifier, CHECK_OK); | 1247 ValidateExpression(&property_classifier, CHECK_OK); |
| 1184 if (classifier != nullptr) { | 1248 if (classifier != nullptr) { |
| 1185 classifier->Accumulate(&property_classifier, | 1249 classifier->Accumulate(&property_classifier, |
| 1186 ExpressionClassifier::ExpressionProductions); | 1250 ExpressionClassifier::ExpressionProductions); |
| 1187 } | 1251 } |
| 1188 } | 1252 } |
| 1189 | 1253 |
| 1190 Expect(Token::RBRACE, CHECK_OK); | 1254 Expect(Token::RBRACE, CHECK_OK); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 } | 1288 } |
| 1225 Expect(Token::RBRACE, CHECK_OK); | 1289 Expect(Token::RBRACE, CHECK_OK); |
| 1226 return PreParserExpression::Default(); | 1290 return PreParserExpression::Default(); |
| 1227 } | 1291 } |
| 1228 | 1292 |
| 1229 #undef CHECK_OK | 1293 #undef CHECK_OK |
| 1230 | 1294 |
| 1231 | 1295 |
| 1232 } // namespace internal | 1296 } // namespace internal |
| 1233 } // namespace v8 | 1297 } // namespace v8 |
| OLD | NEW |