| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // | 171 // |
| 172 // HoistableDeclaration[Yield, Default] : | 172 // HoistableDeclaration[Yield, Default] : |
| 173 // FunctionDeclaration[?Yield, ?Default] | 173 // FunctionDeclaration[?Yield, ?Default] |
| 174 // GeneratorDeclaration[?Yield, ?Default] | 174 // GeneratorDeclaration[?Yield, ?Default] |
| 175 // | 175 // |
| 176 // LexicalDeclaration[In, Yield] : | 176 // LexicalDeclaration[In, Yield] : |
| 177 // LetOrConst BindingList[?In, ?Yield] ; | 177 // LetOrConst BindingList[?In, ?Yield] ; |
| 178 | 178 |
| 179 switch (peek()) { | 179 switch (peek()) { |
| 180 case Token::FUNCTION: | 180 case Token::FUNCTION: |
| 181 return ParseFunctionDeclaration(ok); | 181 return ParseHoistableDeclaration(ok); |
| 182 case Token::CLASS: | 182 case Token::CLASS: |
| 183 return ParseClassDeclaration(ok); | 183 return ParseClassDeclaration(ok); |
| 184 case Token::CONST: | 184 case Token::CONST: |
| 185 return ParseVariableStatement(kStatementListItem, ok); | 185 return ParseVariableStatement(kStatementListItem, ok); |
| 186 case Token::LET: | 186 case Token::LET: |
| 187 if (IsNextLetKeyword()) { | 187 if (IsNextLetKeyword()) { |
| 188 return ParseVariableStatement(kStatementListItem, ok); | 188 return ParseVariableStatement(kStatementListItem, ok); |
| 189 } | 189 } |
| 190 break; | 190 break; |
| 191 default: | 191 default: |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 return Statement::Default(); | 271 return Statement::Default(); |
| 272 } | 272 } |
| 273 return ParseSubStatement(allow_function, ok); | 273 return ParseSubStatement(allow_function, ok); |
| 274 } | 274 } |
| 275 | 275 |
| 276 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { | 276 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { |
| 277 if (is_strict(language_mode()) || peek() != Token::FUNCTION || | 277 if (is_strict(language_mode()) || peek() != Token::FUNCTION || |
| 278 (legacy && allow_harmony_restrictive_declarations())) { | 278 (legacy && allow_harmony_restrictive_declarations())) { |
| 279 return ParseSubStatement(kDisallowLabelledFunctionStatement, ok); | 279 return ParseSubStatement(kDisallowLabelledFunctionStatement, ok); |
| 280 } else { | 280 } else { |
| 281 return ParseFunctionDeclaration(CHECK_OK); | 281 return ParseFunctionDeclaration(ok); |
| 282 } | 282 } |
| 283 } | 283 } |
| 284 | 284 |
| 285 PreParser::Statement PreParser::ParseSubStatement( | 285 PreParser::Statement PreParser::ParseSubStatement( |
| 286 AllowLabelledFunctionStatement allow_function, bool* ok) { | 286 AllowLabelledFunctionStatement allow_function, bool* ok) { |
| 287 // Statement :: | 287 // Statement :: |
| 288 // Block | 288 // Block |
| 289 // VariableStatement | 289 // VariableStatement |
| 290 // EmptyStatement | 290 // EmptyStatement |
| 291 // ExpressionStatement | 291 // ExpressionStatement |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 | 368 |
| 369 case Token::VAR: | 369 case Token::VAR: |
| 370 return ParseVariableStatement(kStatement, ok); | 370 return ParseVariableStatement(kStatement, ok); |
| 371 | 371 |
| 372 default: | 372 default: |
| 373 return ParseExpressionOrLabelledStatement(allow_function, ok); | 373 return ParseExpressionOrLabelledStatement(allow_function, ok); |
| 374 } | 374 } |
| 375 } | 375 } |
| 376 | 376 |
| 377 | 377 |
| 378 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { | 378 PreParser::Statement PreParser::ParseHoistableDeclaration( |
| 379 // FunctionDeclaration :: | 379 int pos, bool is_generator, bool* ok) { |
| 380 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' | |
| 381 // GeneratorDeclaration :: | |
| 382 // 'function' '*' Identifier '(' FormalParameterListopt ')' | |
| 383 // '{' FunctionBody '}' | |
| 384 Expect(Token::FUNCTION, CHECK_OK); | |
| 385 int pos = position(); | |
| 386 bool is_generator = Check(Token::MUL); | |
| 387 bool is_strict_reserved = false; | 380 bool is_strict_reserved = false; |
| 388 Identifier name = ParseIdentifierOrStrictReservedWord( | 381 Identifier name = ParseIdentifierOrStrictReservedWord( |
| 389 &is_strict_reserved, CHECK_OK); | 382 &is_strict_reserved, CHECK_OK); |
| 390 ParseFunctionLiteral(name, scanner()->location(), | 383 ParseFunctionLiteral(name, scanner()->location(), |
| 391 is_strict_reserved ? kFunctionNameIsStrictReserved | 384 is_strict_reserved ? kFunctionNameIsStrictReserved |
| 392 : kFunctionNameValidityUnknown, | 385 : kFunctionNameValidityUnknown, |
| 393 is_generator ? FunctionKind::kGeneratorFunction | 386 is_generator ? FunctionKind::kGeneratorFunction |
| 394 : FunctionKind::kNormalFunction, | 387 : FunctionKind::kNormalFunction, |
| 395 pos, FunctionLiteral::kDeclaration, language_mode(), | 388 pos, FunctionLiteral::kDeclaration, language_mode(), |
| 396 CHECK_OK); | 389 CHECK_OK); |
| 397 return Statement::FunctionDeclaration(); | 390 return Statement::FunctionDeclaration(); |
| 398 } | 391 } |
| 399 | 392 |
| 400 | 393 |
| 394 PreParser::Statement PreParser::ParseHoistableDeclaration(bool* ok) { |
| 395 // FunctionDeclaration :: |
| 396 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' |
| 397 // GeneratorDeclaration :: |
| 398 // 'function' '*' Identifier '(' FormalParameterListopt ')' |
| 399 // '{' FunctionBody '}' |
| 400 Expect(Token::FUNCTION, CHECK_OK); |
| 401 int pos = position(); |
| 402 bool is_generator = Check(Token::MUL); |
| 403 return ParseHoistableDeclaration(pos, is_generator, CHECK_OK); |
| 404 } |
| 405 |
| 406 |
| 401 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) { | 407 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) { |
| 402 Expect(Token::CLASS, CHECK_OK); | 408 Expect(Token::CLASS, CHECK_OK); |
| 403 | 409 |
| 404 int pos = position(); | 410 int pos = position(); |
| 405 bool is_strict_reserved = false; | 411 bool is_strict_reserved = false; |
| 406 Identifier name = | 412 Identifier name = |
| 407 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 413 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
| 408 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, | 414 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, |
| 409 CHECK_OK); | 415 CHECK_OK); |
| 410 return Statement::Default(); | 416 return Statement::Default(); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 *bindings_loc = | 545 *bindings_loc = |
| 540 Scanner::Location(bindings_start, scanner()->location().end_pos); | 546 Scanner::Location(bindings_start, scanner()->location().end_pos); |
| 541 } | 547 } |
| 542 | 548 |
| 543 if (num_decl != nullptr) *num_decl = nvars; | 549 if (num_decl != nullptr) *num_decl = nvars; |
| 544 if (is_lexical != nullptr) *is_lexical = lexical; | 550 if (is_lexical != nullptr) *is_lexical = lexical; |
| 545 if (is_binding_pattern != nullptr) *is_binding_pattern = is_pattern; | 551 if (is_binding_pattern != nullptr) *is_binding_pattern = is_pattern; |
| 546 return Statement::Default(); | 552 return Statement::Default(); |
| 547 } | 553 } |
| 548 | 554 |
| 555 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { |
| 556 Consume(Token::FUNCTION); |
| 557 int pos = position(); |
| 558 bool is_generator = Check(Token::MUL); |
| 559 if (allow_harmony_restrictive_declarations() && is_generator) { |
| 560 PreParserTraits::ReportMessageAt( |
| 561 scanner()->location(), |
| 562 MessageTemplate::kGeneratorInLegacyContext); |
| 563 *ok = false; |
| 564 return Statement::Default(); |
| 565 } |
| 566 return ParseHoistableDeclaration(pos, is_generator, ok); |
| 567 } |
| 568 |
| 549 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement( | 569 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement( |
| 550 AllowLabelledFunctionStatement allow_function, bool* ok) { | 570 AllowLabelledFunctionStatement allow_function, bool* ok) { |
| 551 // ExpressionStatement | LabelledStatement :: | 571 // ExpressionStatement | LabelledStatement :: |
| 552 // Expression ';' | 572 // Expression ';' |
| 553 // Identifier ':' Statement | 573 // Identifier ':' Statement |
| 554 | 574 |
| 555 switch (peek()) { | 575 switch (peek()) { |
| 556 case Token::FUNCTION: | 576 case Token::FUNCTION: |
| 557 case Token::LBRACE: | 577 case Token::LBRACE: |
| 558 UNREACHABLE(); // Always handled by the callers. | 578 UNREACHABLE(); // Always handled by the callers. |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 Expect(Token::RBRACE, CHECK_OK); | 1143 Expect(Token::RBRACE, CHECK_OK); |
| 1124 return PreParserExpression::Default(); | 1144 return PreParserExpression::Default(); |
| 1125 } | 1145 } |
| 1126 } | 1146 } |
| 1127 | 1147 |
| 1128 #undef CHECK_OK | 1148 #undef CHECK_OK |
| 1129 | 1149 |
| 1130 | 1150 |
| 1131 } // namespace internal | 1151 } // namespace internal |
| 1132 } // namespace v8 | 1152 } // namespace v8 |
| OLD | NEW |