| 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 27 matching lines...) Expand all Loading... |
| 38 #define CHECK_OK_CUSTOM(x) ok); \ | 38 #define CHECK_OK_CUSTOM(x) ok); \ |
| 39 if (!*ok) return this->x(); \ | 39 if (!*ok) return this->x(); \ |
| 40 ((void)0 | 40 ((void)0 |
| 41 #define DUMMY ) // to make indentation work | 41 #define DUMMY ) // to make indentation work |
| 42 #undef DUMMY | 42 #undef DUMMY |
| 43 | 43 |
| 44 void PreParserTraits::ReportMessageAt(Scanner::Location location, | 44 void PreParserTraits::ReportMessageAt(Scanner::Location location, |
| 45 MessageTemplate::Template message, | 45 MessageTemplate::Template message, |
| 46 const char* arg, | 46 const char* arg, |
| 47 ParseErrorType error_type) { | 47 ParseErrorType error_type) { |
| 48 ReportMessageAt(location.beg_pos, location.end_pos, message, arg, error_type); | 48 pre_parser_->log_->LogMessage(location.beg_pos, location.end_pos, message, |
| 49 arg, error_type); |
| 50 } |
| 51 |
| 52 void PreParserTraits::ReportMessageAt(Scanner::Location location, |
| 53 MessageTemplate::Template message, |
| 54 const AstRawString* arg, |
| 55 ParseErrorType error_type) { |
| 56 UNREACHABLE(); |
| 49 } | 57 } |
| 50 | 58 |
| 51 | 59 |
| 52 void PreParserTraits::ReportMessageAt(int start_pos, int end_pos, | |
| 53 MessageTemplate::Template message, | |
| 54 const char* arg, | |
| 55 ParseErrorType error_type) { | |
| 56 pre_parser_->log_->LogMessage(start_pos, end_pos, message, arg, error_type); | |
| 57 } | |
| 58 | |
| 59 | |
| 60 PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) { | 60 PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) { |
| 61 if (scanner->current_token() == Token::ENUM) { | 61 if (scanner->current_token() == Token::ENUM) { |
| 62 return PreParserIdentifier::Enum(); | 62 return PreParserIdentifier::Enum(); |
| 63 } else if (scanner->current_token() == Token::AWAIT) { | 63 } else if (scanner->current_token() == Token::AWAIT) { |
| 64 return PreParserIdentifier::Await(); | 64 return PreParserIdentifier::Await(); |
| 65 } else if (scanner->current_token() == | 65 } else if (scanner->current_token() == |
| 66 Token::FUTURE_STRICT_RESERVED_WORD) { | 66 Token::FUTURE_STRICT_RESERVED_WORD) { |
| 67 return PreParserIdentifier::FutureStrictReserved(); | 67 return PreParserIdentifier::FutureStrictReserved(); |
| 68 } else if (scanner->current_token() == Token::LET) { | 68 } else if (scanner->current_token() == Token::LET) { |
| 69 return PreParserIdentifier::Let(); | 69 return PreParserIdentifier::Let(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 86 if (scanner->LiteralMatches("prototype", 9)) { | 86 if (scanner->LiteralMatches("prototype", 9)) { |
| 87 return PreParserIdentifier::Prototype(); | 87 return PreParserIdentifier::Prototype(); |
| 88 } | 88 } |
| 89 if (scanner->LiteralMatches("constructor", 11)) { | 89 if (scanner->LiteralMatches("constructor", 11)) { |
| 90 return PreParserIdentifier::Constructor(); | 90 return PreParserIdentifier::Constructor(); |
| 91 } | 91 } |
| 92 return PreParserIdentifier::Default(); | 92 return PreParserIdentifier::Default(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 | 95 |
| 96 PreParserIdentifier PreParserTraits::GetNumberAsSymbol(Scanner* scanner) { | |
| 97 return PreParserIdentifier::Default(); | |
| 98 } | |
| 99 | |
| 100 | |
| 101 PreParserExpression PreParserTraits::ExpressionFromString( | 96 PreParserExpression PreParserTraits::ExpressionFromString( |
| 102 int pos, Scanner* scanner, PreParserFactory* factory) { | 97 int pos, Scanner* scanner, PreParserFactory* factory) { |
| 103 if (scanner->UnescapedLiteralMatches("use strict", 10)) { | 98 if (scanner->UnescapedLiteralMatches("use strict", 10)) { |
| 104 return PreParserExpression::UseStrictStringLiteral(); | 99 return PreParserExpression::UseStrictStringLiteral(); |
| 105 } | 100 } |
| 106 return PreParserExpression::StringLiteral(); | 101 return PreParserExpression::StringLiteral(); |
| 107 } | 102 } |
| 108 | 103 |
| 109 | 104 |
| 110 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { | 105 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 scope()->SetLanguageMode( | 250 scope()->SetLanguageMode( |
| 256 static_cast<LanguageMode>(scope()->language_mode() | STRICT)); | 251 static_cast<LanguageMode>(scope()->language_mode() | STRICT)); |
| 257 } else if (!statement.IsStringLiteral()) { | 252 } else if (!statement.IsStringLiteral()) { |
| 258 directive_prologue = false; | 253 directive_prologue = false; |
| 259 } | 254 } |
| 260 | 255 |
| 261 if (use_strict_found && !scope()->HasSimpleParameters()) { | 256 if (use_strict_found && !scope()->HasSimpleParameters()) { |
| 262 // TC39 deemed "use strict" directives to be an error when occurring | 257 // TC39 deemed "use strict" directives to be an error when occurring |
| 263 // in the body of a function with non-simple parameter list, on | 258 // in the body of a function with non-simple parameter list, on |
| 264 // 29/7/2015. https://goo.gl/ueA7Ln | 259 // 29/7/2015. https://goo.gl/ueA7Ln |
| 265 PreParserTraits::ReportMessageAt( | 260 ReportMessageAt(token_loc, |
| 266 token_loc, MessageTemplate::kIllegalLanguageModeDirective, | 261 MessageTemplate::kIllegalLanguageModeDirective, |
| 267 "use strict"); | 262 "use strict"); |
| 268 *ok = false; | 263 *ok = false; |
| 269 return; | 264 return; |
| 270 } | 265 } |
| 271 } | 266 } |
| 272 | 267 |
| 273 // If we're allowed to reset to a bookmark, we will do so when we see a long | 268 // If we're allowed to reset to a bookmark, we will do so when we see a long |
| 274 // and trivial function. | 269 // and trivial function. |
| 275 // Our current definition of 'long and trivial' is: | 270 // Our current definition of 'long and trivial' is: |
| 276 // - over 200 statements | 271 // - over 200 statements |
| 277 // - all starting with an identifier (i.e., no if, for, while, etc.) | 272 // - all starting with an identifier (i.e., no if, for, while, etc.) |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 ParseAssignmentExpression(var_context != kForStatement, &classifier, | 577 ParseAssignmentExpression(var_context != kForStatement, &classifier, |
| 583 CHECK_OK); | 578 CHECK_OK); |
| 584 ValidateExpression(&classifier, CHECK_OK); | 579 ValidateExpression(&classifier, CHECK_OK); |
| 585 | 580 |
| 586 variable_loc.end_pos = scanner()->location().end_pos; | 581 variable_loc.end_pos = scanner()->location().end_pos; |
| 587 if (first_initializer_loc && !first_initializer_loc->IsValid()) { | 582 if (first_initializer_loc && !first_initializer_loc->IsValid()) { |
| 588 *first_initializer_loc = variable_loc; | 583 *first_initializer_loc = variable_loc; |
| 589 } | 584 } |
| 590 } else if ((require_initializer || is_pattern) && | 585 } else if ((require_initializer || is_pattern) && |
| 591 (var_context != kForStatement || !PeekInOrOf())) { | 586 (var_context != kForStatement || !PeekInOrOf())) { |
| 592 PreParserTraits::ReportMessageAt( | 587 ReportMessageAt( |
| 593 Scanner::Location(decl_pos, scanner()->location().end_pos), | 588 Scanner::Location(decl_pos, scanner()->location().end_pos), |
| 594 MessageTemplate::kDeclarationMissingInitializer, | 589 MessageTemplate::kDeclarationMissingInitializer, |
| 595 is_pattern ? "destructuring" : "const"); | 590 is_pattern ? "destructuring" : "const"); |
| 596 *ok = false; | 591 *ok = false; |
| 597 return Statement::Default(); | 592 return Statement::Default(); |
| 598 } | 593 } |
| 599 } while (peek() == Token::COMMA); | 594 } while (peek() == Token::COMMA); |
| 600 | 595 |
| 601 if (bindings_loc) { | 596 if (bindings_loc) { |
| 602 *bindings_loc = | 597 *bindings_loc = |
| 603 Scanner::Location(bindings_start, scanner()->location().end_pos); | 598 Scanner::Location(bindings_start, scanner()->location().end_pos); |
| 604 } | 599 } |
| 605 | 600 |
| 606 if (num_decl != nullptr) *num_decl = nvars; | 601 if (num_decl != nullptr) *num_decl = nvars; |
| 607 if (is_lexical != nullptr) *is_lexical = lexical; | 602 if (is_lexical != nullptr) *is_lexical = lexical; |
| 608 if (is_binding_pattern != nullptr) *is_binding_pattern = is_pattern; | 603 if (is_binding_pattern != nullptr) *is_binding_pattern = is_pattern; |
| 609 return Statement::Default(); | 604 return Statement::Default(); |
| 610 } | 605 } |
| 611 | 606 |
| 612 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { | 607 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { |
| 613 Consume(Token::FUNCTION); | 608 Consume(Token::FUNCTION); |
| 614 int pos = position(); | 609 int pos = position(); |
| 615 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; | 610 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; |
| 616 if (Check(Token::MUL)) { | 611 if (Check(Token::MUL)) { |
| 617 flags |= ParseFunctionFlags::kIsGenerator; | 612 flags |= ParseFunctionFlags::kIsGenerator; |
| 618 if (allow_harmony_restrictive_declarations()) { | 613 if (allow_harmony_restrictive_declarations()) { |
| 619 PreParserTraits::ReportMessageAt( | 614 ReportMessageAt(scanner()->location(), |
| 620 scanner()->location(), MessageTemplate::kGeneratorInLegacyContext); | 615 MessageTemplate::kGeneratorInLegacyContext); |
| 621 *ok = false; | 616 *ok = false; |
| 622 return Statement::Default(); | 617 return Statement::Default(); |
| 623 } | 618 } |
| 624 } | 619 } |
| 625 return ParseHoistableDeclaration(pos, flags, ok); | 620 return ParseHoistableDeclaration(pos, flags, ok); |
| 626 } | 621 } |
| 627 | 622 |
| 628 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement( | 623 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement( |
| 629 AllowLabelledFunctionStatement allow_function, bool* ok) { | 624 AllowLabelledFunctionStatement allow_function, bool* ok) { |
| 630 // ExpressionStatement | LabelledStatement :: | 625 // ExpressionStatement | LabelledStatement :: |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 bool is_binding_pattern; | 872 bool is_binding_pattern; |
| 878 Scanner::Location first_initializer_loc = Scanner::Location::invalid(); | 873 Scanner::Location first_initializer_loc = Scanner::Location::invalid(); |
| 879 Scanner::Location bindings_loc = Scanner::Location::invalid(); | 874 Scanner::Location bindings_loc = Scanner::Location::invalid(); |
| 880 ParseVariableDeclarations(kForStatement, &decl_count, &is_lexical, | 875 ParseVariableDeclarations(kForStatement, &decl_count, &is_lexical, |
| 881 &is_binding_pattern, &first_initializer_loc, | 876 &is_binding_pattern, &first_initializer_loc, |
| 882 &bindings_loc, CHECK_OK); | 877 &bindings_loc, CHECK_OK); |
| 883 if (is_lexical) has_lexical = true; | 878 if (is_lexical) has_lexical = true; |
| 884 if (CheckInOrOf(&mode, ok)) { | 879 if (CheckInOrOf(&mode, ok)) { |
| 885 if (!*ok) return Statement::Default(); | 880 if (!*ok) return Statement::Default(); |
| 886 if (decl_count != 1) { | 881 if (decl_count != 1) { |
| 887 PreParserTraits::ReportMessageAt( | 882 ReportMessageAt(bindings_loc, |
| 888 bindings_loc, MessageTemplate::kForInOfLoopMultiBindings, | 883 MessageTemplate::kForInOfLoopMultiBindings, |
| 889 ForEachStatement::VisitModeString(mode)); | 884 ForEachStatement::VisitModeString(mode)); |
| 890 *ok = false; | 885 *ok = false; |
| 891 return Statement::Default(); | 886 return Statement::Default(); |
| 892 } | 887 } |
| 893 if (first_initializer_loc.IsValid() && | 888 if (first_initializer_loc.IsValid() && |
| 894 (is_strict(language_mode()) || mode == ForEachStatement::ITERATE || | 889 (is_strict(language_mode()) || mode == ForEachStatement::ITERATE || |
| 895 is_lexical || is_binding_pattern || allow_harmony_for_in())) { | 890 is_lexical || is_binding_pattern || allow_harmony_for_in())) { |
| 896 // Only increment the use count if we would have let this through | 891 // Only increment the use count if we would have let this through |
| 897 // without the flag. | 892 // without the flag. |
| 898 if (use_counts_ != nullptr && allow_harmony_for_in()) { | 893 if (use_counts_ != nullptr && allow_harmony_for_in()) { |
| 899 ++use_counts_[v8::Isolate::kForInInitializer]; | 894 ++use_counts_[v8::Isolate::kForInInitializer]; |
| 900 } | 895 } |
| 901 PreParserTraits::ReportMessageAt( | 896 ReportMessageAt(first_initializer_loc, |
| 902 first_initializer_loc, MessageTemplate::kForInOfLoopInitializer, | 897 MessageTemplate::kForInOfLoopInitializer, |
| 903 ForEachStatement::VisitModeString(mode)); | 898 ForEachStatement::VisitModeString(mode)); |
| 904 *ok = false; | 899 *ok = false; |
| 905 return Statement::Default(); | 900 return Statement::Default(); |
| 906 } | 901 } |
| 907 | 902 |
| 908 if (mode == ForEachStatement::ITERATE) { | 903 if (mode == ForEachStatement::ITERATE) { |
| 909 ExpressionClassifier classifier(this); | 904 ExpressionClassifier classifier(this); |
| 910 ParseAssignmentExpression(true, &classifier, CHECK_OK); | 905 ParseAssignmentExpression(true, &classifier, CHECK_OK); |
| 911 RewriteNonPattern(&classifier, CHECK_OK); | 906 RewriteNonPattern(&classifier, CHECK_OK); |
| 912 } else { | 907 } else { |
| 913 ParseExpression(true, CHECK_OK); | 908 ParseExpression(true, CHECK_OK); |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 | 1306 |
| 1312 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); | 1307 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); |
| 1313 } | 1308 } |
| 1314 | 1309 |
| 1315 #undef CHECK_OK | 1310 #undef CHECK_OK |
| 1316 #undef CHECK_OK_CUSTOM | 1311 #undef CHECK_OK_CUSTOM |
| 1317 | 1312 |
| 1318 | 1313 |
| 1319 } // namespace internal | 1314 } // namespace internal |
| 1320 } // namespace v8 | 1315 } // namespace v8 |
| OLD | NEW |