| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 return PreParserIdentifier::Await(); | 44 return PreParserIdentifier::Await(); |
| 45 } else if (scanner->current_token() == | 45 } else if (scanner->current_token() == |
| 46 Token::FUTURE_STRICT_RESERVED_WORD) { | 46 Token::FUTURE_STRICT_RESERVED_WORD) { |
| 47 return PreParserIdentifier::FutureStrictReserved(); | 47 return PreParserIdentifier::FutureStrictReserved(); |
| 48 } else if (scanner->current_token() == Token::LET) { | 48 } else if (scanner->current_token() == Token::LET) { |
| 49 return PreParserIdentifier::Let(); | 49 return PreParserIdentifier::Let(); |
| 50 } else if (scanner->current_token() == Token::STATIC) { | 50 } else if (scanner->current_token() == Token::STATIC) { |
| 51 return PreParserIdentifier::Static(); | 51 return PreParserIdentifier::Static(); |
| 52 } else if (scanner->current_token() == Token::YIELD) { | 52 } else if (scanner->current_token() == Token::YIELD) { |
| 53 return PreParserIdentifier::Yield(); | 53 return PreParserIdentifier::Yield(); |
| 54 } else if (scanner->current_token() == Token::ASYNC) { |
| 55 return PreParserIdentifier::Async(); |
| 54 } | 56 } |
| 55 if (scanner->UnescapedLiteralMatches("eval", 4)) { | 57 if (scanner->UnescapedLiteralMatches("eval", 4)) { |
| 56 return PreParserIdentifier::Eval(); | 58 return PreParserIdentifier::Eval(); |
| 57 } | 59 } |
| 58 if (scanner->UnescapedLiteralMatches("arguments", 9)) { | 60 if (scanner->UnescapedLiteralMatches("arguments", 9)) { |
| 59 return PreParserIdentifier::Arguments(); | 61 return PreParserIdentifier::Arguments(); |
| 60 } | 62 } |
| 61 if (scanner->UnescapedLiteralMatches("undefined", 9)) { | 63 if (scanner->UnescapedLiteralMatches("undefined", 9)) { |
| 62 return PreParserIdentifier::Undefined(); | 64 return PreParserIdentifier::Undefined(); |
| 63 } | 65 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 return ParseHoistableDeclaration(ok); | 188 return ParseHoistableDeclaration(ok); |
| 187 case Token::CLASS: | 189 case Token::CLASS: |
| 188 return ParseClassDeclaration(ok); | 190 return ParseClassDeclaration(ok); |
| 189 case Token::CONST: | 191 case Token::CONST: |
| 190 return ParseVariableStatement(kStatementListItem, ok); | 192 return ParseVariableStatement(kStatementListItem, ok); |
| 191 case Token::LET: | 193 case Token::LET: |
| 192 if (IsNextLetKeyword()) { | 194 if (IsNextLetKeyword()) { |
| 193 return ParseVariableStatement(kStatementListItem, ok); | 195 return ParseVariableStatement(kStatementListItem, ok); |
| 194 } | 196 } |
| 195 break; | 197 break; |
| 198 case Token::ASYNC: |
| 199 if (allow_harmony_async_await() && PeekAhead() == Token::FUNCTION && |
| 200 !scanner()->HasAnyLineTerminatorAfterNext()) { |
| 201 Consume(Token::ASYNC); |
| 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::ASYNC); |
| 414 int pos = position(); |
| 415 Expect(Token::FUNCTION, CHECK_OK); |
| 416 bool is_strict_reserved = false; |
| 417 Identifier name = |
| 418 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
| 419 if (V8_UNLIKELY(is_async_function() && this->IsAwait(name))) { |
| 420 ReportMessageAt(scanner()->location(), |
| 421 MessageTemplate::kAwaitBindingIdentifier); |
| 422 *ok = false; |
| 423 return Statement::Default(); |
| 424 } |
| 425 ParseFunctionLiteral(name, scanner()->location(), |
| 426 is_strict_reserved ? kFunctionNameIsStrictReserved |
| 427 : kFunctionNameValidityUnknown, |
| 428 FunctionKind::kAsyncFunction, pos, |
| 429 FunctionLiteral::kDeclaration, language_mode(), |
| 430 CHECK_OK); |
| 431 return Statement::FunctionDeclaration(); |
| 432 } |
| 400 | 433 |
| 401 PreParser::Statement PreParser::ParseHoistableDeclaration(bool* ok) { | 434 PreParser::Statement PreParser::ParseHoistableDeclaration(bool* ok) { |
| 402 // FunctionDeclaration :: | 435 // FunctionDeclaration :: |
| 403 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' | 436 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' |
| 404 // GeneratorDeclaration :: | 437 // GeneratorDeclaration :: |
| 405 // 'function' '*' Identifier '(' FormalParameterListopt ')' | 438 // 'function' '*' Identifier '(' FormalParameterListopt ')' |
| 406 // '{' FunctionBody '}' | 439 // '{' FunctionBody '}' |
| 407 Expect(Token::FUNCTION, CHECK_OK); | 440 Expect(Token::FUNCTION, CHECK_OK); |
| 408 int pos = position(); | 441 int pos = position(); |
| 409 bool is_generator = Check(Token::MUL); | 442 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); | 1137 allow_duplicate_parameters, CHECK_OK); |
| 1105 | 1138 |
| 1106 if (is_strict(language_mode)) { | 1139 if (is_strict(language_mode)) { |
| 1107 int end_position = scanner()->location().end_pos; | 1140 int end_position = scanner()->location().end_pos; |
| 1108 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); | 1141 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); |
| 1109 } | 1142 } |
| 1110 | 1143 |
| 1111 return Expression::Default(); | 1144 return Expression::Default(); |
| 1112 } | 1145 } |
| 1113 | 1146 |
| 1147 PreParser::Expression PreParser::ParseAsyncFunctionExpression(bool* ok) { |
| 1148 // AsyncFunctionDeclaration :: |
| 1149 // async [no LineTerminator here] function ( FormalParameters[Await] ) |
| 1150 // { AsyncFunctionBody } |
| 1151 // |
| 1152 // async [no LineTerminator here] function BindingIdentifier[Await] |
| 1153 // ( FormalParameters[Await] ) { AsyncFunctionBody } |
| 1154 int pos = position(); |
| 1155 Expect(Token::FUNCTION, CHECK_OK); |
| 1156 bool is_strict_reserved = false; |
| 1157 Identifier name; |
| 1158 FunctionLiteral::FunctionType type = FunctionLiteral::kAnonymousExpression; |
| 1159 |
| 1160 if (peek_any_identifier()) { |
| 1161 type = FunctionLiteral::kNamedExpression; |
| 1162 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
| 1163 if (this->IsAwait(name)) { |
| 1164 ReportMessageAt(scanner()->location(), |
| 1165 MessageTemplate::kAwaitBindingIdentifier); |
| 1166 *ok = false; |
| 1167 return Expression::Default(); |
| 1168 } |
| 1169 } |
| 1170 |
| 1171 ParseFunctionLiteral(name, scanner()->location(), |
| 1172 is_strict_reserved ? kFunctionNameIsStrictReserved |
| 1173 : kFunctionNameValidityUnknown, |
| 1174 FunctionKind::kAsyncFunction, pos, type, language_mode(), |
| 1175 CHECK_OK); |
| 1176 return Expression::Default(); |
| 1177 } |
| 1114 | 1178 |
| 1115 void PreParser::ParseLazyFunctionLiteralBody(bool* ok, | 1179 void PreParser::ParseLazyFunctionLiteralBody(bool* ok, |
| 1116 Scanner::BookmarkScope* bookmark) { | 1180 Scanner::BookmarkScope* bookmark) { |
| 1117 int body_start = position(); | 1181 int body_start = position(); |
| 1118 ParseStatementList(Token::RBRACE, ok, bookmark); | 1182 ParseStatementList(Token::RBRACE, ok, bookmark); |
| 1119 if (!*ok) return; | 1183 if (!*ok) return; |
| 1120 if (bookmark && bookmark->HasBeenReset()) return; | 1184 if (bookmark && bookmark->HasBeenReset()) return; |
| 1121 | 1185 |
| 1122 // Position right after terminal '}'. | 1186 // Position right after terminal '}'. |
| 1123 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 1187 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 } | 1229 } |
| 1166 } | 1230 } |
| 1167 | 1231 |
| 1168 ClassLiteralChecker checker(this); | 1232 ClassLiteralChecker checker(this); |
| 1169 bool has_seen_constructor = false; | 1233 bool has_seen_constructor = false; |
| 1170 | 1234 |
| 1171 Expect(Token::LBRACE, CHECK_OK); | 1235 Expect(Token::LBRACE, CHECK_OK); |
| 1172 while (peek() != Token::RBRACE) { | 1236 while (peek() != Token::RBRACE) { |
| 1173 if (Check(Token::SEMICOLON)) continue; | 1237 if (Check(Token::SEMICOLON)) continue; |
| 1174 const bool in_class = true; | 1238 const bool in_class = true; |
| 1175 const bool is_static = false; | |
| 1176 bool is_computed_name = false; // Classes do not care about computed | 1239 bool is_computed_name = false; // Classes do not care about computed |
| 1177 // property names here. | 1240 // property names here. |
| 1178 Identifier name; | 1241 Identifier name; |
| 1179 ExpressionClassifier property_classifier(this); | 1242 ExpressionClassifier property_classifier(this); |
| 1180 ParsePropertyDefinition(&checker, in_class, has_extends, is_static, | 1243 ParsePropertyDefinition(&checker, in_class, has_extends, MethodKind::Normal, |
| 1181 &is_computed_name, &has_seen_constructor, | 1244 &is_computed_name, &has_seen_constructor, |
| 1182 &property_classifier, &name, CHECK_OK); | 1245 &property_classifier, &name, CHECK_OK); |
| 1183 ValidateExpression(&property_classifier, CHECK_OK); | 1246 ValidateExpression(&property_classifier, CHECK_OK); |
| 1184 if (classifier != nullptr) { | 1247 if (classifier != nullptr) { |
| 1185 classifier->Accumulate(&property_classifier, | 1248 classifier->Accumulate(&property_classifier, |
| 1186 ExpressionClassifier::ExpressionProductions); | 1249 ExpressionClassifier::ExpressionProductions); |
| 1187 } | 1250 } |
| 1188 } | 1251 } |
| 1189 | 1252 |
| 1190 Expect(Token::RBRACE, CHECK_OK); | 1253 Expect(Token::RBRACE, CHECK_OK); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 } | 1287 } |
| 1225 Expect(Token::RBRACE, CHECK_OK); | 1288 Expect(Token::RBRACE, CHECK_OK); |
| 1226 return PreParserExpression::Default(); | 1289 return PreParserExpression::Default(); |
| 1227 } | 1290 } |
| 1228 | 1291 |
| 1229 #undef CHECK_OK | 1292 #undef CHECK_OK |
| 1230 | 1293 |
| 1231 | 1294 |
| 1232 } // namespace internal | 1295 } // namespace internal |
| 1233 } // namespace v8 | 1296 } // namespace v8 |
| OLD | NEW |