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

Side by Side Diff: src/preparser.h

Issue 1272673003: [es6] Re-implement rest parameters via desugaring. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase + fix brokenness Created 5 years, 3 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
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/bailout-reason.h" 8 #include "src/bailout-reason.h"
9 #include "src/expression-classifier.h" 9 #include "src/expression-classifier.h"
10 #include "src/func-name-inferrer.h" 10 #include "src/func-name-inferrer.h"
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 void AddTemplateExpression(ExpressionT); 696 void AddTemplateExpression(ExpressionT);
697 ExpressionT ParseSuperExpression(bool is_new, 697 ExpressionT ParseSuperExpression(bool is_new,
698 ExpressionClassifier* classifier, bool* ok); 698 ExpressionClassifier* classifier, bool* ok);
699 ExpressionT ParseNewTargetExpression(bool* ok); 699 ExpressionT ParseNewTargetExpression(bool* ok);
700 ExpressionT ParseStrongInitializationExpression( 700 ExpressionT ParseStrongInitializationExpression(
701 ExpressionClassifier* classifier, bool* ok); 701 ExpressionClassifier* classifier, bool* ok);
702 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, 702 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier,
703 bool* ok); 703 bool* ok);
704 704
705 void ParseFormalParameter(FormalParametersT* parameters, 705 void ParseFormalParameter(FormalParametersT* parameters,
706 ExpressionClassifier* classifier, bool* ok); 706 ExpressionClassifier* classifier, int start_pos,
707 bool* ok);
708 inline void ParseFormalParameter(FormalParametersT* parameters,
adamk 2015/08/28 23:26:37 Is it really worth having two versions of this met
caitp (gmail) 2015/08/28 23:58:01 Sure, this way just seemed like less work than hun
caitp (gmail) 2015/08/29 15:51:59 Method is gone, isn't needed without the AST node
709 ExpressionClassifier* classifier, bool* ok) {
710 ParseFormalParameter(parameters, classifier, peek_position(), ok);
711 }
707 void ParseFormalParameterList(FormalParametersT* parameters, 712 void ParseFormalParameterList(FormalParametersT* parameters,
708 ExpressionClassifier* classifier, bool* ok); 713 ExpressionClassifier* classifier, bool* ok);
709 void CheckArityRestrictions( 714 void CheckArityRestrictions(
710 int param_count, FunctionLiteral::ArityRestriction arity_restriction, 715 int param_count, FunctionLiteral::ArityRestriction arity_restriction,
711 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok); 716 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok);
712 717
713 // Checks if the expression is a valid reference expression (e.g., on the 718 // Checks if the expression is a valid reference expression (e.g., on the
714 // left-hand side of assignments). Although ruled out by ECMA as early errors, 719 // left-hand side of assignments). Although ruled out by ECMA as early errors,
715 // we allow calls for web compatibility and rewrite them to a runtime throw. 720 // we allow calls for web compatibility and rewrite them to a runtime throw.
716 ExpressionT CheckAndRewriteReferenceExpression( 721 ExpressionT CheckAndRewriteReferenceExpression(
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 } 915 }
911 916
912 static PreParserExpression FromIdentifier(PreParserIdentifier id) { 917 static PreParserExpression FromIdentifier(PreParserIdentifier id) {
913 return PreParserExpression(TypeField::encode(kIdentifierExpression) | 918 return PreParserExpression(TypeField::encode(kIdentifierExpression) |
914 IdentifierTypeField::encode(id.type_)); 919 IdentifierTypeField::encode(id.type_));
915 } 920 }
916 921
917 static PreParserExpression BinaryOperation(PreParserExpression left, 922 static PreParserExpression BinaryOperation(PreParserExpression left,
918 Token::Value op, 923 Token::Value op,
919 PreParserExpression right) { 924 PreParserExpression right) {
920 return PreParserExpression(TypeField::encode(kBinaryOperationExpression)); 925 return PreParserExpression(
926 TypeField::encode(kBinaryOperationExpression) |
927 BinaryOperationTokenField::encode(op) |
adamk 2015/08/28 23:26:37 This seems overly general. Can you get away with j
caitp (gmail) 2015/08/28 23:58:01 Acknowledged
928 HasRestField::encode(right->IsSpreadExpression()));
921 } 929 }
922 930
923 static PreParserExpression StringLiteral() { 931 static PreParserExpression StringLiteral() {
924 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); 932 return PreParserExpression(TypeField::encode(kStringLiteralExpression));
925 } 933 }
926 934
927 static PreParserExpression UseStrictStringLiteral() { 935 static PreParserExpression UseStrictStringLiteral() {
928 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | 936 return PreParserExpression(TypeField::encode(kStringLiteralExpression) |
929 IsUseStrictField::encode(true)); 937 IsUseStrictField::encode(true));
930 } 938 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 static PreParserExpression NoTemplateTag() { 973 static PreParserExpression NoTemplateTag() {
966 return PreParserExpression( 974 return PreParserExpression(
967 TypeField::encode(kExpression) | 975 TypeField::encode(kExpression) |
968 ExpressionTypeField::encode(kNoTemplateTagExpression)); 976 ExpressionTypeField::encode(kNoTemplateTagExpression));
969 } 977 }
970 978
971 bool IsIdentifier() const { 979 bool IsIdentifier() const {
972 return TypeField::decode(code_) == kIdentifierExpression; 980 return TypeField::decode(code_) == kIdentifierExpression;
973 } 981 }
974 982
983 PreParserExpression AsVariableProxy() const { return *this; }
adamk 2015/08/28 23:26:37 If you end up needing this, it seems like it shoul
caitp (gmail) 2015/08/28 23:58:01 If it only returns false for `this`, that's probab
caitp (gmail) 2015/08/29 15:51:59 It's not needed without the new AST node, so it's
984
975 PreParserIdentifier AsIdentifier() const { 985 PreParserIdentifier AsIdentifier() const {
976 DCHECK(IsIdentifier()); 986 DCHECK(IsIdentifier());
977 return PreParserIdentifier(IdentifierTypeField::decode(code_)); 987 return PreParserIdentifier(IdentifierTypeField::decode(code_));
978 } 988 }
979 989
980 bool IsStringLiteral() const { 990 bool IsStringLiteral() const {
981 return TypeField::decode(code_) == kStringLiteralExpression; 991 return TypeField::decode(code_) == kStringLiteralExpression;
982 } 992 }
983 993
984 bool IsUseStrictLiteral() const { 994 bool IsUseStrictLiteral() const {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 1037
1028 bool IsNoTemplateTag() const { 1038 bool IsNoTemplateTag() const {
1029 return TypeField::decode(code_) == kExpression && 1039 return TypeField::decode(code_) == kExpression &&
1030 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression; 1040 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression;
1031 } 1041 }
1032 1042
1033 bool IsSpreadExpression() const { 1043 bool IsSpreadExpression() const {
1034 return TypeField::decode(code_) == kSpreadExpression; 1044 return TypeField::decode(code_) == kSpreadExpression;
1035 } 1045 }
1036 1046
1047 bool HasRestParameter() const {
1048 // Preparser's way of determining if an arrow function has a rest parameter.
1049 return IsSpreadExpression() ||
1050 (IsBinaryOperation() &&
1051 BinaryOperationTokenField::decode(code_) == Token::COMMA &&
adamk 2015/08/28 23:26:37 I'm not sure that you're getting much from this to
caitp (gmail) 2015/08/28 23:58:01 It's important for making lazy parsing work with a
adamk 2015/08/29 01:01:07 I think I wasn't as clear as I could have been. I
caitp (gmail) 2015/08/29 15:51:59 Done.
1052 HasRestField::decode(code_));
1053 }
1054
1037 PreParserExpression AsFunctionLiteral() { return *this; } 1055 PreParserExpression AsFunctionLiteral() { return *this; }
1038 1056
1039 bool IsBinaryOperation() const { 1057 bool IsBinaryOperation() const {
1040 return TypeField::decode(code_) == kBinaryOperationExpression; 1058 return TypeField::decode(code_) == kBinaryOperationExpression;
1041 } 1059 }
1042 1060
1043 // Dummy implementation for making expression->somefunc() work in both Parser 1061 // Dummy implementation for making expression->somefunc() work in both Parser
1044 // and PreParser. 1062 // and PreParser.
1045 PreParserExpression* operator->() { return this; } 1063 PreParserExpression* operator->() { return this; }
1046 1064
(...skipping 28 matching lines...) Expand all
1075 // The first three bits are for the Type. 1093 // The first three bits are for the Type.
1076 typedef BitField<Type, 0, 3> TypeField; 1094 typedef BitField<Type, 0, 3> TypeField;
1077 1095
1078 // The rest of the bits are interpreted depending on the value 1096 // The rest of the bits are interpreted depending on the value
1079 // of the Type field, so they can share the storage. 1097 // of the Type field, so they can share the storage.
1080 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; 1098 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField;
1081 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; 1099 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField;
1082 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; 1100 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField;
1083 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> 1101 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10>
1084 IdentifierTypeField; 1102 IdentifierTypeField;
1103 typedef BitField<Token::Value, TypeField::kNext, 8> BinaryOperationTokenField;
1104 typedef BitField<bool, BinaryOperationTokenField::kNext, 1> HasRestField;
1085 1105
1086 uint32_t code_; 1106 uint32_t code_;
1087 }; 1107 };
1088 1108
1089 1109
1090 // The pre-parser doesn't need to build lists of expressions, identifiers, or 1110 // The pre-parser doesn't need to build lists of expressions, identifiers, or
1091 // the like. 1111 // the like.
1092 template <typename T> 1112 template <typename T>
1093 class PreParserList { 1113 class PreParserList {
1094 public: 1114 public:
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 int literal_index, 1238 int literal_index,
1219 int boilerplate_properties, 1239 int boilerplate_properties,
1220 bool has_function, 1240 bool has_function,
1221 bool is_strong, 1241 bool is_strong,
1222 int pos) { 1242 int pos) {
1223 return PreParserExpression::Default(); 1243 return PreParserExpression::Default();
1224 } 1244 }
1225 PreParserExpression NewVariableProxy(void* variable) { 1245 PreParserExpression NewVariableProxy(void* variable) {
1226 return PreParserExpression::Default(); 1246 return PreParserExpression::Default();
1227 } 1247 }
1248 PreParserExpression NewRestParameter(PreParserExpression param, int index,
1249 int position) {
1250 return PreParserExpression::Default();
1251 }
1228 PreParserExpression NewProperty(PreParserExpression obj, 1252 PreParserExpression NewProperty(PreParserExpression obj,
1229 PreParserExpression key, 1253 PreParserExpression key,
1230 int pos) { 1254 int pos) {
1231 if (obj.IsThis()) { 1255 if (obj.IsThis()) {
1232 return PreParserExpression::ThisProperty(); 1256 return PreParserExpression::ThisProperty();
1233 } 1257 }
1234 return PreParserExpression::Property(); 1258 return PreParserExpression::Property();
1235 } 1259 }
1236 PreParserExpression NewUnaryOperation(Token::Value op, 1260 PreParserExpression NewUnaryOperation(Token::Value op,
1237 PreParserExpression expression, 1261 PreParserExpression expression,
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
1847 return pre_parser_->factory()->NewCallNew(function, args, pos); 1871 return pre_parser_->factory()->NewCallNew(function, args, pos);
1848 } 1872 }
1849 1873
1850 1874
1851 void PreParserTraits::ParseArrowFunctionFormalParameterList( 1875 void PreParserTraits::ParseArrowFunctionFormalParameterList(
1852 PreParserFormalParameters* parameters, 1876 PreParserFormalParameters* parameters,
1853 PreParserExpression params, const Scanner::Location& params_loc, 1877 PreParserExpression params, const Scanner::Location& params_loc,
1854 Scanner::Location* duplicate_loc, bool* ok) { 1878 Scanner::Location* duplicate_loc, bool* ok) {
1855 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter 1879 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter
1856 // lists that are too long. 1880 // lists that are too long.
1881
1882 // Accomodate array literal for rest parameter.
1883 if (params.HasRestParameter()) {
1884 ++parameters->materialized_literals_count;
1885 pre_parser_->function_state_->NextMaterializedLiteralIndex();
1886 }
1857 } 1887 }
1858 1888
1859 1889
1860 PreParserStatementList PreParser::ParseEagerFunctionBody( 1890 PreParserStatementList PreParser::ParseEagerFunctionBody(
1861 PreParserIdentifier function_name, int pos, 1891 PreParserIdentifier function_name, int pos,
1862 const PreParserFormalParameters& parameters, FunctionKind kind, 1892 const PreParserFormalParameters& parameters, FunctionKind kind,
1863 FunctionLiteral::FunctionType function_type, bool* ok) { 1893 FunctionLiteral::FunctionType function_type, bool* ok) {
1864 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 1894 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
1865 1895
1866 ParseStatementList(Token::RBRACE, ok); 1896 ParseStatementList(Token::RBRACE, ok);
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
2855 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, 2885 ValidateArrowFormalParameters(&arrow_formals_classifier, expression,
2856 parenthesized_formals, CHECK_OK); 2886 parenthesized_formals, CHECK_OK);
2857 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); 2887 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos);
2858 Scope* scope = 2888 Scope* scope =
2859 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); 2889 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction);
2860 FormalParametersT parameters(scope); 2890 FormalParametersT parameters(scope);
2861 if (!arrow_formals_classifier.is_simple_parameter_list()) { 2891 if (!arrow_formals_classifier.is_simple_parameter_list()) {
2862 scope->SetHasNonSimpleParameters(); 2892 scope->SetHasNonSimpleParameters();
2863 parameters.is_simple = false; 2893 parameters.is_simple = false;
2864 } 2894 }
2895
2896 Scanner::Location duplicate_loc = Scanner::Location::invalid();
2897 this->ParseArrowFunctionFormalParameterList(&parameters, expression, loc,
adamk 2015/08/28 23:26:37 So this had to move up because it now affects mate
caitp (gmail) 2015/08/28 23:58:01 Yeah :( I tried to find a better way to do it, but
adamk 2015/08/29 01:01:07 No need for a comment, as long as a test will fail
2898 &duplicate_loc, CHECK_OK);
2899
2865 checkpoint.Restore(&parameters.materialized_literals_count); 2900 checkpoint.Restore(&parameters.materialized_literals_count);
2866 2901
2867 scope->set_start_position(lhs_beg_pos); 2902 scope->set_start_position(lhs_beg_pos);
2868 Scanner::Location duplicate_loc = Scanner::Location::invalid();
2869 this->ParseArrowFunctionFormalParameterList(&parameters, expression, loc,
2870 &duplicate_loc, CHECK_OK);
2871 if (duplicate_loc.IsValid()) { 2903 if (duplicate_loc.IsValid()) {
2872 arrow_formals_classifier.RecordDuplicateFormalParameterError( 2904 arrow_formals_classifier.RecordDuplicateFormalParameterError(
2873 duplicate_loc); 2905 duplicate_loc);
2874 } 2906 }
2907
2875 expression = this->ParseArrowFunctionLiteral( 2908 expression = this->ParseArrowFunctionLiteral(
2876 parameters, arrow_formals_classifier, CHECK_OK); 2909 parameters, arrow_formals_classifier, CHECK_OK);
2877 return expression; 2910 return expression;
2878 } 2911 }
2879 2912
2880 // "expression" was not itself an arrow function parameter list, but it might 2913 // "expression" was not itself an arrow function parameter list, but it might
2881 // form part of one. Propagate speculative formal parameter error locations. 2914 // form part of one. Propagate speculative formal parameter error locations.
2882 classifier->Accumulate(arrow_formals_classifier, 2915 classifier->Accumulate(arrow_formals_classifier,
2883 ExpressionClassifier::StandardProductions | 2916 ExpressionClassifier::StandardProductions |
2884 ExpressionClassifier::FormalParametersProductions); 2917 ExpressionClassifier::FormalParametersProductions);
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
3649 default: 3682 default:
3650 return expression; 3683 return expression;
3651 } 3684 }
3652 } 3685 }
3653 DCHECK(false); 3686 DCHECK(false);
3654 return this->EmptyExpression(); 3687 return this->EmptyExpression();
3655 } 3688 }
3656 3689
3657 3690
3658 template <class Traits> 3691 template <class Traits>
3659 void ParserBase<Traits>::ParseFormalParameter( 3692 void ParserBase<Traits>::ParseFormalParameter(FormalParametersT* parameters,
3660 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) { 3693 ExpressionClassifier* classifier,
3694 int start_pos, bool* ok) {
3661 // FormalParameter[Yield,GeneratorParameter] : 3695 // FormalParameter[Yield,GeneratorParameter] :
3662 // BindingElement[?Yield, ?GeneratorParameter] 3696 // BindingElement[?Yield, ?GeneratorParameter]
3663 bool is_rest = parameters->has_rest; 3697 bool is_rest = parameters->has_rest;
3664 3698
3665 Token::Value next = peek(); 3699 Token::Value next = peek();
3666 ExpressionT pattern = ParsePrimaryExpression(classifier, ok); 3700 ExpressionT pattern = ParsePrimaryExpression(classifier, ok);
3667 if (!*ok) return; 3701 if (!*ok) return;
3668 3702
3669 ValidateBindingPattern(classifier, ok); 3703 ValidateBindingPattern(classifier, ok);
3670 if (!*ok) return; 3704 if (!*ok) return;
3671 3705
3672 if (!Traits::IsIdentifier(pattern)) { 3706 if (!Traits::IsIdentifier(pattern)) {
3673 if (is_rest || !allow_harmony_destructuring()) { 3707 if (is_rest || !allow_harmony_destructuring()) {
3674 ReportUnexpectedToken(next); 3708 ReportUnexpectedToken(next);
3675 *ok = false; 3709 *ok = false;
3676 return; 3710 return;
3677 } 3711 }
3678 parameters->is_simple = false; 3712 parameters->is_simple = false;
3679 classifier->RecordNonSimpleParameter(); 3713 classifier->RecordNonSimpleParameter();
3680 } 3714 }
3681 3715
3716 if (is_rest) {
3717 pattern = factory()->NewRestParameter(
3718 pattern->AsVariableProxy(),
3719 function_state_->NextMaterializedLiteralIndex(), start_pos);
3720 ++parameters->materialized_literals_count;
3721 }
3722
3682 ExpressionT initializer = Traits::EmptyExpression(); 3723 ExpressionT initializer = Traits::EmptyExpression();
3683 if (!is_rest && allow_harmony_default_parameters() && Check(Token::ASSIGN)) { 3724 if (!is_rest && allow_harmony_default_parameters() && Check(Token::ASSIGN)) {
3684 ExpressionClassifier init_classifier; 3725 ExpressionClassifier init_classifier;
3685 initializer = ParseAssignmentExpression(true, &init_classifier, ok); 3726 initializer = ParseAssignmentExpression(true, &init_classifier, ok);
3686 if (!*ok) return; 3727 if (!*ok) return;
3687 ValidateExpression(&init_classifier, ok); 3728 ValidateExpression(&init_classifier, ok);
3688 if (!*ok) return; 3729 if (!*ok) return;
3689 parameters->is_simple = false; 3730 parameters->is_simple = false;
3690 classifier->RecordNonSimpleParameter(); 3731 classifier->RecordNonSimpleParameter();
3691 } 3732 }
(...skipping 14 matching lines...) Expand all
3706 // FormalsList[?Yield, ?GeneratorParameter] 3747 // FormalsList[?Yield, ?GeneratorParameter]
3707 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] 3748 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield]
3708 // 3749 //
3709 // FormalsList[Yield,GeneratorParameter] : 3750 // FormalsList[Yield,GeneratorParameter] :
3710 // FormalParameter[?Yield, ?GeneratorParameter] 3751 // FormalParameter[?Yield, ?GeneratorParameter]
3711 // FormalsList[?Yield, ?GeneratorParameter] , 3752 // FormalsList[?Yield, ?GeneratorParameter] ,
3712 // FormalParameter[?Yield,?GeneratorParameter] 3753 // FormalParameter[?Yield,?GeneratorParameter]
3713 3754
3714 DCHECK_EQ(0, parameters->Arity()); 3755 DCHECK_EQ(0, parameters->Arity());
3715 3756
3757 int parameter_start;
3716 if (peek() != Token::RPAREN) { 3758 if (peek() != Token::RPAREN) {
3717 do { 3759 do {
3718 if (parameters->Arity() > Code::kMaxArguments) { 3760 if (parameters->Arity() > Code::kMaxArguments) {
3719 ReportMessage(MessageTemplate::kTooManyParameters); 3761 ReportMessage(MessageTemplate::kTooManyParameters);
3720 *ok = false; 3762 *ok = false;
3721 return; 3763 return;
3722 } 3764 }
3765 parameter_start = peek_position();
3723 parameters->has_rest = 3766 parameters->has_rest =
3724 allow_harmony_rest_parameters() && Check(Token::ELLIPSIS); 3767 allow_harmony_rest_parameters() && Check(Token::ELLIPSIS);
3725 ParseFormalParameter(parameters, classifier, ok); 3768
3769 ParseFormalParameter(parameters, classifier, parameter_start, ok);
3726 if (!*ok) return; 3770 if (!*ok) return;
3727 } while (!parameters->has_rest && Check(Token::COMMA)); 3771 } while (!parameters->has_rest && Check(Token::COMMA));
3728 3772
3729 if (parameters->has_rest) { 3773 if (parameters->has_rest) {
3730 parameters->is_simple = false; 3774 parameters->is_simple = false;
3731 classifier->RecordNonSimpleParameter(); 3775 classifier->RecordNonSimpleParameter();
3732 if (peek() == Token::COMMA) { 3776 if (peek() == Token::COMMA) {
3733 ReportMessageAt(scanner()->peek_location(), 3777 ReportMessageAt(scanner()->peek_location(),
3734 MessageTemplate::kParamAfterRest); 3778 MessageTemplate::kParamAfterRest);
3735 *ok = false; 3779 *ok = false;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
3810 3854
3811 if (peek() == Token::LBRACE) { 3855 if (peek() == Token::LBRACE) {
3812 // Multiple statement body 3856 // Multiple statement body
3813 Consume(Token::LBRACE); 3857 Consume(Token::LBRACE);
3814 bool is_lazily_parsed = 3858 bool is_lazily_parsed =
3815 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); 3859 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation());
3816 if (is_lazily_parsed) { 3860 if (is_lazily_parsed) {
3817 body = this->NewStatementList(0, zone()); 3861 body = this->NewStatementList(0, zone());
3818 this->SkipLazyFunctionBody(&materialized_literal_count, 3862 this->SkipLazyFunctionBody(&materialized_literal_count,
3819 &expected_property_count, CHECK_OK); 3863 &expected_property_count, CHECK_OK);
3864
3865 if (formal_parameters.has_rest) {
3866 DCHECK(formal_parameters.materialized_literals_count > 0);
adamk 2015/08/28 23:26:37 Would this ever be anything other than 1 in this c
caitp (gmail) 2015/08/28 23:58:01 Yes --- I believe initializers with materialized l
adamk 2015/08/29 01:01:07 Ah, I meant to say "can this ever happen without d
caitp (gmail) 2015/08/29 15:51:59 I've changed it to always add the formals material
3867 materialized_literal_count +=
3868 formal_parameters.materialized_literals_count;
3869 }
3820 } else { 3870 } else {
3821 body = this->ParseEagerFunctionBody( 3871 body = this->ParseEagerFunctionBody(
3822 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters, 3872 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters,
3823 kArrowFunction, FunctionLiteral::ANONYMOUS_EXPRESSION, CHECK_OK); 3873 kArrowFunction, FunctionLiteral::ANONYMOUS_EXPRESSION, CHECK_OK);
3824 materialized_literal_count = 3874 materialized_literal_count =
3825 function_state.materialized_literal_count(); 3875 function_state.materialized_literal_count();
3826 expected_property_count = function_state.expected_property_count(); 3876 expected_property_count = function_state.expected_property_count();
3827 } 3877 }
3828 } else { 3878 } else {
3829 // Single-expression body 3879 // Single-expression body
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
4076 *ok = false; 4126 *ok = false;
4077 return; 4127 return;
4078 } 4128 }
4079 has_seen_constructor_ = true; 4129 has_seen_constructor_ = true;
4080 return; 4130 return;
4081 } 4131 }
4082 } 4132 }
4083 } } // v8::internal 4133 } } // v8::internal
4084 4134
4085 #endif // V8_PREPARSER_H 4135 #endif // V8_PREPARSER_H
OLDNEW
« src/parser.cc ('K') | « src/pattern-rewriter.cc ('k') | src/prettyprinter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698