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