| OLD | NEW |
| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 zone_(zone), | 83 zone_(zone), |
| 84 scanner_(scanner), | 84 scanner_(scanner), |
| 85 stack_overflow_(false), | 85 stack_overflow_(false), |
| 86 allow_lazy_(false), | 86 allow_lazy_(false), |
| 87 allow_natives_(false), | 87 allow_natives_(false), |
| 88 allow_harmony_arrow_functions_(false), | 88 allow_harmony_arrow_functions_(false), |
| 89 allow_harmony_object_literals_(false), | 89 allow_harmony_object_literals_(false), |
| 90 allow_harmony_sloppy_(false), | 90 allow_harmony_sloppy_(false), |
| 91 allow_harmony_computed_property_names_(false), | 91 allow_harmony_computed_property_names_(false), |
| 92 allow_harmony_rest_params_(false), | 92 allow_harmony_rest_params_(false), |
| 93 allow_harmony_spreadcalls_(false), |
| 93 allow_strong_mode_(false) {} | 94 allow_strong_mode_(false) {} |
| 94 | 95 |
| 95 // Getters that indicate whether certain syntactical constructs are | 96 // Getters that indicate whether certain syntactical constructs are |
| 96 // allowed to be parsed by this instance of the parser. | 97 // allowed to be parsed by this instance of the parser. |
| 97 bool allow_lazy() const { return allow_lazy_; } | 98 bool allow_lazy() const { return allow_lazy_; } |
| 98 bool allow_natives() const { return allow_natives_; } | 99 bool allow_natives() const { return allow_natives_; } |
| 99 bool allow_harmony_arrow_functions() const { | 100 bool allow_harmony_arrow_functions() const { |
| 100 return allow_harmony_arrow_functions_; | 101 return allow_harmony_arrow_functions_; |
| 101 } | 102 } |
| 102 bool allow_harmony_modules() const { return scanner()->HarmonyModules(); } | 103 bool allow_harmony_modules() const { return scanner()->HarmonyModules(); } |
| 103 bool allow_harmony_numeric_literals() const { | 104 bool allow_harmony_numeric_literals() const { |
| 104 return scanner()->HarmonyNumericLiterals(); | 105 return scanner()->HarmonyNumericLiterals(); |
| 105 } | 106 } |
| 106 bool allow_harmony_classes() const { return scanner()->HarmonyClasses(); } | 107 bool allow_harmony_classes() const { return scanner()->HarmonyClasses(); } |
| 107 bool allow_harmony_object_literals() const { | 108 bool allow_harmony_object_literals() const { |
| 108 return allow_harmony_object_literals_; | 109 return allow_harmony_object_literals_; |
| 109 } | 110 } |
| 110 bool allow_harmony_sloppy() const { return allow_harmony_sloppy_; } | 111 bool allow_harmony_sloppy() const { return allow_harmony_sloppy_; } |
| 111 bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); } | 112 bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); } |
| 112 bool allow_harmony_computed_property_names() const { | 113 bool allow_harmony_computed_property_names() const { |
| 113 return allow_harmony_computed_property_names_; | 114 return allow_harmony_computed_property_names_; |
| 114 } | 115 } |
| 115 bool allow_harmony_rest_params() const { | 116 bool allow_harmony_rest_params() const { |
| 116 return allow_harmony_rest_params_; | 117 return allow_harmony_rest_params_; |
| 117 } | 118 } |
| 119 bool allow_harmony_spreadcalls() const { return allow_harmony_spreadcalls_; } |
| 118 | 120 |
| 119 bool allow_strong_mode() const { return allow_strong_mode_; } | 121 bool allow_strong_mode() const { return allow_strong_mode_; } |
| 120 | 122 |
| 121 // Setters that determine whether certain syntactical constructs are | 123 // Setters that determine whether certain syntactical constructs are |
| 122 // allowed to be parsed by this instance of the parser. | 124 // allowed to be parsed by this instance of the parser. |
| 123 void set_allow_lazy(bool allow) { allow_lazy_ = allow; } | 125 void set_allow_lazy(bool allow) { allow_lazy_ = allow; } |
| 124 void set_allow_natives(bool allow) { allow_natives_ = allow; } | 126 void set_allow_natives(bool allow) { allow_natives_ = allow; } |
| 125 void set_allow_harmony_arrow_functions(bool allow) { | 127 void set_allow_harmony_arrow_functions(bool allow) { |
| 126 allow_harmony_arrow_functions_ = allow; | 128 allow_harmony_arrow_functions_ = allow; |
| 127 } | 129 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 142 } | 144 } |
| 143 void set_allow_harmony_unicode(bool allow) { | 145 void set_allow_harmony_unicode(bool allow) { |
| 144 scanner()->SetHarmonyUnicode(allow); | 146 scanner()->SetHarmonyUnicode(allow); |
| 145 } | 147 } |
| 146 void set_allow_harmony_computed_property_names(bool allow) { | 148 void set_allow_harmony_computed_property_names(bool allow) { |
| 147 allow_harmony_computed_property_names_ = allow; | 149 allow_harmony_computed_property_names_ = allow; |
| 148 } | 150 } |
| 149 void set_allow_harmony_rest_params(bool allow) { | 151 void set_allow_harmony_rest_params(bool allow) { |
| 150 allow_harmony_rest_params_ = allow; | 152 allow_harmony_rest_params_ = allow; |
| 151 } | 153 } |
| 154 void set_allow_harmony_spreadcalls(bool allow) { |
| 155 allow_harmony_spreadcalls_ = allow; |
| 156 } |
| 152 void set_allow_strong_mode(bool allow) { allow_strong_mode_ = allow; } | 157 void set_allow_strong_mode(bool allow) { allow_strong_mode_ = allow; } |
| 153 | 158 |
| 154 protected: | 159 protected: |
| 155 enum AllowEvalOrArgumentsAsIdentifier { | 160 enum AllowEvalOrArgumentsAsIdentifier { |
| 156 kAllowEvalOrArguments, | 161 kAllowEvalOrArguments, |
| 157 kDontAllowEvalOrArguments | 162 kDontAllowEvalOrArguments |
| 158 }; | 163 }; |
| 159 | 164 |
| 160 enum Mode { | 165 enum Mode { |
| 161 PARSE_LAZILY, | 166 PARSE_LAZILY, |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 ExpressionT ParseExpression(bool accept_IN, bool* ok); | 581 ExpressionT ParseExpression(bool accept_IN, bool* ok); |
| 577 ExpressionT ParseArrayLiteral(bool* ok); | 582 ExpressionT ParseArrayLiteral(bool* ok); |
| 578 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, | 583 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, |
| 579 bool* is_static, bool* is_computed_name, | 584 bool* is_static, bool* is_computed_name, |
| 580 bool* ok); | 585 bool* ok); |
| 581 ExpressionT ParseObjectLiteral(bool* ok); | 586 ExpressionT ParseObjectLiteral(bool* ok); |
| 582 ObjectLiteralPropertyT ParsePropertyDefinition( | 587 ObjectLiteralPropertyT ParsePropertyDefinition( |
| 583 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 588 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
| 584 bool is_static, bool* is_computed_name, bool* has_seen_constructor, | 589 bool is_static, bool* is_computed_name, bool* has_seen_constructor, |
| 585 bool* ok); | 590 bool* ok); |
| 586 typename Traits::Type::ExpressionList ParseArguments(bool* ok); | 591 typename Traits::Type::ExpressionList ParseArguments( |
| 592 Scanner::Location* first_spread_pos, bool* ok); |
| 587 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); | 593 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); |
| 588 ExpressionT ParseYieldExpression(bool* ok); | 594 ExpressionT ParseYieldExpression(bool* ok); |
| 589 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); | 595 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); |
| 590 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 596 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
| 591 ExpressionT ParseUnaryExpression(bool* ok); | 597 ExpressionT ParseUnaryExpression(bool* ok); |
| 592 ExpressionT ParsePostfixExpression(bool* ok); | 598 ExpressionT ParsePostfixExpression(bool* ok); |
| 593 ExpressionT ParseLeftHandSideExpression(bool* ok); | 599 ExpressionT ParseLeftHandSideExpression(bool* ok); |
| 594 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); | 600 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); |
| 595 ExpressionT ParseMemberExpression(bool* ok); | 601 ExpressionT ParseMemberExpression(bool* ok); |
| 596 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression, | 602 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 Scanner* scanner_; | 694 Scanner* scanner_; |
| 689 bool stack_overflow_; | 695 bool stack_overflow_; |
| 690 | 696 |
| 691 bool allow_lazy_; | 697 bool allow_lazy_; |
| 692 bool allow_natives_; | 698 bool allow_natives_; |
| 693 bool allow_harmony_arrow_functions_; | 699 bool allow_harmony_arrow_functions_; |
| 694 bool allow_harmony_object_literals_; | 700 bool allow_harmony_object_literals_; |
| 695 bool allow_harmony_sloppy_; | 701 bool allow_harmony_sloppy_; |
| 696 bool allow_harmony_computed_property_names_; | 702 bool allow_harmony_computed_property_names_; |
| 697 bool allow_harmony_rest_params_; | 703 bool allow_harmony_rest_params_; |
| 704 bool allow_harmony_spreadcalls_; |
| 698 bool allow_strong_mode_; | 705 bool allow_strong_mode_; |
| 699 }; | 706 }; |
| 700 | 707 |
| 701 | 708 |
| 702 class PreParserIdentifier { | 709 class PreParserIdentifier { |
| 703 public: | 710 public: |
| 704 PreParserIdentifier() : type_(kUnknownIdentifier) {} | 711 PreParserIdentifier() : type_(kUnknownIdentifier) {} |
| 705 static PreParserIdentifier Default() { | 712 static PreParserIdentifier Default() { |
| 706 return PreParserIdentifier(kUnknownIdentifier); | 713 return PreParserIdentifier(kUnknownIdentifier); |
| 707 } | 714 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 friend class PreParserExpression; | 787 friend class PreParserExpression; |
| 781 }; | 788 }; |
| 782 | 789 |
| 783 | 790 |
| 784 class PreParserExpression { | 791 class PreParserExpression { |
| 785 public: | 792 public: |
| 786 static PreParserExpression Default() { | 793 static PreParserExpression Default() { |
| 787 return PreParserExpression(TypeField::encode(kExpression)); | 794 return PreParserExpression(TypeField::encode(kExpression)); |
| 788 } | 795 } |
| 789 | 796 |
| 797 static PreParserExpression Spread(PreParserExpression expression) { |
| 798 return PreParserExpression(TypeField::encode(kSpreadExpression)); |
| 799 } |
| 800 |
| 790 static PreParserExpression FromIdentifier(PreParserIdentifier id) { | 801 static PreParserExpression FromIdentifier(PreParserIdentifier id) { |
| 791 return PreParserExpression(TypeField::encode(kIdentifierExpression) | | 802 return PreParserExpression(TypeField::encode(kIdentifierExpression) | |
| 792 IdentifierTypeField::encode(id.type_)); | 803 IdentifierTypeField::encode(id.type_)); |
| 793 } | 804 } |
| 794 | 805 |
| 795 static PreParserExpression BinaryOperation(PreParserExpression left, | 806 static PreParserExpression BinaryOperation(PreParserExpression left, |
| 796 Token::Value op, | 807 Token::Value op, |
| 797 PreParserExpression right) { | 808 PreParserExpression right) { |
| 798 bool valid_arrow_param_list = | 809 bool valid_arrow_param_list = |
| 799 op == Token::COMMA && !left.is_parenthesized() && | 810 op == Token::COMMA && !left.is_parenthesized() && |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 | 919 |
| 909 // At the moment PreParser doesn't track these expression types. | 920 // At the moment PreParser doesn't track these expression types. |
| 910 bool IsFunctionLiteral() const { return false; } | 921 bool IsFunctionLiteral() const { return false; } |
| 911 bool IsCallNew() const { return false; } | 922 bool IsCallNew() const { return false; } |
| 912 | 923 |
| 913 bool IsNoTemplateTag() const { | 924 bool IsNoTemplateTag() const { |
| 914 return TypeField::decode(code_) == kExpression && | 925 return TypeField::decode(code_) == kExpression && |
| 915 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression; | 926 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression; |
| 916 } | 927 } |
| 917 | 928 |
| 929 bool IsSpreadExpression() const { |
| 930 return TypeField::decode(code_) == kSpreadExpression; |
| 931 } |
| 932 |
| 918 PreParserExpression AsFunctionLiteral() { return *this; } | 933 PreParserExpression AsFunctionLiteral() { return *this; } |
| 919 | 934 |
| 920 bool IsBinaryOperation() const { | 935 bool IsBinaryOperation() const { |
| 921 return TypeField::decode(code_) == kBinaryOperationExpression; | 936 return TypeField::decode(code_) == kBinaryOperationExpression; |
| 922 } | 937 } |
| 923 | 938 |
| 924 bool is_parenthesized() const { | 939 bool is_parenthesized() const { |
| 925 return ParenthesizationField::decode(code_) != kNotParenthesized; | 940 return ParenthesizationField::decode(code_) != kNotParenthesized; |
| 926 } | 941 } |
| 927 | 942 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 940 void set_parenthesized() {} | 955 void set_parenthesized() {} |
| 941 | 956 |
| 942 int position() const { return RelocInfo::kNoPosition; } | 957 int position() const { return RelocInfo::kNoPosition; } |
| 943 void set_function_token_position(int position) {} | 958 void set_function_token_position(int position) {} |
| 944 | 959 |
| 945 private: | 960 private: |
| 946 enum Type { | 961 enum Type { |
| 947 kExpression, | 962 kExpression, |
| 948 kIdentifierExpression, | 963 kIdentifierExpression, |
| 949 kStringLiteralExpression, | 964 kStringLiteralExpression, |
| 950 kBinaryOperationExpression | 965 kBinaryOperationExpression, |
| 966 kSpreadExpression |
| 951 }; | 967 }; |
| 952 | 968 |
| 953 enum Parenthesization { | 969 enum Parenthesization { |
| 954 kNotParenthesized, | 970 kNotParenthesized, |
| 955 kParanthesizedExpression, | 971 kParanthesizedExpression, |
| 956 kMultiParenthesizedExpression | 972 kMultiParenthesizedExpression |
| 957 }; | 973 }; |
| 958 | 974 |
| 959 enum ExpressionType { | 975 enum ExpressionType { |
| 960 kThisExpression, | 976 kThisExpression, |
| 961 kThisPropertyExpression, | 977 kThisPropertyExpression, |
| 962 kPropertyExpression, | 978 kPropertyExpression, |
| 963 kCallExpression, | 979 kCallExpression, |
| 964 kNoTemplateTagExpression | 980 kNoTemplateTagExpression |
| 965 }; | 981 }; |
| 966 | 982 |
| 967 explicit PreParserExpression(uint32_t expression_code) | 983 explicit PreParserExpression(uint32_t expression_code) |
| 968 : code_(expression_code) {} | 984 : code_(expression_code) {} |
| 969 | 985 |
| 970 V8_INLINE bool IsValidArrowParams() const { | 986 V8_INLINE bool IsValidArrowParams() const { |
| 971 return IsBinaryOperation() | 987 return IsBinaryOperation() |
| 972 ? IsValidArrowParamListField::decode(code_) | 988 ? IsValidArrowParamListField::decode(code_) |
| 973 : (IsIdentifier() && AsIdentifier().IsValidArrowParam()); | 989 : (IsIdentifier() && AsIdentifier().IsValidArrowParam()); |
| 974 } | 990 } |
| 975 | 991 |
| 976 // The first four bits are for the Type and Parenthesization. | 992 // The first five bits are for the Type and Parenthesization. |
| 977 typedef BitField<Type, 0, 2> TypeField; | 993 typedef BitField<Type, 0, 3> TypeField; |
| 978 typedef BitField<Parenthesization, TypeField::kNext, 2> ParenthesizationField; | 994 typedef BitField<Parenthesization, TypeField::kNext, 2> ParenthesizationField; |
| 979 | 995 |
| 980 // The rest of the bits are interpreted depending on the value | 996 // The rest of the bits are interpreted depending on the value |
| 981 // of the Type field, so they can share the storage. | 997 // of the Type field, so they can share the storage. |
| 982 typedef BitField<ExpressionType, ParenthesizationField::kNext, 3> | 998 typedef BitField<ExpressionType, ParenthesizationField::kNext, 3> |
| 983 ExpressionTypeField; | 999 ExpressionTypeField; |
| 984 typedef BitField<bool, ParenthesizationField::kNext, 1> IsUseStrictField; | 1000 typedef BitField<bool, ParenthesizationField::kNext, 1> IsUseStrictField; |
| 985 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; | 1001 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; |
| 986 typedef BitField<bool, ParenthesizationField::kNext, 1> | 1002 typedef BitField<bool, ParenthesizationField::kNext, 1> |
| 987 IsValidArrowParamListField; | 1003 IsValidArrowParamListField; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 PreParserExpression NewCall(PreParserExpression expression, | 1184 PreParserExpression NewCall(PreParserExpression expression, |
| 1169 PreParserExpressionList arguments, | 1185 PreParserExpressionList arguments, |
| 1170 int pos) { | 1186 int pos) { |
| 1171 return PreParserExpression::Call(); | 1187 return PreParserExpression::Call(); |
| 1172 } | 1188 } |
| 1173 PreParserExpression NewCallNew(PreParserExpression expression, | 1189 PreParserExpression NewCallNew(PreParserExpression expression, |
| 1174 PreParserExpressionList arguments, | 1190 PreParserExpressionList arguments, |
| 1175 int pos) { | 1191 int pos) { |
| 1176 return PreParserExpression::Default(); | 1192 return PreParserExpression::Default(); |
| 1177 } | 1193 } |
| 1194 PreParserExpression NewCallRuntime(const AstRawString* name, |
| 1195 const Runtime::Function* function, |
| 1196 PreParserExpressionList arguments, |
| 1197 int pos) { |
| 1198 return PreParserExpression::Default(); |
| 1199 } |
| 1178 PreParserStatement NewReturnStatement(PreParserExpression expression, | 1200 PreParserStatement NewReturnStatement(PreParserExpression expression, |
| 1179 int pos) { | 1201 int pos) { |
| 1180 return PreParserStatement::Default(); | 1202 return PreParserStatement::Default(); |
| 1181 } | 1203 } |
| 1182 PreParserExpression NewFunctionLiteral( | 1204 PreParserExpression NewFunctionLiteral( |
| 1183 PreParserIdentifier name, AstValueFactory* ast_value_factory, | 1205 PreParserIdentifier name, AstValueFactory* ast_value_factory, |
| 1184 Scope* scope, PreParserStatementList body, int materialized_literal_count, | 1206 Scope* scope, PreParserStatementList body, int materialized_literal_count, |
| 1185 int expected_property_count, int handler_count, int parameter_count, | 1207 int expected_property_count, int handler_count, int parameter_count, |
| 1186 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 1208 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
| 1187 FunctionLiteral::FunctionType function_type, | 1209 FunctionLiteral::FunctionType function_type, |
| 1188 FunctionLiteral::IsFunctionFlag is_function, | 1210 FunctionLiteral::IsFunctionFlag is_function, |
| 1189 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, | 1211 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, |
| 1190 int position) { | 1212 int position) { |
| 1191 return PreParserExpression::Default(); | 1213 return PreParserExpression::Default(); |
| 1192 } | 1214 } |
| 1193 | 1215 |
| 1216 PreParserExpression NewSpread(PreParserExpression expression, int pos) { |
| 1217 return PreParserExpression::Spread(expression); |
| 1218 } |
| 1219 |
| 1194 // Return the object itself as AstVisitor and implement the needed | 1220 // Return the object itself as AstVisitor and implement the needed |
| 1195 // dummy method right in this class. | 1221 // dummy method right in this class. |
| 1196 PreParserFactory* visitor() { return this; } | 1222 PreParserFactory* visitor() { return this; } |
| 1197 int* ast_properties() { | 1223 int* ast_properties() { |
| 1198 static int dummy = 42; | 1224 static int dummy = 42; |
| 1199 return &dummy; | 1225 return &dummy; |
| 1200 } | 1226 } |
| 1201 }; | 1227 }; |
| 1202 | 1228 |
| 1203 | 1229 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 PreParserIdentifier name, Scanner::Location function_name_location, | 1522 PreParserIdentifier name, Scanner::Location function_name_location, |
| 1497 bool name_is_strict_reserved, FunctionKind kind, | 1523 bool name_is_strict_reserved, FunctionKind kind, |
| 1498 int function_token_position, FunctionLiteral::FunctionType type, | 1524 int function_token_position, FunctionLiteral::FunctionType type, |
| 1499 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); | 1525 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); |
| 1500 | 1526 |
| 1501 PreParserExpression ParseClassLiteral(PreParserIdentifier name, | 1527 PreParserExpression ParseClassLiteral(PreParserIdentifier name, |
| 1502 Scanner::Location class_name_location, | 1528 Scanner::Location class_name_location, |
| 1503 bool name_is_strict_reserved, int pos, | 1529 bool name_is_strict_reserved, int pos, |
| 1504 bool* ok); | 1530 bool* ok); |
| 1505 | 1531 |
| 1532 PreParserExpressionList PrepareSpreadArguments(PreParserExpressionList list) { |
| 1533 return list; |
| 1534 } |
| 1535 |
| 1536 inline void MaterializeUnspreadArgumentsLiterals(int count); |
| 1537 |
| 1538 inline PreParserExpression SpreadCall(PreParserExpression function, |
| 1539 PreParserExpressionList args, int pos); |
| 1540 |
| 1541 inline PreParserExpression SpreadCallNew(PreParserExpression function, |
| 1542 PreParserExpressionList args, |
| 1543 int pos); |
| 1544 |
| 1506 private: | 1545 private: |
| 1507 PreParser* pre_parser_; | 1546 PreParser* pre_parser_; |
| 1508 }; | 1547 }; |
| 1509 | 1548 |
| 1510 | 1549 |
| 1511 // Preparsing checks a JavaScript program and emits preparse-data that helps | 1550 // Preparsing checks a JavaScript program and emits preparse-data that helps |
| 1512 // a later parsing to be faster. | 1551 // a later parsing to be faster. |
| 1513 // See preparse-data-format.h for the data format. | 1552 // See preparse-data-format.h for the data format. |
| 1514 | 1553 |
| 1515 // The PreParser checks that the syntax follows the grammar for JavaScript, | 1554 // The PreParser checks that the syntax follows the grammar for JavaScript, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1635 bool* ok); | 1674 bool* ok); |
| 1636 }; | 1675 }; |
| 1637 | 1676 |
| 1638 | 1677 |
| 1639 void PreParserTraits::MaterializeTemplateCallsiteLiterals() { | 1678 void PreParserTraits::MaterializeTemplateCallsiteLiterals() { |
| 1640 pre_parser_->function_state_->NextMaterializedLiteralIndex(); | 1679 pre_parser_->function_state_->NextMaterializedLiteralIndex(); |
| 1641 pre_parser_->function_state_->NextMaterializedLiteralIndex(); | 1680 pre_parser_->function_state_->NextMaterializedLiteralIndex(); |
| 1642 } | 1681 } |
| 1643 | 1682 |
| 1644 | 1683 |
| 1684 void PreParserTraits::MaterializeUnspreadArgumentsLiterals(int count) { |
| 1685 for (int i = 0; i < count; ++i) { |
| 1686 pre_parser_->function_state_->NextMaterializedLiteralIndex(); |
| 1687 } |
| 1688 } |
| 1689 |
| 1690 |
| 1691 PreParserExpression PreParserTraits::SpreadCall(PreParserExpression function, |
| 1692 PreParserExpressionList args, |
| 1693 int pos) { |
| 1694 return pre_parser_->factory()->NewCall(function, args, pos); |
| 1695 } |
| 1696 |
| 1697 PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function, |
| 1698 PreParserExpressionList args, |
| 1699 int pos) { |
| 1700 return pre_parser_->factory()->NewCallNew(function, args, pos); |
| 1701 } |
| 1702 |
| 1703 |
| 1645 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1704 PreParserStatementList PreParser::ParseEagerFunctionBody( |
| 1646 PreParserIdentifier function_name, int pos, Variable* fvar, | 1705 PreParserIdentifier function_name, int pos, Variable* fvar, |
| 1647 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { | 1706 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { |
| 1648 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 1707 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
| 1649 | 1708 |
| 1650 ParseStatementList(Token::RBRACE, ok); | 1709 ParseStatementList(Token::RBRACE, ok); |
| 1651 if (!*ok) return PreParserStatementList(); | 1710 if (!*ok) return PreParserStatementList(); |
| 1652 | 1711 |
| 1653 Expect(Token::RBRACE, ok); | 1712 Expect(Token::RBRACE, ok); |
| 1654 return PreParserStatementList(); | 1713 return PreParserStatementList(); |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2304 return factory()->NewObjectLiteral(properties, | 2363 return factory()->NewObjectLiteral(properties, |
| 2305 literal_index, | 2364 literal_index, |
| 2306 number_of_boilerplate_properties, | 2365 number_of_boilerplate_properties, |
| 2307 has_function, | 2366 has_function, |
| 2308 pos); | 2367 pos); |
| 2309 } | 2368 } |
| 2310 | 2369 |
| 2311 | 2370 |
| 2312 template <class Traits> | 2371 template <class Traits> |
| 2313 typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments( | 2372 typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments( |
| 2314 bool* ok) { | 2373 Scanner::Location* first_spread_arg_loc, bool* ok) { |
| 2315 // Arguments :: | 2374 // Arguments :: |
| 2316 // '(' (AssignmentExpression)*[','] ')' | 2375 // '(' (AssignmentExpression)*[','] ')' |
| 2317 | 2376 |
| 2377 Scanner::Location spread_arg = Scanner::Location::invalid(); |
| 2318 typename Traits::Type::ExpressionList result = | 2378 typename Traits::Type::ExpressionList result = |
| 2319 this->NewExpressionList(4, zone_); | 2379 this->NewExpressionList(4, zone_); |
| 2320 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); | 2380 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); |
| 2321 bool done = (peek() == Token::RPAREN); | 2381 bool done = (peek() == Token::RPAREN); |
| 2382 bool was_unspread = false; |
| 2383 int unspread_sequences_count = 0; |
| 2322 while (!done) { | 2384 while (!done) { |
| 2385 bool is_spread = allow_harmony_spreadcalls() && (peek() == Token::ELLIPSIS); |
| 2386 int start_pos = peek_position(); |
| 2387 if (is_spread) Consume(Token::ELLIPSIS); |
| 2388 |
| 2323 ExpressionT argument = this->ParseAssignmentExpression( | 2389 ExpressionT argument = this->ParseAssignmentExpression( |
| 2324 true, CHECK_OK_CUSTOM(NullExpressionList)); | 2390 true, CHECK_OK_CUSTOM(NullExpressionList)); |
| 2391 if (is_spread) { |
| 2392 if (!spread_arg.IsValid()) { |
| 2393 spread_arg.beg_pos = start_pos; |
| 2394 spread_arg.end_pos = peek_position(); |
| 2395 } |
| 2396 argument = factory()->NewSpread(argument, start_pos); |
| 2397 } |
| 2325 result->Add(argument, zone_); | 2398 result->Add(argument, zone_); |
| 2399 |
| 2400 // unspread_sequences_count is the number of sequences of parameters which |
| 2401 // are not prefixed with a spread '...' operator. |
| 2402 if (is_spread) { |
| 2403 was_unspread = false; |
| 2404 } else if (!was_unspread) { |
| 2405 was_unspread = true; |
| 2406 unspread_sequences_count++; |
| 2407 } |
| 2408 |
| 2326 if (result->length() > Code::kMaxArguments) { | 2409 if (result->length() > Code::kMaxArguments) { |
| 2327 ReportMessage("too_many_arguments"); | 2410 ReportMessage("too_many_arguments"); |
| 2328 *ok = false; | 2411 *ok = false; |
| 2329 return this->NullExpressionList(); | 2412 return this->NullExpressionList(); |
| 2330 } | 2413 } |
| 2331 done = (peek() != Token::COMMA); | 2414 done = (peek() != Token::COMMA); |
| 2332 if (!done) { | 2415 if (!done) { |
| 2333 Next(); | 2416 Next(); |
| 2334 } | 2417 } |
| 2335 } | 2418 } |
| 2336 Scanner::Location location = scanner_->location(); | 2419 Scanner::Location location = scanner_->location(); |
| 2337 if (Token::RPAREN != Next()) { | 2420 if (Token::RPAREN != Next()) { |
| 2338 ReportMessageAt(location, "unterminated_arg_list"); | 2421 ReportMessageAt(location, "unterminated_arg_list"); |
| 2339 *ok = false; | 2422 *ok = false; |
| 2340 return this->NullExpressionList(); | 2423 return this->NullExpressionList(); |
| 2341 } | 2424 } |
| 2425 *first_spread_arg_loc = spread_arg; |
| 2426 |
| 2427 if (spread_arg.IsValid()) { |
| 2428 // Unspread parameter sequences are translated into array literals in the |
| 2429 // parser. Ensure that the number of materialized literals matches between |
| 2430 // the parser and preparser |
| 2431 Traits::MaterializeUnspreadArgumentsLiterals(unspread_sequences_count); |
| 2432 } |
| 2433 |
| 2342 return result; | 2434 return result; |
| 2343 } | 2435 } |
| 2344 | 2436 |
| 2345 // Precedence = 2 | 2437 // Precedence = 2 |
| 2346 template <class Traits> | 2438 template <class Traits> |
| 2347 typename ParserBase<Traits>::ExpressionT | 2439 typename ParserBase<Traits>::ExpressionT |
| 2348 ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, bool* ok) { | 2440 ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, bool* ok) { |
| 2349 // AssignmentExpression :: | 2441 // AssignmentExpression :: |
| 2350 // ConditionalExpression | 2442 // ConditionalExpression |
| 2351 // ArrowFunction | 2443 // ArrowFunction |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2646 // should not point to the closing brace otherwise it will intersect | 2738 // should not point to the closing brace otherwise it will intersect |
| 2647 // with positions recorded for function literal and confuse debugger. | 2739 // with positions recorded for function literal and confuse debugger. |
| 2648 pos = peek_position(); | 2740 pos = peek_position(); |
| 2649 // Also the trailing parenthesis are a hint that the function will | 2741 // Also the trailing parenthesis are a hint that the function will |
| 2650 // be called immediately. If we happen to have parsed a preceding | 2742 // be called immediately. If we happen to have parsed a preceding |
| 2651 // function literal eagerly, we can also compile it eagerly. | 2743 // function literal eagerly, we can also compile it eagerly. |
| 2652 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { | 2744 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { |
| 2653 result->AsFunctionLiteral()->set_parenthesized(); | 2745 result->AsFunctionLiteral()->set_parenthesized(); |
| 2654 } | 2746 } |
| 2655 } | 2747 } |
| 2656 typename Traits::Type::ExpressionList args = ParseArguments(CHECK_OK); | 2748 Scanner::Location spread_pos; |
| 2749 typename Traits::Type::ExpressionList args = |
| 2750 ParseArguments(&spread_pos, CHECK_OK); |
| 2657 | 2751 |
| 2658 // Keep track of eval() calls since they disable all local variable | 2752 // Keep track of eval() calls since they disable all local variable |
| 2659 // optimizations. | 2753 // optimizations. |
| 2660 // The calls that need special treatment are the | 2754 // The calls that need special treatment are the |
| 2661 // direct eval calls. These calls are all of the form eval(...), with | 2755 // direct eval calls. These calls are all of the form eval(...), with |
| 2662 // no explicit receiver. | 2756 // no explicit receiver. |
| 2663 // These calls are marked as potentially direct eval calls. Whether | 2757 // These calls are marked as potentially direct eval calls. Whether |
| 2664 // they are actually direct calls to eval is determined at run time. | 2758 // they are actually direct calls to eval is determined at run time. |
| 2665 this->CheckPossibleEvalCall(result, scope_); | 2759 this->CheckPossibleEvalCall(result, scope_); |
| 2666 result = factory()->NewCall(result, args, pos); | 2760 |
| 2761 if (spread_pos.IsValid()) { |
| 2762 args = Traits::PrepareSpreadArguments(args); |
| 2763 result = Traits::SpreadCall(result, args, pos); |
| 2764 } else { |
| 2765 result = factory()->NewCall(result, args, pos); |
| 2766 } |
| 2667 if (fni_ != NULL) fni_->RemoveLastFunction(); | 2767 if (fni_ != NULL) fni_->RemoveLastFunction(); |
| 2668 break; | 2768 break; |
| 2669 } | 2769 } |
| 2670 | 2770 |
| 2671 case Token::PERIOD: { | 2771 case Token::PERIOD: { |
| 2672 Consume(Token::PERIOD); | 2772 Consume(Token::PERIOD); |
| 2673 int pos = position(); | 2773 int pos = position(); |
| 2674 IdentifierT name = ParseIdentifierName(CHECK_OK); | 2774 IdentifierT name = ParseIdentifierName(CHECK_OK); |
| 2675 result = factory()->NewProperty( | 2775 result = factory()->NewProperty( |
| 2676 result, factory()->NewStringLiteral(name, pos), pos); | 2776 result, factory()->NewStringLiteral(name, pos), pos); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2710 int new_pos = position(); | 2810 int new_pos = position(); |
| 2711 ExpressionT result = this->EmptyExpression(); | 2811 ExpressionT result = this->EmptyExpression(); |
| 2712 if (peek() == Token::SUPER) { | 2812 if (peek() == Token::SUPER) { |
| 2713 const bool is_new = true; | 2813 const bool is_new = true; |
| 2714 result = ParseSuperExpression(is_new, CHECK_OK); | 2814 result = ParseSuperExpression(is_new, CHECK_OK); |
| 2715 } else { | 2815 } else { |
| 2716 result = this->ParseMemberWithNewPrefixesExpression(CHECK_OK); | 2816 result = this->ParseMemberWithNewPrefixesExpression(CHECK_OK); |
| 2717 } | 2817 } |
| 2718 if (peek() == Token::LPAREN) { | 2818 if (peek() == Token::LPAREN) { |
| 2719 // NewExpression with arguments. | 2819 // NewExpression with arguments. |
| 2820 Scanner::Location spread_pos; |
| 2720 typename Traits::Type::ExpressionList args = | 2821 typename Traits::Type::ExpressionList args = |
| 2721 this->ParseArguments(CHECK_OK); | 2822 this->ParseArguments(&spread_pos, CHECK_OK); |
| 2722 result = factory()->NewCallNew(result, args, new_pos); | 2823 |
| 2824 if (spread_pos.IsValid()) { |
| 2825 args = Traits::PrepareSpreadArguments(args); |
| 2826 result = Traits::SpreadCallNew(result, args, new_pos); |
| 2827 } else { |
| 2828 result = factory()->NewCallNew(result, args, new_pos); |
| 2829 } |
| 2723 // The expression can still continue with . or [ after the arguments. | 2830 // The expression can still continue with . or [ after the arguments. |
| 2724 result = this->ParseMemberExpressionContinuation(result, CHECK_OK); | 2831 result = this->ParseMemberExpressionContinuation(result, CHECK_OK); |
| 2725 return result; | 2832 return result; |
| 2726 } | 2833 } |
| 2727 // NewExpression without arguments. | 2834 // NewExpression without arguments. |
| 2728 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), | 2835 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), |
| 2729 new_pos); | 2836 new_pos); |
| 2730 } | 2837 } |
| 2731 // No 'new' or 'super' keyword. | 2838 // No 'new' or 'super' keyword. |
| 2732 return this->ParseMemberExpression(ok); | 2839 return this->ParseMemberExpression(ok); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3163 *ok = false; | 3270 *ok = false; |
| 3164 return; | 3271 return; |
| 3165 } | 3272 } |
| 3166 has_seen_constructor_ = true; | 3273 has_seen_constructor_ = true; |
| 3167 return; | 3274 return; |
| 3168 } | 3275 } |
| 3169 } | 3276 } |
| 3170 } } // v8::internal | 3277 } } // v8::internal |
| 3171 | 3278 |
| 3172 #endif // V8_PREPARSER_H | 3279 #endif // V8_PREPARSER_H |
| OLD | NEW |