Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: src/preparser.h

Issue 1138153003: Use ExpressionClassifier to identify valid arrow function formals (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Classify destructuring bindings as invalid unless destructuring is enabled Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parser.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #ifndef V8_PREPARSER_H 5 #ifndef V8_PREPARSER_H
6 #define V8_PREPARSER_H 6 #define V8_PREPARSER_H
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 16 matching lines...) Expand all
27 FormalParameterErrorLocations() 27 FormalParameterErrorLocations()
28 : eval_or_arguments(Scanner::Location::invalid()), 28 : eval_or_arguments(Scanner::Location::invalid()),
29 undefined(Scanner::Location::invalid()), 29 undefined(Scanner::Location::invalid()),
30 duplicate(Scanner::Location::invalid()), 30 duplicate(Scanner::Location::invalid()),
31 reserved(Scanner::Location::invalid()) {} 31 reserved(Scanner::Location::invalid()) {}
32 32
33 Scanner::Location eval_or_arguments; 33 Scanner::Location eval_or_arguments;
34 Scanner::Location undefined; 34 Scanner::Location undefined;
35 Scanner::Location duplicate; 35 Scanner::Location duplicate;
36 Scanner::Location reserved; 36 Scanner::Location reserved;
37
38 void Accumulate(const FormalParameterErrorLocations& inner) {
39 if (!eval_or_arguments.IsValid()) {
40 eval_or_arguments = inner.eval_or_arguments;
41 }
42 if (!undefined.IsValid()) undefined = inner.undefined;
43 if (!duplicate.IsValid()) duplicate = inner.duplicate;
44 if (!reserved.IsValid()) reserved = inner.reserved;
45 }
37 }; 46 };
38 47
39 48
40 // Common base class shared between parser and pre-parser. Traits encapsulate 49 // Common base class shared between parser and pre-parser. Traits encapsulate
41 // the differences between Parser and PreParser: 50 // the differences between Parser and PreParser:
42 51
43 // - Return types: For example, Parser functions return Expression* and 52 // - Return types: For example, Parser functions return Expression* and
44 // PreParser functions return PreParserExpression. 53 // PreParser functions return PreParserExpression.
45 54
46 // - Creating parse tree nodes: Parser generates an AST during the recursive 55 // - Creating parse tree nodes: Parser generates an AST during the recursive
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 message(nullptr), 605 message(nullptr),
597 arg(nullptr) {} 606 arg(nullptr) {}
598 607
599 Scanner::Location location; 608 Scanner::Location location;
600 const char* message; 609 const char* message;
601 const char* arg; 610 const char* arg;
602 611
603 bool HasError() const { return location.IsValid(); } 612 bool HasError() const { return location.IsValid(); }
604 }; 613 };
605 614
606 ExpressionClassifier() {} 615 ExpressionClassifier() : formal_parameter_error_locs_(nullptr) {}
616 explicit ExpressionClassifier(FormalParameterErrorLocations* error_locs)
617 : formal_parameter_error_locs_(error_locs) {}
607 618
608 bool is_valid_expression() const { return !expression_error_.HasError(); } 619 bool is_valid_expression() const { return !expression_error_.HasError(); }
609 620
610 bool is_valid_binding_pattern() const { 621 bool is_valid_binding_pattern() const {
611 return !binding_pattern_error_.HasError(); 622 return !binding_pattern_error_.HasError();
612 } 623 }
613 624
614 bool is_valid_assignment_pattern() const { 625 bool is_valid_assignment_pattern() const {
615 return !assignment_pattern_error_.HasError(); 626 return !assignment_pattern_error_.HasError();
616 } 627 }
617 628
629 bool is_valid_arrow_formal_parameters() const {
630 return !arrow_formal_parameters_error_.HasError();
631 }
632
618 const Error& expression_error() const { return expression_error_; } 633 const Error& expression_error() const { return expression_error_; }
619 634
620 const Error& binding_pattern_error() const { 635 const Error& binding_pattern_error() const {
621 return binding_pattern_error_; 636 return binding_pattern_error_;
622 } 637 }
623 638
624 const Error& assignment_pattern_error() const { 639 const Error& assignment_pattern_error() const {
625 return assignment_pattern_error_; 640 return assignment_pattern_error_;
626 } 641 }
627 642
643 const Error& arrow_formal_parameters_error() const {
644 return arrow_formal_parameters_error_;
645 }
646
647 FormalParameterErrorLocations* formal_parameter_error_locs() const {
648 return formal_parameter_error_locs_;
649 }
650
628 void RecordExpressionError(const Scanner::Location& loc, 651 void RecordExpressionError(const Scanner::Location& loc,
629 const char* message, const char* arg = nullptr) { 652 const char* message, const char* arg = nullptr) {
630 if (!is_valid_expression()) return; 653 if (!is_valid_expression()) return;
631 expression_error_.location = loc; 654 expression_error_.location = loc;
632 expression_error_.message = message; 655 expression_error_.message = message;
633 expression_error_.arg = arg; 656 expression_error_.arg = arg;
634 } 657 }
635 658
636 void RecordBindingPatternError(const Scanner::Location& loc, 659 void RecordBindingPatternError(const Scanner::Location& loc,
637 const char* message, 660 const char* message,
638 const char* arg = nullptr) { 661 const char* arg = nullptr) {
639 if (!is_valid_binding_pattern()) return; 662 if (!is_valid_binding_pattern()) return;
640 binding_pattern_error_.location = loc; 663 binding_pattern_error_.location = loc;
641 binding_pattern_error_.message = message; 664 binding_pattern_error_.message = message;
642 binding_pattern_error_.arg = arg; 665 binding_pattern_error_.arg = arg;
643 } 666 }
644 667
645 void RecordAssignmentPatternError(const Scanner::Location& loc, 668 void RecordAssignmentPatternError(const Scanner::Location& loc,
646 const char* message, 669 const char* message,
647 const char* arg = nullptr) { 670 const char* arg = nullptr) {
648 if (!is_valid_assignment_pattern()) return; 671 if (!is_valid_assignment_pattern()) return;
649 assignment_pattern_error_.location = loc; 672 assignment_pattern_error_.location = loc;
650 assignment_pattern_error_.message = message; 673 assignment_pattern_error_.message = message;
651 assignment_pattern_error_.arg = arg; 674 assignment_pattern_error_.arg = arg;
652 } 675 }
653 676
677 void RecordArrowFormalParametersError(const Scanner::Location& loc,
Dmitry Lomov (no reviews) 2015/05/12 15:12:20 Instead of having all these methods, I suggest mer
678 const char* message,
679 const char* arg = nullptr) {
680 if (!is_valid_arrow_formal_parameters()) return;
681 arrow_formal_parameters_error_.location = loc;
682 arrow_formal_parameters_error_.message = message;
683 arrow_formal_parameters_error_.arg = arg;
684 }
685
686 void RecordEvalOrArguments(const Scanner::Location& loc) {
687 if (!formal_parameter_error_locs_) return;
688 if (!formal_parameter_error_locs_->eval_or_arguments.IsValid()) {
689 formal_parameter_error_locs_->eval_or_arguments = loc;
690 }
691 }
692
693 void RecordUndefined(const Scanner::Location& loc) {
694 if (!formal_parameter_error_locs_) return;
695 if (!formal_parameter_error_locs_->undefined.IsValid()) {
696 formal_parameter_error_locs_->undefined = loc;
697 }
698 }
699
700 void RecordDuplicate(const Scanner::Location& loc) {
701 if (!formal_parameter_error_locs_) return;
702 if (!formal_parameter_error_locs_->duplicate.IsValid()) {
703 formal_parameter_error_locs_->duplicate = loc;
704 }
705 }
706
707 void RecordFutureStrictReserved(const Scanner::Location& loc) {
708 if (!formal_parameter_error_locs_) return;
709 if (!formal_parameter_error_locs_->reserved.IsValid()) {
710 formal_parameter_error_locs_->reserved = loc;
711 }
712 }
713
714 enum TargetProduction {
715 ExpressionProduction = 1 << 0,
716 BindingPatternProduction = 1 << 1,
717 AssignmentPatternProduction = 1 << 2,
718 ArrowFormalParametersProduction = 1 << 3,
719 StandardProductions = (ExpressionProduction | BindingPatternProduction |
720 AssignmentPatternProduction),
721 AllProductions = StandardProductions | ArrowFormalParametersProduction
722 };
723
724 void Accumulate(const ExpressionClassifier& inner,
725 unsigned productions = StandardProductions) {
726 if (productions & ExpressionProduction && is_valid_expression()) {
727 expression_error_ = inner.expression_error_;
728 }
729 if (productions & BindingPatternProduction &&
730 is_valid_binding_pattern()) {
731 binding_pattern_error_ = inner.binding_pattern_error_;
732 }
733 if (productions & AssignmentPatternProduction &&
734 is_valid_assignment_pattern()) {
735 assignment_pattern_error_ = inner.assignment_pattern_error_;
736 }
737 if (productions & ArrowFormalParametersProduction &&
738 is_valid_arrow_formal_parameters()) {
739 // The result continues to be a valid arrow formal parameters if the
740 // inner expression is a valid binding pattern.
741 arrow_formal_parameters_error_ = inner.binding_pattern_error_;
742 }
743 }
744
654 private: 745 private:
655 Error expression_error_; 746 Error expression_error_;
656 Error binding_pattern_error_; 747 Error binding_pattern_error_;
657 Error assignment_pattern_error_; 748 Error assignment_pattern_error_;
749 Error arrow_formal_parameters_error_;
750 FormalParameterErrorLocations* formal_parameter_error_locs_;
658 }; 751 };
659 752
660 void ReportClassifierError( 753 void ReportClassifierError(
661 const typename ExpressionClassifier::Error& error) { 754 const typename ExpressionClassifier::Error& error) {
662 Traits::ReportMessageAt(error.location, error.message, error.arg, 755 Traits::ReportMessageAt(error.location, error.message, error.arg,
663 kSyntaxError); 756 kSyntaxError);
664 } 757 }
665 758
666 void ValidateExpression(const ExpressionClassifier* classifier, bool* ok) { 759 void ValidateExpression(const ExpressionClassifier* classifier, bool* ok) {
667 if (!classifier->is_valid_expression()) { 760 if (!classifier->is_valid_expression()) {
(...skipping 11 matching lines...) Expand all
679 } 772 }
680 773
681 void ValidateAssignmentPattern(const ExpressionClassifier* classifier, 774 void ValidateAssignmentPattern(const ExpressionClassifier* classifier,
682 bool* ok) { 775 bool* ok) {
683 if (!classifier->is_valid_assignment_pattern()) { 776 if (!classifier->is_valid_assignment_pattern()) {
684 ReportClassifierError(classifier->assignment_pattern_error()); 777 ReportClassifierError(classifier->assignment_pattern_error());
685 *ok = false; 778 *ok = false;
686 } 779 }
687 } 780 }
688 781
782 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier,
783 ExpressionT expr, bool* ok) {
784 if (classifier->is_valid_binding_pattern()) {
785 // A simple arrow formal parameter: IDENTIFIER => BODY.
786 if (!this->IsIdentifier(expr)) {
787 Traits::ReportMessageAt(scanner()->location(), "unexpected_token",
788 Token::String(scanner()->current_token()));
789 *ok = false;
790 }
791 } else if (!classifier->is_valid_arrow_formal_parameters()) {
792 ReportClassifierError(classifier->arrow_formal_parameters_error());
793 *ok = false;
794 }
795 }
796
689 void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) { 797 void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) {
690 classifier->RecordBindingPatternError( 798 classifier->RecordBindingPatternError(
691 scanner()->location(), "unexpected_token", Token::String(peek())); 799 scanner()->peek_location(), "unexpected_token", Token::String(peek()));
800 }
801
802 void ArrowFormalParametersUnexpectedToken(ExpressionClassifier* classifier) {
803 classifier->RecordArrowFormalParametersError(
804 scanner()->peek_location(), "unexpected_token", Token::String(peek()));
692 } 805 }
693 806
694 // Recursive descent functions: 807 // Recursive descent functions:
695 808
696 // Parses an identifier that is valid for the current scope, in particular it 809 // Parses an identifier that is valid for the current scope, in particular it
697 // fails on strict mode future reserved keywords in a strict scope. If 810 // fails on strict mode future reserved keywords in a strict scope. If
698 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or 811 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or
699 // "arguments" as identifier even in strict mode (this is needed in cases like 812 // "arguments" as identifier even in strict mode (this is needed in cases like
700 // "var foo = eval;"). 813 // "var foo = eval;").
701 IdentifierT ParseIdentifier(AllowRestrictedIdentifiers, bool* ok); 814 IdentifierT ParseIdentifier(AllowRestrictedIdentifiers, bool* ok);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 bool* ok); 858 bool* ok);
746 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, 859 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier,
747 bool* ok); 860 bool* ok);
748 ExpressionT ParseMemberWithNewPrefixesExpression( 861 ExpressionT ParseMemberWithNewPrefixesExpression(
749 ExpressionClassifier* classifier, bool* ok); 862 ExpressionClassifier* classifier, bool* ok);
750 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, bool* ok); 863 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, bool* ok);
751 ExpressionT ParseMemberExpressionContinuation( 864 ExpressionT ParseMemberExpressionContinuation(
752 ExpressionT expression, ExpressionClassifier* classifier, bool* ok); 865 ExpressionT expression, ExpressionClassifier* classifier, bool* ok);
753 ExpressionT ParseArrowFunctionLiteral( 866 ExpressionT ParseArrowFunctionLiteral(
754 Scope* function_scope, const FormalParameterErrorLocations& error_locs, 867 Scope* function_scope, const FormalParameterErrorLocations& error_locs,
755 bool has_rest, ExpressionClassifier* classifier, bool* ok); 868 bool has_rest, bool* ok);
756 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, 869 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start,
757 ExpressionClassifier* classifier, bool* ok); 870 ExpressionClassifier* classifier, bool* ok);
758 void AddTemplateExpression(ExpressionT); 871 void AddTemplateExpression(ExpressionT);
759 ExpressionT ParseSuperExpression(bool is_new, 872 ExpressionT ParseSuperExpression(bool is_new,
760 ExpressionClassifier* classifier, bool* ok); 873 ExpressionClassifier* classifier, bool* ok);
761 ExpressionT ParseStrongInitializationExpression( 874 ExpressionT ParseStrongInitializationExpression(
762 ExpressionClassifier* classifier, bool* ok); 875 ExpressionClassifier* classifier, bool* ok);
763 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, 876 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier,
764 bool* ok); 877 bool* ok);
765 878
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 } 1079 }
967 1080
968 static PreParserExpression FromIdentifier(PreParserIdentifier id) { 1081 static PreParserExpression FromIdentifier(PreParserIdentifier id) {
969 return PreParserExpression(TypeField::encode(kIdentifierExpression) | 1082 return PreParserExpression(TypeField::encode(kIdentifierExpression) |
970 IdentifierTypeField::encode(id.type_)); 1083 IdentifierTypeField::encode(id.type_));
971 } 1084 }
972 1085
973 static PreParserExpression BinaryOperation(PreParserExpression left, 1086 static PreParserExpression BinaryOperation(PreParserExpression left,
974 Token::Value op, 1087 Token::Value op,
975 PreParserExpression right) { 1088 PreParserExpression right) {
976 ValidArrowParam valid_arrow_param_list = 1089 return PreParserExpression(TypeField::encode(kBinaryOperationExpression));
977 (op == Token::COMMA && !left.is_single_parenthesized() &&
978 !right.is_single_parenthesized())
979 ? std::min(left.ValidateArrowParams(), right.ValidateArrowParams())
980 : kInvalidArrowParam;
981 return PreParserExpression(
982 TypeField::encode(kBinaryOperationExpression) |
983 IsValidArrowParamListField::encode(valid_arrow_param_list));
984 } 1090 }
985 1091
986 static PreParserExpression StringLiteral() { 1092 static PreParserExpression StringLiteral() {
987 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); 1093 return PreParserExpression(TypeField::encode(kStringLiteralExpression));
988 } 1094 }
989 1095
990 static PreParserExpression UseStrictStringLiteral() { 1096 static PreParserExpression UseStrictStringLiteral() {
991 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | 1097 return PreParserExpression(TypeField::encode(kStringLiteralExpression) |
992 IsUseStrictField::encode(true)); 1098 IsUseStrictField::encode(true));
993 } 1099 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 1172
1067 bool IsCall() const { 1173 bool IsCall() const {
1068 return TypeField::decode(code_) == kExpression && 1174 return TypeField::decode(code_) == kExpression &&
1069 ExpressionTypeField::decode(code_) == kCallExpression; 1175 ExpressionTypeField::decode(code_) == kCallExpression;
1070 } 1176 }
1071 1177
1072 bool IsValidReferenceExpression() const { 1178 bool IsValidReferenceExpression() const {
1073 return IsIdentifier() || IsProperty(); 1179 return IsIdentifier() || IsProperty();
1074 } 1180 }
1075 1181
1076 bool IsValidArrowParamList(FormalParameterErrorLocations* locs,
1077 const Scanner::Location& params_loc) const {
1078 ValidArrowParam valid = ValidateArrowParams();
1079 if (ParenthesizationField::decode(code_) == kMultiParenthesizedExpression) {
1080 return false;
1081 }
1082 switch (valid) {
1083 case kInvalidArrowParam:
1084 return false;
1085 case kInvalidStrongArrowParam:
1086 locs->undefined = params_loc;
1087 return true;
1088 case kInvalidStrictReservedArrowParam:
1089 locs->reserved = params_loc;
1090 return true;
1091 case kInvalidStrictEvalArgumentsArrowParam:
1092 locs->eval_or_arguments = params_loc;
1093 return true;
1094 default:
1095 DCHECK_EQ(valid, kValidArrowParam);
1096 return true;
1097 }
1098 }
1099
1100 // At the moment PreParser doesn't track these expression types. 1182 // At the moment PreParser doesn't track these expression types.
1101 bool IsFunctionLiteral() const { return false; } 1183 bool IsFunctionLiteral() const { return false; }
1102 bool IsCallNew() const { return false; } 1184 bool IsCallNew() const { return false; }
1103 1185
1104 bool IsNoTemplateTag() const { 1186 bool IsNoTemplateTag() const {
1105 return TypeField::decode(code_) == kExpression && 1187 return TypeField::decode(code_) == kExpression &&
1106 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression; 1188 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression;
1107 } 1189 }
1108 1190
1109 bool IsSpreadExpression() const { 1191 bool IsSpreadExpression() const {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 }; 1235 };
1154 1236
1155 enum ExpressionType { 1237 enum ExpressionType {
1156 kThisExpression, 1238 kThisExpression,
1157 kThisPropertyExpression, 1239 kThisPropertyExpression,
1158 kPropertyExpression, 1240 kPropertyExpression,
1159 kCallExpression, 1241 kCallExpression,
1160 kNoTemplateTagExpression 1242 kNoTemplateTagExpression
1161 }; 1243 };
1162 1244
1163 // These validity constraints are ordered such that a value of N implies lack
1164 // of errors M < N.
1165 enum ValidArrowParam {
1166 kInvalidArrowParam,
1167 kInvalidStrictEvalArgumentsArrowParam,
1168 kInvalidStrictReservedArrowParam,
1169 kInvalidStrongArrowParam,
1170 kValidArrowParam
1171 };
1172
1173 explicit PreParserExpression(uint32_t expression_code) 1245 explicit PreParserExpression(uint32_t expression_code)
1174 : code_(expression_code) {} 1246 : code_(expression_code) {}
1175 1247
1176 V8_INLINE ValidArrowParam ValidateArrowParams() const {
1177 if (IsBinaryOperation()) {
1178 return IsValidArrowParamListField::decode(code_);
1179 }
1180 if (!IsIdentifier()) {
1181 return kInvalidArrowParam;
1182 }
1183 PreParserIdentifier ident = AsIdentifier();
1184 // In strict mode, eval and arguments are not valid formal parameter names.
1185 if (ident.IsEval() || ident.IsArguments()) {
1186 return kInvalidStrictEvalArgumentsArrowParam;
1187 }
1188 // In strict mode, future reserved words are not valid either, and as they
1189 // produce different errors we allot them their own error code.
1190 if (ident.IsFutureStrictReserved()) {
1191 return kInvalidStrictReservedArrowParam;
1192 }
1193 // In strong mode, 'undefined' isn't a valid formal parameter name either.
1194 if (ident.IsUndefined()) {
1195 return kInvalidStrongArrowParam;
1196 }
1197 return kValidArrowParam;
1198 }
1199
1200 // The first five bits are for the Type and Parenthesization. 1248 // The first five bits are for the Type and Parenthesization.
1201 typedef BitField<Type, 0, 3> TypeField; 1249 typedef BitField<Type, 0, 3> TypeField;
1202 typedef BitField<Parenthesization, TypeField::kNext, 2> ParenthesizationField; 1250 typedef BitField<Parenthesization, TypeField::kNext, 2> ParenthesizationField;
1203 1251
1204 // The rest of the bits are interpreted depending on the value 1252 // The rest of the bits are interpreted depending on the value
1205 // of the Type field, so they can share the storage. 1253 // of the Type field, so they can share the storage.
1206 typedef BitField<ExpressionType, ParenthesizationField::kNext, 3> 1254 typedef BitField<ExpressionType, ParenthesizationField::kNext, 3>
1207 ExpressionTypeField; 1255 ExpressionTypeField;
1208 typedef BitField<bool, ParenthesizationField::kNext, 1> IsUseStrictField; 1256 typedef BitField<bool, ParenthesizationField::kNext, 1> IsUseStrictField;
1209 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; 1257 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField;
1210 typedef BitField<ValidArrowParam, ParenthesizationField::kNext, 3>
1211 IsValidArrowParamListField;
1212 typedef BitField<PreParserIdentifier::Type, ParenthesizationField::kNext, 10> 1258 typedef BitField<PreParserIdentifier::Type, ParenthesizationField::kNext, 10>
1213 IdentifierTypeField; 1259 IdentifierTypeField;
1214 1260
1215 uint32_t code_; 1261 uint32_t code_;
1216 }; 1262 };
1217 1263
1218 1264
1219 // The pre-parser doesn't need to build lists of expressions, identifiers, or 1265 // The pre-parser doesn't need to build lists of expressions, identifiers, or
1220 // the like. 1266 // the like.
1221 template <typename T> 1267 template <typename T>
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 return pre_parser_->scanner()->FindSymbol(duplicate_finder, 1) != 0; 1971 return pre_parser_->scanner()->FindSymbol(duplicate_finder, 1) != 0;
1926 } 1972 }
1927 1973
1928 1974
1929 void PreParserTraits::ParseArrowFunctionFormalParameters( 1975 void PreParserTraits::ParseArrowFunctionFormalParameters(
1930 Scope* scope, PreParserExpression params, 1976 Scope* scope, PreParserExpression params,
1931 const Scanner::Location& params_loc, 1977 const Scanner::Location& params_loc,
1932 FormalParameterErrorLocations* error_locs, bool* is_rest, bool* ok) { 1978 FormalParameterErrorLocations* error_locs, bool* is_rest, bool* ok) {
1933 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter 1979 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter
1934 // lists that are too long. 1980 // lists that are too long.
1935 if (!params.IsValidArrowParamList(error_locs, params_loc)) {
1936 *ok = false;
1937 ReportMessageAt(params_loc, "malformed_arrow_function_parameter_list");
1938 return;
1939 }
1940 } 1981 }
1941 1982
1942 1983
1943 PreParserStatementList PreParser::ParseEagerFunctionBody( 1984 PreParserStatementList PreParser::ParseEagerFunctionBody(
1944 PreParserIdentifier function_name, int pos, Variable* fvar, 1985 PreParserIdentifier function_name, int pos, Variable* fvar,
1945 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { 1986 Token::Value fvar_init_op, FunctionKind kind, bool* ok) {
1946 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 1987 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
1947 1988
1948 ParseStatementList(Token::RBRACE, ok); 1989 ParseStatementList(Token::RBRACE, ok);
1949 if (!*ok) return PreParserStatementList(); 1990 if (!*ok) return PreParserStatementList();
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 } 2095 }
2055 2096
2056 2097
2057 template <class Traits> 2098 template <class Traits>
2058 typename ParserBase<Traits>::IdentifierT 2099 typename ParserBase<Traits>::IdentifierT
2059 ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier, 2100 ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier,
2060 bool* ok) { 2101 bool* ok) {
2061 Token::Value next = Next(); 2102 Token::Value next = Next();
2062 if (next == Token::IDENTIFIER) { 2103 if (next == Token::IDENTIFIER) {
2063 IdentifierT name = this->GetSymbol(scanner()); 2104 IdentifierT name = this->GetSymbol(scanner());
2064 if (is_strict(language_mode()) && this->IsEvalOrArguments(name)) { 2105 if (this->IsEvalOrArguments(name)) {
2065 classifier->RecordBindingPatternError(scanner()->location(), 2106 classifier->RecordEvalOrArguments(scanner()->location());
2066 "strict_eval_arguments"); 2107 if (is_strict(language_mode())) {
2108 classifier->RecordBindingPatternError(scanner()->location(),
2109 "strict_eval_arguments");
2110 }
2067 } 2111 }
2068 if (is_strong(language_mode()) && this->IsUndefined(name)) { 2112 if (this->IsUndefined(name)) {
2069 // TODO(dslomov): allow 'undefined' in nested patterns. 2113 classifier->RecordUndefined(scanner()->location());
2070 classifier->RecordBindingPatternError(scanner()->location(), 2114 if (is_strong(language_mode())) {
2071 "strong_undefined"); 2115 // TODO(dslomov): allow 'undefined' in nested patterns.
2072 classifier->RecordAssignmentPatternError(scanner()->location(), 2116 classifier->RecordBindingPatternError(scanner()->location(),
2073 "strong_undefined"); 2117 "strong_undefined");
2118 classifier->RecordAssignmentPatternError(scanner()->location(),
2119 "strong_undefined");
2120 }
2074 } 2121 }
2075 if (is_strong(language_mode()) && this->IsArguments(name)) { 2122 if (is_strong(language_mode()) && this->IsArguments(name)) {
2076 classifier->RecordExpressionError(scanner()->location(), 2123 classifier->RecordExpressionError(scanner()->location(),
2077 "strong_arguments"); 2124 "strong_arguments");
2078 } 2125 }
2079 if (this->IsArguments(name)) scope_->RecordArgumentsUsage(); 2126 if (this->IsArguments(name)) scope_->RecordArgumentsUsage();
2080 return name; 2127 return name;
2081 } else if (is_sloppy(language_mode()) && 2128 } else if (is_sloppy(language_mode()) &&
2082 (next == Token::FUTURE_STRICT_RESERVED_WORD || 2129 (next == Token::FUTURE_STRICT_RESERVED_WORD ||
2083 next == Token::LET || next == Token::STATIC || 2130 next == Token::LET || next == Token::STATIC ||
2084 (next == Token::YIELD && !is_generator()))) { 2131 (next == Token::YIELD && !is_generator()))) {
2132 classifier->RecordFutureStrictReserved(scanner()->location());
2085 return this->GetSymbol(scanner()); 2133 return this->GetSymbol(scanner());
2086 } else { 2134 } else {
2087 this->ReportUnexpectedToken(next); 2135 this->ReportUnexpectedToken(next);
2088 *ok = false; 2136 *ok = false;
2089 return Traits::EmptyIdentifier(); 2137 return Traits::EmptyIdentifier();
2090 } 2138 }
2091 } 2139 }
2092 2140
2093 2141
2094 template <class Traits> 2142 template <class Traits>
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
2263 2311
2264 case Token::ASSIGN_DIV: 2312 case Token::ASSIGN_DIV:
2265 result = this->ParseRegExpLiteral(true, classifier, CHECK_OK); 2313 result = this->ParseRegExpLiteral(true, classifier, CHECK_OK);
2266 break; 2314 break;
2267 2315
2268 case Token::DIV: 2316 case Token::DIV:
2269 result = this->ParseRegExpLiteral(false, classifier, CHECK_OK); 2317 result = this->ParseRegExpLiteral(false, classifier, CHECK_OK);
2270 break; 2318 break;
2271 2319
2272 case Token::LBRACK: 2320 case Token::LBRACK:
2321 if (!allow_harmony_destructuring()) {
2322 BindingPatternUnexpectedToken(classifier);
2323 }
2273 result = this->ParseArrayLiteral(classifier, CHECK_OK); 2324 result = this->ParseArrayLiteral(classifier, CHECK_OK);
2274 break; 2325 break;
2275 2326
2276 case Token::LBRACE: 2327 case Token::LBRACE:
2328 if (!allow_harmony_destructuring()) {
2329 BindingPatternUnexpectedToken(classifier);
2330 }
2277 result = this->ParseObjectLiteral(classifier, CHECK_OK); 2331 result = this->ParseObjectLiteral(classifier, CHECK_OK);
2278 break; 2332 break;
2279 2333
2280 case Token::LPAREN: 2334 case Token::LPAREN:
2335 // Arrow function formal parameters are either a single identifier or a
2336 // list of BindingPattern productions enclosed in parentheses.
2337 // Parentheses are not valid on the LHS of a BindingPattern, so we use the
2338 // is_valid_binding_pattern() check to detect multiple levels of
2339 // parenthesization.
2340 if (!classifier->is_valid_binding_pattern()) {
2341 ArrowFormalParametersUnexpectedToken(classifier);
2342 }
2281 BindingPatternUnexpectedToken(classifier); 2343 BindingPatternUnexpectedToken(classifier);
2282 Consume(Token::LPAREN); 2344 Consume(Token::LPAREN);
2283 if (allow_harmony_arrow_functions() && Check(Token::RPAREN)) { 2345 if (allow_harmony_arrow_functions() && Check(Token::RPAREN)) {
2284 // As a primary expression, the only thing that can follow "()" is "=>". 2346 // As a primary expression, the only thing that can follow "()" is "=>".
2347 classifier->RecordBindingPatternError(scanner()->location(),
2348 "unexpected_token",
2349 Token::String(Token::RPAREN));
2285 Scope* scope = this->NewScope(scope_, ARROW_SCOPE); 2350 Scope* scope = this->NewScope(scope_, ARROW_SCOPE);
2286 scope->set_start_position(beg_pos); 2351 scope->set_start_position(beg_pos);
2287 FormalParameterErrorLocations error_locs; 2352 FormalParameterErrorLocations error_locs;
2288 bool has_rest = false; 2353 bool has_rest = false;
2289 result = this->ParseArrowFunctionLiteral(scope, error_locs, has_rest, 2354 result = this->ParseArrowFunctionLiteral(scope, error_locs, has_rest,
2290 classifier, CHECK_OK); 2355 CHECK_OK);
2291 } else { 2356 } else {
2292 // Heuristically try to detect immediately called functions before 2357 // Heuristically try to detect immediately called functions before
2293 // seeing the call parentheses. 2358 // seeing the call parentheses.
2294 parenthesized_function_ = (peek() == Token::FUNCTION); 2359 parenthesized_function_ = (peek() == Token::FUNCTION);
2295 result = this->ParseExpression(true, classifier, CHECK_OK); 2360 result = this->ParseExpression(true, classifier, CHECK_OK);
2296 result->increase_parenthesization_level(); 2361 result->increase_parenthesization_level();
2297 Expect(Token::RPAREN, CHECK_OK); 2362 Expect(Token::RPAREN, CHECK_OK);
2298 } 2363 }
2299 break; 2364 break;
2300 2365
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2357 2422
2358 2423
2359 // Precedence = 1 2424 // Precedence = 1
2360 template <class Traits> 2425 template <class Traits>
2361 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( 2426 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression(
2362 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { 2427 bool accept_IN, ExpressionClassifier* classifier, bool* ok) {
2363 // Expression :: 2428 // Expression ::
2364 // AssignmentExpression 2429 // AssignmentExpression
2365 // Expression ',' AssignmentExpression 2430 // Expression ',' AssignmentExpression
2366 2431
2432 ExpressionClassifier binding_classifier(
2433 classifier->formal_parameter_error_locs());
2367 ExpressionT result = 2434 ExpressionT result =
2368 this->ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); 2435 this->ParseAssignmentExpression(accept_IN, &binding_classifier, CHECK_OK);
2436 classifier->Accumulate(binding_classifier,
2437 ExpressionClassifier::AllProductions);
2369 while (peek() == Token::COMMA) { 2438 while (peek() == Token::COMMA) {
2370 Expect(Token::COMMA, CHECK_OK); 2439 Expect(Token::COMMA, CHECK_OK);
2371 int pos = position(); 2440 int pos = position();
2372 ExpressionT right = 2441 ExpressionT right = this->ParseAssignmentExpression(
2373 this->ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); 2442 accept_IN, &binding_classifier, CHECK_OK);
2443 classifier->Accumulate(binding_classifier,
2444 ExpressionClassifier::AllProductions);
2374 result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos); 2445 result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos);
2375 } 2446 }
2376 return result; 2447 return result;
2377 } 2448 }
2378 2449
2379 2450
2380 template <class Traits> 2451 template <class Traits>
2381 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral( 2452 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral(
2382 ExpressionClassifier* classifier, bool* ok) { 2453 ExpressionClassifier* classifier, bool* ok) {
2383 // ArrayLiteral :: 2454 // ArrayLiteral ::
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
2749 // LeftHandSideExpression AssignmentOperator AssignmentExpression 2820 // LeftHandSideExpression AssignmentOperator AssignmentExpression
2750 2821
2751 Scanner::Location lhs_location = scanner()->peek_location(); 2822 Scanner::Location lhs_location = scanner()->peek_location();
2752 2823
2753 if (peek() == Token::YIELD && is_generator()) { 2824 if (peek() == Token::YIELD && is_generator()) {
2754 return this->ParseYieldExpression(classifier, ok); 2825 return this->ParseYieldExpression(classifier, ok);
2755 } 2826 }
2756 2827
2757 if (fni_ != NULL) fni_->Enter(); 2828 if (fni_ != NULL) fni_->Enter();
2758 ParserBase<Traits>::Checkpoint checkpoint(this); 2829 ParserBase<Traits>::Checkpoint checkpoint(this);
2759 ExpressionT expression = 2830 FormalParameterErrorLocations formals_error_locs;
2760 this->ParseConditionalExpression(accept_IN, classifier, CHECK_OK); 2831 ExpressionClassifier arrow_formals_classifier(&formals_error_locs);
2832 if (peek() != Token::LPAREN) {
2833 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier);
2834 }
2835 ExpressionT expression = this->ParseConditionalExpression(
2836 accept_IN, &arrow_formals_classifier, CHECK_OK);
2837 classifier->Accumulate(arrow_formals_classifier);
2761 2838
2762 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) { 2839 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) {
2763 checkpoint.Restore(); 2840 checkpoint.Restore();
2764 FormalParameterErrorLocations error_locs; 2841 BindingPatternUnexpectedToken(classifier);
2842 ValidateArrowFormalParameters(&arrow_formals_classifier, expression,
2843 CHECK_OK);
2765 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos); 2844 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos);
2766 bool has_rest = false; 2845 bool has_rest = false;
2767 Scope* scope = this->NewScope(scope_, ARROW_SCOPE); 2846 Scope* scope = this->NewScope(scope_, ARROW_SCOPE);
2768 scope->set_start_position(lhs_location.beg_pos); 2847 scope->set_start_position(lhs_location.beg_pos);
2769 this->ParseArrowFunctionFormalParameters(scope, expression, loc, 2848 this->ParseArrowFunctionFormalParameters(
2770 &error_locs, &has_rest, CHECK_OK); 2849 scope, expression, loc, &formals_error_locs, &has_rest, CHECK_OK);
2771 expression = this->ParseArrowFunctionLiteral(scope, error_locs, has_rest, 2850 expression = this->ParseArrowFunctionLiteral(scope, formals_error_locs,
2772 classifier, CHECK_OK); 2851 has_rest, CHECK_OK);
2773 return expression; 2852 return expression;
2774 } 2853 }
2775 2854
2855 if (classifier->formal_parameter_error_locs()) {
2856 classifier->formal_parameter_error_locs()->Accumulate(formals_error_locs);
2857 }
2858
2776 if (!Token::IsAssignmentOp(peek())) { 2859 if (!Token::IsAssignmentOp(peek())) {
2777 if (fni_ != NULL) fni_->Leave(); 2860 if (fni_ != NULL) fni_->Leave();
2778 // Parsed conditional expression only (no assignment). 2861 // Parsed conditional expression only (no assignment).
2779 return expression; 2862 return expression;
2780 } 2863 }
2781 2864
2865 if (!allow_harmony_destructuring()) {
2866 BindingPatternUnexpectedToken(classifier);
2867 }
2868
2782 expression = this->CheckAndRewriteReferenceExpression( 2869 expression = this->CheckAndRewriteReferenceExpression(
2783 expression, lhs_location, "invalid_lhs_in_assignment", CHECK_OK); 2870 expression, lhs_location, "invalid_lhs_in_assignment", CHECK_OK);
2784 expression = this->MarkExpressionAsAssigned(expression); 2871 expression = this->MarkExpressionAsAssigned(expression);
2785 2872
2786 Token::Value op = Next(); // Get assignment operator. 2873 Token::Value op = Next(); // Get assignment operator.
2787 int pos = position(); 2874 int pos = position();
2788 ExpressionT right = 2875 ExpressionT right =
2789 this->ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); 2876 this->ParseAssignmentExpression(accept_IN, classifier, CHECK_OK);
2790 2877
2791 // TODO(1231235): We try to estimate the set of properties set by 2878 // TODO(1231235): We try to estimate the set of properties set by
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2873 bool* ok) { 2960 bool* ok) {
2874 // ConditionalExpression :: 2961 // ConditionalExpression ::
2875 // LogicalOrExpression 2962 // LogicalOrExpression
2876 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression 2963 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression
2877 2964
2878 int pos = peek_position(); 2965 int pos = peek_position();
2879 // We start using the binary expression parser for prec >= 4 only! 2966 // We start using the binary expression parser for prec >= 4 only!
2880 ExpressionT expression = 2967 ExpressionT expression =
2881 this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK); 2968 this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK);
2882 if (peek() != Token::CONDITIONAL) return expression; 2969 if (peek() != Token::CONDITIONAL) return expression;
2970 BindingPatternUnexpectedToken(classifier);
2883 Consume(Token::CONDITIONAL); 2971 Consume(Token::CONDITIONAL);
2884 // In parsing the first assignment expression in conditional 2972 // In parsing the first assignment expression in conditional
2885 // expressions we always accept the 'in' keyword; see ECMA-262, 2973 // expressions we always accept the 'in' keyword; see ECMA-262,
2886 // section 11.12, page 58. 2974 // section 11.12, page 58.
2887 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK); 2975 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK);
2888 Expect(Token::COLON, CHECK_OK); 2976 Expect(Token::COLON, CHECK_OK);
2889 ExpressionT right = 2977 ExpressionT right =
2890 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); 2978 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK);
2891 return factory()->NewConditional(expression, left, right, pos); 2979 return factory()->NewConditional(expression, left, right, pos);
2892 } 2980 }
2893 2981
2894 2982
2895 // Precedence >= 4 2983 // Precedence >= 4
2896 template <class Traits> 2984 template <class Traits>
2897 typename ParserBase<Traits>::ExpressionT 2985 typename ParserBase<Traits>::ExpressionT
2898 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, 2986 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN,
2899 ExpressionClassifier* classifier, 2987 ExpressionClassifier* classifier,
2900 bool* ok) { 2988 bool* ok) {
2901 DCHECK(prec >= 4); 2989 DCHECK(prec >= 4);
2902 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); 2990 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK);
2903 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { 2991 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) {
2904 // prec1 >= 4 2992 // prec1 >= 4
2905 while (Precedence(peek(), accept_IN) == prec1) { 2993 while (Precedence(peek(), accept_IN) == prec1) {
2994 BindingPatternUnexpectedToken(classifier);
2906 Token::Value op = Next(); 2995 Token::Value op = Next();
2907 Scanner::Location op_location = scanner()->location(); 2996 Scanner::Location op_location = scanner()->location();
2908 int pos = position(); 2997 int pos = position();
2909 ExpressionT y = 2998 ExpressionT y =
2910 ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK); 2999 ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK);
2911 3000
2912 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, 3001 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos,
2913 factory())) { 3002 factory())) {
2914 continue; 3003 continue;
2915 } 3004 }
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
3561 default: 3650 default:
3562 break; 3651 break;
3563 } 3652 }
3564 } 3653 }
3565 3654
3566 3655
3567 template <class Traits> 3656 template <class Traits>
3568 typename ParserBase<Traits>::ExpressionT 3657 typename ParserBase<Traits>::ExpressionT
3569 ParserBase<Traits>::ParseArrowFunctionLiteral( 3658 ParserBase<Traits>::ParseArrowFunctionLiteral(
3570 Scope* scope, const FormalParameterErrorLocations& error_locs, 3659 Scope* scope, const FormalParameterErrorLocations& error_locs,
3571 bool has_rest, ExpressionClassifier* classifier, bool* ok) { 3660 bool has_rest, bool* ok) {
3572 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { 3661 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) {
3573 // ASI inserts `;` after arrow parameters if a line terminator is found. 3662 // ASI inserts `;` after arrow parameters if a line terminator is found.
3574 // `=> ...` is never a valid expression, so report as syntax error. 3663 // `=> ...` is never a valid expression, so report as syntax error.
3575 // If next token is not `=>`, it's a syntax error anyways. 3664 // If next token is not `=>`, it's a syntax error anyways.
3576 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); 3665 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW);
3577 *ok = false; 3666 *ok = false;
3578 return this->EmptyExpression(); 3667 return this->EmptyExpression();
3579 } 3668 }
3580 3669
3581 typename Traits::Type::StatementList body; 3670 typename Traits::Type::StatementList body;
3582 int num_parameters = scope->num_parameters(); 3671 int num_parameters = scope->num_parameters();
3583 int materialized_literal_count = -1; 3672 int materialized_literal_count = -1;
3584 int expected_property_count = -1; 3673 int expected_property_count = -1;
3585 int handler_count = 0; 3674 int handler_count = 0;
3586 Scanner::Location super_loc; 3675 Scanner::Location super_loc;
3587 3676
3588 { 3677 {
3589 typename Traits::Type::Factory function_factory(ast_value_factory()); 3678 typename Traits::Type::Factory function_factory(ast_value_factory());
3590 FunctionState function_state(&function_state_, &scope_, scope, 3679 FunctionState function_state(&function_state_, &scope_, scope,
3591 kArrowFunction, &function_factory); 3680 kArrowFunction, &function_factory);
3592 3681
3593 if (peek() == Token::ARROW) {
3594 BindingPatternUnexpectedToken(classifier);
3595 }
3596 Expect(Token::ARROW, CHECK_OK); 3682 Expect(Token::ARROW, CHECK_OK);
3597 3683
3598 if (peek() == Token::LBRACE) { 3684 if (peek() == Token::LBRACE) {
3599 // Multiple statement body 3685 // Multiple statement body
3600 Consume(Token::LBRACE); 3686 Consume(Token::LBRACE);
3601 bool is_lazily_parsed = 3687 bool is_lazily_parsed =
3602 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); 3688 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation());
3603 if (is_lazily_parsed) { 3689 if (is_lazily_parsed) {
3604 body = this->NewStatementList(0, zone()); 3690 body = this->NewStatementList(0, zone());
3605 this->SkipLazyFunctionBody(&materialized_literal_count, 3691 this->SkipLazyFunctionBody(&materialized_literal_count,
3606 &expected_property_count, CHECK_OK); 3692 &expected_property_count, CHECK_OK);
3607 } else { 3693 } else {
3608 body = this->ParseEagerFunctionBody( 3694 body = this->ParseEagerFunctionBody(
3609 this->EmptyIdentifier(), RelocInfo::kNoPosition, NULL, 3695 this->EmptyIdentifier(), RelocInfo::kNoPosition, NULL,
3610 Token::INIT_VAR, kArrowFunction, CHECK_OK); 3696 Token::INIT_VAR, kArrowFunction, CHECK_OK);
3611 materialized_literal_count = 3697 materialized_literal_count =
3612 function_state.materialized_literal_count(); 3698 function_state.materialized_literal_count();
3613 expected_property_count = function_state.expected_property_count(); 3699 expected_property_count = function_state.expected_property_count();
3614 handler_count = function_state.handler_count(); 3700 handler_count = function_state.handler_count();
3615 } 3701 }
3616 } else { 3702 } else {
3617 // Single-expression body 3703 // Single-expression body
3618 int pos = position(); 3704 int pos = position();
3619 parenthesized_function_ = false; 3705 parenthesized_function_ = false;
3706 ExpressionClassifier classifier;
3620 ExpressionT expression = 3707 ExpressionT expression =
3621 ParseAssignmentExpression(true, classifier, CHECK_OK); 3708 ParseAssignmentExpression(true, &classifier, CHECK_OK);
3709 ValidateExpression(&classifier, CHECK_OK);
3622 body = this->NewStatementList(1, zone()); 3710 body = this->NewStatementList(1, zone());
3623 body->Add(factory()->NewReturnStatement(expression, pos), zone()); 3711 body->Add(factory()->NewReturnStatement(expression, pos), zone());
3624 materialized_literal_count = function_state.materialized_literal_count(); 3712 materialized_literal_count = function_state.materialized_literal_count();
3625 expected_property_count = function_state.expected_property_count(); 3713 expected_property_count = function_state.expected_property_count();
3626 handler_count = function_state.handler_count(); 3714 handler_count = function_state.handler_count();
3627 } 3715 }
3628 super_loc = function_state.super_location(); 3716 super_loc = function_state.super_location();
3629 3717
3630 scope->set_end_position(scanner()->location().end_pos); 3718 scope->set_end_position(scanner()->location().end_pos);
3631 3719
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
3843 *ok = false; 3931 *ok = false;
3844 return; 3932 return;
3845 } 3933 }
3846 has_seen_constructor_ = true; 3934 has_seen_constructor_ = true;
3847 return; 3935 return;
3848 } 3936 }
3849 } 3937 }
3850 } } // v8::internal 3938 } } // v8::internal
3851 3939
3852 #endif // V8_PREPARSER_H 3940 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698