| 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/func-name-inferrer.h" | 10 #include "src/func-name-inferrer.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // // In particular... | 39 // // In particular... |
| 40 // struct Type { | 40 // struct Type { |
| 41 // // Used by FunctionState and BlockState. | 41 // // Used by FunctionState and BlockState. |
| 42 // typedef Scope; | 42 // typedef Scope; |
| 43 // typedef GeneratorVariable; | 43 // typedef GeneratorVariable; |
| 44 // typedef Zone; | 44 // typedef Zone; |
| 45 // // Return types for traversing functions. | 45 // // Return types for traversing functions. |
| 46 // typedef Identifier; | 46 // typedef Identifier; |
| 47 // typedef Expression; | 47 // typedef Expression; |
| 48 // typedef FunctionLiteral; | 48 // typedef FunctionLiteral; |
| 49 // typedef ClassLiteral; |
| 49 // typedef ObjectLiteralProperty; | 50 // typedef ObjectLiteralProperty; |
| 50 // typedef Literal; | 51 // typedef Literal; |
| 51 // typedef ExpressionList; | 52 // typedef ExpressionList; |
| 52 // typedef PropertyList; | 53 // typedef PropertyList; |
| 53 // // For constructing objects returned by the traversing functions. | 54 // // For constructing objects returned by the traversing functions. |
| 54 // typedef Factory; | 55 // typedef Factory; |
| 55 // }; | 56 // }; |
| 56 // // ... | 57 // // ... |
| 57 // }; | 58 // }; |
| 58 | 59 |
| 59 template <typename Traits> | 60 template <typename Traits> |
| 60 class ParserBase : public Traits { | 61 class ParserBase : public Traits { |
| 61 public: | 62 public: |
| 62 // Shorten type names defined by Traits. | 63 // Shorten type names defined by Traits. |
| 63 typedef typename Traits::Type::Expression ExpressionT; | 64 typedef typename Traits::Type::Expression ExpressionT; |
| 64 typedef typename Traits::Type::Identifier IdentifierT; | 65 typedef typename Traits::Type::Identifier IdentifierT; |
| 65 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; | 66 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; |
| 67 typedef typename Traits::Type::ClassLiteral ClassLiteralT; |
| 66 typedef typename Traits::Type::Literal LiteralT; | 68 typedef typename Traits::Type::Literal LiteralT; |
| 67 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; | 69 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; |
| 68 | 70 |
| 69 ParserBase(Scanner* scanner, uintptr_t stack_limit, v8::Extension* extension, | 71 ParserBase(Scanner* scanner, uintptr_t stack_limit, v8::Extension* extension, |
| 70 ParserRecorder* log, typename Traits::Type::Zone* zone, | 72 ParserRecorder* log, typename Traits::Type::Zone* zone, |
| 71 AstNode::IdGen* ast_node_id_gen, | 73 AstNode::IdGen* ast_node_id_gen, |
| 72 typename Traits::Type::Parser this_object) | 74 typename Traits::Type::Parser this_object) |
| 73 : Traits(this_object), | 75 : Traits(this_object), |
| 74 parenthesized_function_(false), | 76 parenthesized_function_(false), |
| 75 scope_(NULL), | 77 scope_(NULL), |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 // Parses an identifier and determines whether or not it is 'get' or 'set'. | 475 // Parses an identifier and determines whether or not it is 'get' or 'set'. |
| 474 IdentifierT ParseIdentifierNameOrGetOrSet(bool* is_get, | 476 IdentifierT ParseIdentifierNameOrGetOrSet(bool* is_get, |
| 475 bool* is_set, | 477 bool* is_set, |
| 476 bool* ok); | 478 bool* ok); |
| 477 | 479 |
| 478 ExpressionT ParseRegExpLiteral(bool seen_equal, bool* ok); | 480 ExpressionT ParseRegExpLiteral(bool seen_equal, bool* ok); |
| 479 | 481 |
| 480 ExpressionT ParsePrimaryExpression(bool* ok); | 482 ExpressionT ParsePrimaryExpression(bool* ok); |
| 481 ExpressionT ParseExpression(bool accept_IN, bool* ok); | 483 ExpressionT ParseExpression(bool accept_IN, bool* ok); |
| 482 ExpressionT ParseArrayLiteral(bool* ok); | 484 ExpressionT ParseArrayLiteral(bool* ok); |
| 485 IdentifierT ParsePropertyName(bool* is_get, bool* is_set, bool* is_static, |
| 486 bool* ok); |
| 483 ExpressionT ParseObjectLiteral(bool* ok); | 487 ExpressionT ParseObjectLiteral(bool* ok); |
| 484 ObjectLiteralPropertyT ParsePropertyDefinition(ObjectLiteralChecker* checker, | 488 ObjectLiteralPropertyT ParsePropertyDefinition(ObjectLiteralChecker* checker, |
| 489 bool in_class, bool is_static, |
| 485 bool* ok); | 490 bool* ok); |
| 486 IdentifierT ParsePropertyName(bool* is_getter, bool* is_setter, bool* ok); | |
| 487 typename Traits::Type::ExpressionList ParseArguments(bool* ok); | 491 typename Traits::Type::ExpressionList ParseArguments(bool* ok); |
| 488 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); | 492 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); |
| 489 ExpressionT ParseYieldExpression(bool* ok); | 493 ExpressionT ParseYieldExpression(bool* ok); |
| 490 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); | 494 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); |
| 491 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 495 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
| 492 ExpressionT ParseUnaryExpression(bool* ok); | 496 ExpressionT ParseUnaryExpression(bool* ok); |
| 493 ExpressionT ParsePostfixExpression(bool* ok); | 497 ExpressionT ParsePostfixExpression(bool* ok); |
| 494 ExpressionT ParseLeftHandSideExpression(bool* ok); | 498 ExpressionT ParseLeftHandSideExpression(bool* ok); |
| 495 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); | 499 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); |
| 496 ExpressionT ParseMemberExpression(bool* ok); | 500 ExpressionT ParseMemberExpression(bool* ok); |
| 497 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression, | 501 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression, |
| 498 bool* ok); | 502 bool* ok); |
| 499 ExpressionT ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast, | 503 ExpressionT ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast, |
| 500 bool* ok); | 504 bool* ok); |
| 505 ClassLiteralT ParseClassLiteral(IdentifierT name, |
| 506 Scanner::Location function_name_location, |
| 507 bool name_is_strict_reserved, int pos, |
| 508 bool* ok); |
| 501 | 509 |
| 502 // Checks if the expression is a valid reference expression (e.g., on the | 510 // Checks if the expression is a valid reference expression (e.g., on the |
| 503 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 511 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
| 504 // we allow calls for web compatibility and rewrite them to a runtime throw. | 512 // we allow calls for web compatibility and rewrite them to a runtime throw. |
| 505 ExpressionT CheckAndRewriteReferenceExpression( | 513 ExpressionT CheckAndRewriteReferenceExpression( |
| 506 ExpressionT expression, | 514 ExpressionT expression, |
| 507 Scanner::Location location, const char* message, bool* ok); | 515 Scanner::Location location, const char* message, bool* ok); |
| 508 | 516 |
| 509 // Used to detect duplicates in object literals. Each of the values | 517 // Used to detect duplicates in object literals. Each of the values |
| 510 // kGetterProperty, kSetterProperty and kValueProperty represents | 518 // kGetterProperty, kSetterProperty and kValueProperty represents |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 } | 613 } |
| 606 static PreParserIdentifier FutureStrictReserved() { | 614 static PreParserIdentifier FutureStrictReserved() { |
| 607 return PreParserIdentifier(kFutureStrictReservedIdentifier); | 615 return PreParserIdentifier(kFutureStrictReservedIdentifier); |
| 608 } | 616 } |
| 609 static PreParserIdentifier Let() { | 617 static PreParserIdentifier Let() { |
| 610 return PreParserIdentifier(kLetIdentifier); | 618 return PreParserIdentifier(kLetIdentifier); |
| 611 } | 619 } |
| 612 static PreParserIdentifier Yield() { | 620 static PreParserIdentifier Yield() { |
| 613 return PreParserIdentifier(kYieldIdentifier); | 621 return PreParserIdentifier(kYieldIdentifier); |
| 614 } | 622 } |
| 623 static PreParserIdentifier Prototype() { |
| 624 return PreParserIdentifier(kPrototypeIdentifier); |
| 625 } |
| 626 static PreParserIdentifier Constructor() { |
| 627 return PreParserIdentifier(kConstructorIdentifier); |
| 628 } |
| 615 bool IsEval() const { return type_ == kEvalIdentifier; } | 629 bool IsEval() const { return type_ == kEvalIdentifier; } |
| 616 bool IsArguments() const { return type_ == kArgumentsIdentifier; } | 630 bool IsArguments() const { return type_ == kArgumentsIdentifier; } |
| 617 bool IsEvalOrArguments() const { return type_ >= kEvalIdentifier; } | |
| 618 bool IsYield() const { return type_ == kYieldIdentifier; } | 631 bool IsYield() const { return type_ == kYieldIdentifier; } |
| 632 bool IsPrototype() const { return type_ == kPrototypeIdentifier; } |
| 633 bool IsConstructor() const { return type_ == kConstructorIdentifier; } |
| 634 bool IsEvalOrArguments() const { |
| 635 return type_ == kEvalIdentifier || type_ == kArgumentsIdentifier; |
| 636 } |
| 619 bool IsFutureReserved() const { return type_ == kFutureReservedIdentifier; } | 637 bool IsFutureReserved() const { return type_ == kFutureReservedIdentifier; } |
| 620 bool IsFutureStrictReserved() const { | 638 bool IsFutureStrictReserved() const { |
| 621 return type_ == kFutureStrictReservedIdentifier; | 639 return type_ == kFutureStrictReservedIdentifier; |
| 622 } | 640 } |
| 623 bool IsValidStrictVariable() const { return type_ == kUnknownIdentifier; } | 641 bool IsValidStrictVariable() const { return type_ == kUnknownIdentifier; } |
| 624 | 642 |
| 625 // Allow identifier->name()[->length()] to work. The preparser | 643 // Allow identifier->name()[->length()] to work. The preparser |
| 626 // does not need the actual positions/lengths of the identifiers. | 644 // does not need the actual positions/lengths of the identifiers. |
| 627 const PreParserIdentifier* operator->() const { return this; } | 645 const PreParserIdentifier* operator->() const { return this; } |
| 628 const PreParserIdentifier raw_name() const { return *this; } | 646 const PreParserIdentifier raw_name() const { return *this; } |
| 629 | 647 |
| 630 int position() const { return 0; } | 648 int position() const { return 0; } |
| 631 int length() const { return 0; } | 649 int length() const { return 0; } |
| 632 | 650 |
| 633 private: | 651 private: |
| 634 enum Type { | 652 enum Type { |
| 635 kUnknownIdentifier, | 653 kUnknownIdentifier, |
| 636 kFutureReservedIdentifier, | 654 kFutureReservedIdentifier, |
| 637 kFutureStrictReservedIdentifier, | 655 kFutureStrictReservedIdentifier, |
| 638 kLetIdentifier, | 656 kLetIdentifier, |
| 639 kYieldIdentifier, | 657 kYieldIdentifier, |
| 640 kEvalIdentifier, | 658 kEvalIdentifier, |
| 641 kArgumentsIdentifier | 659 kArgumentsIdentifier, |
| 660 kPrototypeIdentifier, |
| 661 kConstructorIdentifier |
| 642 }; | 662 }; |
| 643 explicit PreParserIdentifier(Type type) : type_(type) {} | 663 explicit PreParserIdentifier(Type type) : type_(type) {} |
| 644 Type type_; | 664 Type type_; |
| 645 | 665 |
| 646 friend class PreParserExpression; | 666 friend class PreParserExpression; |
| 647 friend class PreParserScope; | 667 friend class PreParserScope; |
| 648 }; | 668 }; |
| 649 | 669 |
| 650 | 670 |
| 651 // Bits 0 and 1 are used to identify the type of expression: | 671 // Bits 0 and 1 are used to identify the type of expression: |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 public: | 940 public: |
| 921 explicit PreParserScope(PreParserScope* outer_scope, ScopeType scope_type, | 941 explicit PreParserScope(PreParserScope* outer_scope, ScopeType scope_type, |
| 922 void* = NULL) | 942 void* = NULL) |
| 923 : scope_type_(scope_type) { | 943 : scope_type_(scope_type) { |
| 924 strict_mode_ = outer_scope ? outer_scope->strict_mode() : SLOPPY; | 944 strict_mode_ = outer_scope ? outer_scope->strict_mode() : SLOPPY; |
| 925 } | 945 } |
| 926 | 946 |
| 927 ScopeType type() { return scope_type_; } | 947 ScopeType type() { return scope_type_; } |
| 928 StrictMode strict_mode() const { return strict_mode_; } | 948 StrictMode strict_mode() const { return strict_mode_; } |
| 929 void SetStrictMode(StrictMode strict_mode) { strict_mode_ = strict_mode; } | 949 void SetStrictMode(StrictMode strict_mode) { strict_mode_ = strict_mode; } |
| 950 void SetScopeName(PreParserIdentifier name) {} |
| 930 | 951 |
| 931 // When PreParser is in use, lazy compilation is already being done, | 952 // When PreParser is in use, lazy compilation is already being done, |
| 932 // things cannot get lazier than that. | 953 // things cannot get lazier than that. |
| 933 bool AllowsLazyCompilation() const { return false; } | 954 bool AllowsLazyCompilation() const { return false; } |
| 934 | 955 |
| 935 void set_start_position(int position) {} | 956 void set_start_position(int position) {} |
| 936 void set_end_position(int position) {} | 957 void set_end_position(int position) {} |
| 937 | 958 |
| 938 bool IsDeclared(const PreParserIdentifier& identifier) const { return false; } | 959 bool IsDeclared(const PreParserIdentifier& identifier) const { return false; } |
| 939 void DeclareParameter(const PreParserIdentifier& identifier, VariableMode) {} | 960 void DeclareParameter(const PreParserIdentifier& identifier, VariableMode) {} |
| (...skipping 24 matching lines...) Expand all Loading... |
| 964 int pos) { | 985 int pos) { |
| 965 return PreParserExpression::Default(); | 986 return PreParserExpression::Default(); |
| 966 } | 987 } |
| 967 PreParserExpression NewArrayLiteral(PreParserExpressionList values, | 988 PreParserExpression NewArrayLiteral(PreParserExpressionList values, |
| 968 int literal_index, | 989 int literal_index, |
| 969 int pos) { | 990 int pos) { |
| 970 return PreParserExpression::Default(); | 991 return PreParserExpression::Default(); |
| 971 } | 992 } |
| 972 PreParserExpression NewObjectLiteralProperty(bool is_getter, | 993 PreParserExpression NewObjectLiteralProperty(bool is_getter, |
| 973 PreParserExpression value, | 994 PreParserExpression value, |
| 974 int pos) { | 995 int pos, bool is_static) { |
| 975 return PreParserExpression::Default(); | 996 return PreParserExpression::Default(); |
| 976 } | 997 } |
| 977 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, | 998 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, |
| 978 PreParserExpression value) { | 999 PreParserExpression value, |
| 1000 bool is_static) { |
| 979 return PreParserExpression::Default(); | 1001 return PreParserExpression::Default(); |
| 980 } | 1002 } |
| 981 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, | 1003 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, |
| 982 int literal_index, | 1004 int literal_index, |
| 983 int boilerplate_properties, | 1005 int boilerplate_properties, |
| 984 bool has_function, | 1006 bool has_function, |
| 985 int pos) { | 1007 int pos) { |
| 986 return PreParserExpression::Default(); | 1008 return PreParserExpression::Default(); |
| 987 } | 1009 } |
| 988 PreParserExpression NewVariableProxy(void* generator_variable) { | 1010 PreParserExpression NewVariableProxy(void* variable) { |
| 989 return PreParserExpression::Default(); | 1011 return PreParserExpression::Default(); |
| 990 } | 1012 } |
| 991 PreParserExpression NewProperty(PreParserExpression obj, | 1013 PreParserExpression NewProperty(PreParserExpression obj, |
| 992 PreParserExpression key, | 1014 PreParserExpression key, |
| 993 int pos) { | 1015 int pos) { |
| 994 if (obj.IsThis()) { | 1016 if (obj.IsThis()) { |
| 995 return PreParserExpression::ThisProperty(); | 1017 return PreParserExpression::ThisProperty(); |
| 996 } | 1018 } |
| 997 return PreParserExpression::Property(); | 1019 return PreParserExpression::Property(); |
| 998 } | 1020 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 const PreParserScope& scope, PreParserStatementList body, | 1076 const PreParserScope& scope, PreParserStatementList body, |
| 1055 int materialized_literal_count, int expected_property_count, | 1077 int materialized_literal_count, int expected_property_count, |
| 1056 int handler_count, int parameter_count, | 1078 int handler_count, int parameter_count, |
| 1057 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 1079 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
| 1058 FunctionLiteral::FunctionType function_type, | 1080 FunctionLiteral::FunctionType function_type, |
| 1059 FunctionLiteral::IsFunctionFlag is_function, | 1081 FunctionLiteral::IsFunctionFlag is_function, |
| 1060 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, | 1082 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, |
| 1061 int position) { | 1083 int position) { |
| 1062 return PreParserExpression::Default(); | 1084 return PreParserExpression::Default(); |
| 1063 } | 1085 } |
| 1086 PreParserExpression NewClassLiteral(PreParserIdentifier name, |
| 1087 PreParserExpression extends, |
| 1088 PreParserExpression constructor, |
| 1089 PreParserExpressionList properties, |
| 1090 AstValueFactory* ast_value_factory, |
| 1091 int position) { |
| 1092 return PreParserExpression::Default(); |
| 1093 } |
| 1064 | 1094 |
| 1065 // Return the object itself as AstVisitor and implement the needed | 1095 // Return the object itself as AstVisitor and implement the needed |
| 1066 // dummy method right in this class. | 1096 // dummy method right in this class. |
| 1067 PreParserFactory* visitor() { return this; } | 1097 PreParserFactory* visitor() { return this; } |
| 1068 BailoutReason dont_optimize_reason() { return kNoReason; } | 1098 BailoutReason dont_optimize_reason() { return kNoReason; } |
| 1069 int* ast_properties() { | 1099 int* ast_properties() { |
| 1070 static int dummy = 42; | 1100 static int dummy = 42; |
| 1071 return &dummy; | 1101 return &dummy; |
| 1072 } | 1102 } |
| 1073 }; | 1103 }; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1092 typedef void Zone; | 1122 typedef void Zone; |
| 1093 | 1123 |
| 1094 typedef int AstProperties; | 1124 typedef int AstProperties; |
| 1095 typedef Vector<PreParserIdentifier> ParameterIdentifierVector; | 1125 typedef Vector<PreParserIdentifier> ParameterIdentifierVector; |
| 1096 | 1126 |
| 1097 // Return types for traversing functions. | 1127 // Return types for traversing functions. |
| 1098 typedef PreParserIdentifier Identifier; | 1128 typedef PreParserIdentifier Identifier; |
| 1099 typedef PreParserExpression Expression; | 1129 typedef PreParserExpression Expression; |
| 1100 typedef PreParserExpression YieldExpression; | 1130 typedef PreParserExpression YieldExpression; |
| 1101 typedef PreParserExpression FunctionLiteral; | 1131 typedef PreParserExpression FunctionLiteral; |
| 1132 typedef PreParserExpression ClassLiteral; |
| 1102 typedef PreParserExpression ObjectLiteralProperty; | 1133 typedef PreParserExpression ObjectLiteralProperty; |
| 1103 typedef PreParserExpression Literal; | 1134 typedef PreParserExpression Literal; |
| 1104 typedef PreParserExpressionList ExpressionList; | 1135 typedef PreParserExpressionList ExpressionList; |
| 1105 typedef PreParserExpressionList PropertyList; | 1136 typedef PreParserExpressionList PropertyList; |
| 1106 typedef PreParserStatementList StatementList; | 1137 typedef PreParserStatementList StatementList; |
| 1107 | 1138 |
| 1108 // For constructing objects returned by the traversing functions. | 1139 // For constructing objects returned by the traversing functions. |
| 1109 typedef PreParserFactory Factory; | 1140 typedef PreParserFactory Factory; |
| 1110 }; | 1141 }; |
| 1111 | 1142 |
| 1112 class Checkpoint; | 1143 class Checkpoint; |
| 1113 | 1144 |
| 1114 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} | 1145 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} |
| 1115 | 1146 |
| 1116 // Custom operations executed when FunctionStates are created and | 1147 // Custom operations executed when FunctionStates are created and |
| 1117 // destructed. (The PreParser doesn't need to do anything.) | 1148 // destructed. (The PreParser doesn't need to do anything.) |
| 1118 template <typename FunctionState> | 1149 template <typename FunctionState> |
| 1119 static void SetUpFunctionState(FunctionState* function_state) {} | 1150 static void SetUpFunctionState(FunctionState* function_state) {} |
| 1120 template <typename FunctionState> | 1151 template <typename FunctionState> |
| 1121 static void TearDownFunctionState(FunctionState* function_state) {} | 1152 static void TearDownFunctionState(FunctionState* function_state) {} |
| 1122 | 1153 |
| 1123 // Helper functions for recursive descent. | 1154 // Helper functions for recursive descent. |
| 1124 static bool IsEvalOrArguments(PreParserIdentifier identifier) { | 1155 static bool IsEvalOrArguments(PreParserIdentifier identifier) { |
| 1125 return identifier.IsEvalOrArguments(); | 1156 return identifier.IsEvalOrArguments(); |
| 1126 } | 1157 } |
| 1127 | 1158 |
| 1159 static bool IsPrototype(PreParserIdentifier identifier) { |
| 1160 return identifier.IsPrototype(); |
| 1161 } |
| 1162 |
| 1163 static bool IsConstructor(PreParserIdentifier identifier) { |
| 1164 return identifier.IsConstructor(); |
| 1165 } |
| 1166 |
| 1128 // Returns true if the expression is of type "this.foo". | 1167 // Returns true if the expression is of type "this.foo". |
| 1129 static bool IsThisProperty(PreParserExpression expression) { | 1168 static bool IsThisProperty(PreParserExpression expression) { |
| 1130 return expression.IsThisProperty(); | 1169 return expression.IsThisProperty(); |
| 1131 } | 1170 } |
| 1132 | 1171 |
| 1133 static bool IsIdentifier(PreParserExpression expression) { | 1172 static bool IsIdentifier(PreParserExpression expression) { |
| 1134 return expression.IsIdentifier(); | 1173 return expression.IsIdentifier(); |
| 1135 } | 1174 } |
| 1136 | 1175 |
| 1137 static PreParserIdentifier AsIdentifier(PreParserExpression expression) { | 1176 static PreParserIdentifier AsIdentifier(PreParserExpression expression) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1238 } | 1277 } |
| 1239 static PreParserExpression EmptyArrowParamList() { | 1278 static PreParserExpression EmptyArrowParamList() { |
| 1240 return PreParserExpression::EmptyArrowParamList(); | 1279 return PreParserExpression::EmptyArrowParamList(); |
| 1241 } | 1280 } |
| 1242 static PreParserExpression EmptyLiteral() { | 1281 static PreParserExpression EmptyLiteral() { |
| 1243 return PreParserExpression::Default(); | 1282 return PreParserExpression::Default(); |
| 1244 } | 1283 } |
| 1245 static PreParserExpression EmptyObjectLiteralProperty() { | 1284 static PreParserExpression EmptyObjectLiteralProperty() { |
| 1246 return PreParserExpression::Default(); | 1285 return PreParserExpression::Default(); |
| 1247 } | 1286 } |
| 1287 static PreParserExpression EmptyFunctionLiteral() { |
| 1288 return PreParserExpression::Default(); |
| 1289 } |
| 1290 static PreParserExpression EmptyClassLiteral() { |
| 1291 return PreParserExpression::Default(); |
| 1292 } |
| 1248 static PreParserExpressionList NullExpressionList() { | 1293 static PreParserExpressionList NullExpressionList() { |
| 1249 return PreParserExpressionList(); | 1294 return PreParserExpressionList(); |
| 1250 } | 1295 } |
| 1251 | 1296 |
| 1252 // Odd-ball literal creators. | 1297 // Odd-ball literal creators. |
| 1253 static PreParserExpression GetLiteralTheHole(int position, | 1298 static PreParserExpression GetLiteralTheHole(int position, |
| 1254 PreParserFactory* factory) { | 1299 PreParserFactory* factory) { |
| 1255 return PreParserExpression::Default(); | 1300 return PreParserExpression::Default(); |
| 1256 } | 1301 } |
| 1257 | 1302 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1428 }; | 1473 }; |
| 1429 | 1474 |
| 1430 // All ParseXXX functions take as the last argument an *ok parameter | 1475 // All ParseXXX functions take as the last argument an *ok parameter |
| 1431 // which is set to false if parsing failed; it is unchanged otherwise. | 1476 // which is set to false if parsing failed; it is unchanged otherwise. |
| 1432 // By making the 'exception handling' explicit, we are forced to check | 1477 // By making the 'exception handling' explicit, we are forced to check |
| 1433 // for failure at the call sites. | 1478 // for failure at the call sites. |
| 1434 Statement ParseSourceElement(bool* ok); | 1479 Statement ParseSourceElement(bool* ok); |
| 1435 SourceElements ParseSourceElements(int end_token, bool* ok); | 1480 SourceElements ParseSourceElements(int end_token, bool* ok); |
| 1436 Statement ParseStatement(bool* ok); | 1481 Statement ParseStatement(bool* ok); |
| 1437 Statement ParseFunctionDeclaration(bool* ok); | 1482 Statement ParseFunctionDeclaration(bool* ok); |
| 1483 Statement ParseClassDeclaration(bool* ok); |
| 1438 Statement ParseBlock(bool* ok); | 1484 Statement ParseBlock(bool* ok); |
| 1439 Statement ParseVariableStatement(VariableDeclarationContext var_context, | 1485 Statement ParseVariableStatement(VariableDeclarationContext var_context, |
| 1440 bool* ok); | 1486 bool* ok); |
| 1441 Statement ParseVariableDeclarations(VariableDeclarationContext var_context, | 1487 Statement ParseVariableDeclarations(VariableDeclarationContext var_context, |
| 1442 VariableDeclarationProperties* decl_props, | 1488 VariableDeclarationProperties* decl_props, |
| 1443 int* num_decl, | 1489 int* num_decl, |
| 1444 bool* ok); | 1490 bool* ok); |
| 1445 Statement ParseExpressionOrLabelledStatement(bool* ok); | 1491 Statement ParseExpressionOrLabelledStatement(bool* ok); |
| 1446 Statement ParseIfStatement(bool* ok); | 1492 Statement ParseIfStatement(bool* ok); |
| 1447 Statement ParseContinueStatement(bool* ok); | 1493 Statement ParseContinueStatement(bool* ok); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1701 // 'this' | 1747 // 'this' |
| 1702 // 'null' | 1748 // 'null' |
| 1703 // 'true' | 1749 // 'true' |
| 1704 // 'false' | 1750 // 'false' |
| 1705 // Identifier | 1751 // Identifier |
| 1706 // Number | 1752 // Number |
| 1707 // String | 1753 // String |
| 1708 // ArrayLiteral | 1754 // ArrayLiteral |
| 1709 // ObjectLiteral | 1755 // ObjectLiteral |
| 1710 // RegExpLiteral | 1756 // RegExpLiteral |
| 1757 // ClassLiteral |
| 1711 // '(' Expression ')' | 1758 // '(' Expression ')' |
| 1712 | 1759 |
| 1713 int pos = peek_position(); | 1760 int pos = peek_position(); |
| 1714 ExpressionT result = this->EmptyExpression(); | 1761 ExpressionT result = this->EmptyExpression(); |
| 1715 Token::Value token = peek(); | 1762 Token::Value token = peek(); |
| 1716 switch (token) { | 1763 switch (token) { |
| 1717 case Token::THIS: { | 1764 case Token::THIS: { |
| 1718 Consume(Token::THIS); | 1765 Consume(Token::THIS); |
| 1719 result = this->ThisExpression(scope_, factory()); | 1766 result = this->ThisExpression(scope_, factory()); |
| 1720 break; | 1767 break; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 } else { | 1818 } else { |
| 1772 // Heuristically try to detect immediately called functions before | 1819 // Heuristically try to detect immediately called functions before |
| 1773 // seeing the call parentheses. | 1820 // seeing the call parentheses. |
| 1774 parenthesized_function_ = (peek() == Token::FUNCTION); | 1821 parenthesized_function_ = (peek() == Token::FUNCTION); |
| 1775 result = this->ParseExpression(true, CHECK_OK); | 1822 result = this->ParseExpression(true, CHECK_OK); |
| 1776 result->increase_parenthesization_level(); | 1823 result->increase_parenthesization_level(); |
| 1777 Expect(Token::RPAREN, CHECK_OK); | 1824 Expect(Token::RPAREN, CHECK_OK); |
| 1778 } | 1825 } |
| 1779 break; | 1826 break; |
| 1780 | 1827 |
| 1828 case Token::CLASS: { |
| 1829 Consume(Token::CLASS); |
| 1830 int class_token_position = position(); |
| 1831 IdentifierT name = this->EmptyIdentifier(); |
| 1832 bool is_strict_reserved_name = false; |
| 1833 Scanner::Location class_name_location = Scanner::Location::invalid(); |
| 1834 if (peek_any_identifier()) { |
| 1835 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, |
| 1836 CHECK_OK); |
| 1837 class_name_location = scanner()->location(); |
| 1838 } |
| 1839 result = this->ParseClassLiteral(name, class_name_location, |
| 1840 is_strict_reserved_name, |
| 1841 class_token_position, CHECK_OK); |
| 1842 break; |
| 1843 } |
| 1844 |
| 1781 case Token::MOD: | 1845 case Token::MOD: |
| 1782 if (allow_natives_syntax() || extension_ != NULL) { | 1846 if (allow_natives_syntax() || extension_ != NULL) { |
| 1783 result = this->ParseV8Intrinsic(CHECK_OK); | 1847 result = this->ParseV8Intrinsic(CHECK_OK); |
| 1784 break; | 1848 break; |
| 1785 } | 1849 } |
| 1786 // If we're not allowing special syntax we fall-through to the | 1850 // If we're not allowing special syntax we fall-through to the |
| 1787 // default case. | 1851 // default case. |
| 1788 | 1852 |
| 1789 default: { | 1853 default: { |
| 1790 Next(); | 1854 Next(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1841 | 1905 |
| 1842 // Update the scope information before the pre-parsing bailout. | 1906 // Update the scope information before the pre-parsing bailout. |
| 1843 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 1907 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
| 1844 | 1908 |
| 1845 return factory()->NewArrayLiteral(values, literal_index, pos); | 1909 return factory()->NewArrayLiteral(values, literal_index, pos); |
| 1846 } | 1910 } |
| 1847 | 1911 |
| 1848 | 1912 |
| 1849 template <class Traits> | 1913 template <class Traits> |
| 1850 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParsePropertyName( | 1914 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParsePropertyName( |
| 1851 bool* is_getter, bool* is_setter, bool* ok) { | 1915 bool* is_get, bool* is_set, bool* is_static, bool* ok) { |
| 1852 Token::Value next = peek(); | 1916 Token::Value next = peek(); |
| 1853 switch (next) { | 1917 switch (next) { |
| 1854 case Token::STRING: | 1918 case Token::STRING: |
| 1855 Consume(Token::STRING); | 1919 Consume(Token::STRING); |
| 1856 return this->GetSymbol(scanner_); | 1920 return this->GetSymbol(scanner_); |
| 1857 case Token::NUMBER: | 1921 case Token::NUMBER: |
| 1858 Consume(Token::NUMBER); | 1922 Consume(Token::NUMBER); |
| 1859 return this->GetNumberAsSymbol(scanner_); | 1923 return this->GetNumberAsSymbol(scanner_); |
| 1924 case Token::STATIC: |
| 1925 *is_static = true; |
| 1926 // Fall through. |
| 1860 default: | 1927 default: |
| 1861 return ParseIdentifierNameOrGetOrSet(is_getter, is_setter, | 1928 return ParseIdentifierNameOrGetOrSet(is_get, is_set, ok); |
| 1862 CHECK_OK_CUSTOM(EmptyIdentifier)); | |
| 1863 } | 1929 } |
| 1930 UNREACHABLE(); |
| 1931 return this->EmptyIdentifier(); |
| 1864 } | 1932 } |
| 1865 | 1933 |
| 1866 | 1934 |
| 1867 template <class Traits> | 1935 template <class Traits> |
| 1868 typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase< | 1936 typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase< |
| 1869 Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, bool* ok) { | 1937 Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, |
| 1938 bool in_class, bool is_static, bool* ok) { |
| 1870 // TODO(arv): Add support for concise generator methods. | 1939 // TODO(arv): Add support for concise generator methods. |
| 1871 ExpressionT value = this->EmptyExpression(); | 1940 ExpressionT value = this->EmptyExpression(); |
| 1872 bool is_getter = false; | 1941 bool is_get = false; |
| 1873 bool is_setter = false; | 1942 bool is_set = false; |
| 1943 bool name_is_static = false; |
| 1874 Token::Value name_token = peek(); | 1944 Token::Value name_token = peek(); |
| 1875 int next_pos = peek_position(); | 1945 int next_pos = peek_position(); |
| 1876 IdentifierT name = ParsePropertyName( | 1946 IdentifierT name = |
| 1877 &is_getter, &is_setter, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1947 ParsePropertyName(&is_get, &is_set, &name_is_static, |
| 1948 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1949 |
| 1878 if (fni_ != NULL) this->PushLiteralName(fni_, name); | 1950 if (fni_ != NULL) this->PushLiteralName(fni_, name); |
| 1879 | 1951 |
| 1880 if (peek() == Token::COLON) { | 1952 if (!in_class && peek() == Token::COLON) { |
| 1881 // PropertyDefinition : PropertyName ':' AssignmentExpression | 1953 // PropertyDefinition : PropertyName ':' AssignmentExpression |
| 1882 checker->CheckProperty(name_token, kValueProperty, | 1954 checker->CheckProperty(name_token, kValueProperty, |
| 1883 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1955 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1884 Consume(Token::COLON); | 1956 Consume(Token::COLON); |
| 1885 value = this->ParseAssignmentExpression( | 1957 value = this->ParseAssignmentExpression( |
| 1886 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1958 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1887 | 1959 |
| 1888 } else if (allow_harmony_object_literals_ && peek() == Token::LPAREN) { | 1960 } else if (allow_harmony_object_literals_ && peek() == Token::LPAREN) { |
| 1889 // Concise Method | 1961 // Concise Method |
| 1962 |
| 1963 if (is_static && this->IsPrototype(name)) { |
| 1964 ReportMessageAt(scanner()->location(), "static_prototype"); |
| 1965 *ok = false; |
| 1966 return this->EmptyObjectLiteralProperty(); |
| 1967 } |
| 1968 |
| 1890 checker->CheckProperty(name_token, kValueProperty, | 1969 checker->CheckProperty(name_token, kValueProperty, |
| 1891 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1970 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1892 value = this->ParseFunctionLiteral( | 1971 value = this->ParseFunctionLiteral( |
| 1893 name, scanner()->location(), | 1972 name, scanner()->location(), |
| 1894 false, // reserved words are allowed here | 1973 false, // reserved words are allowed here |
| 1895 FunctionKind::kConciseMethod, RelocInfo::kNoPosition, | 1974 FunctionKind::kConciseMethod, RelocInfo::kNoPosition, |
| 1896 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::NORMAL_ARITY, | 1975 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::NORMAL_ARITY, |
| 1897 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1976 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1898 | 1977 |
| 1899 } else if (is_getter || is_setter) { | 1978 } else if (in_class && name_is_static && !is_static) { |
| 1979 // static MethodDefinition |
| 1980 return ParsePropertyDefinition(checker, true, true, ok); |
| 1981 |
| 1982 } else if (is_get || is_set) { |
| 1900 // Accessor | 1983 // Accessor |
| 1901 bool dont_care = false; | 1984 bool dont_care = false; |
| 1902 name_token = peek(); | 1985 name_token = peek(); |
| 1903 name = ParsePropertyName(&dont_care, &dont_care, | 1986 name = ParsePropertyName(&dont_care, &dont_care, &dont_care, |
| 1904 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1987 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1988 |
| 1905 // Validate the property. | 1989 // Validate the property. |
| 1990 if (is_static && this->IsPrototype(name)) { |
| 1991 ReportMessageAt(scanner()->location(), "static_prototype"); |
| 1992 *ok = false; |
| 1993 return this->EmptyObjectLiteralProperty(); |
| 1994 } else if (in_class && !is_static && this->IsConstructor(name)) { |
| 1995 // ES6, spec draft rev 27, treats static get constructor as an error too. |
| 1996 // https://bugs.ecmascript.org/show_bug.cgi?id=3223 |
| 1997 // TODO(arv): Update when bug is resolved. |
| 1998 ReportMessageAt(scanner()->location(), "constructor_special_method"); |
| 1999 *ok = false; |
| 2000 return this->EmptyObjectLiteralProperty(); |
| 2001 } |
| 1906 checker->CheckProperty(name_token, | 2002 checker->CheckProperty(name_token, |
| 1907 is_getter ? kGetterProperty : kSetterProperty, | 2003 is_get ? kGetterProperty : kSetterProperty, |
| 1908 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2004 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2005 |
| 1909 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( | 2006 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( |
| 1910 name, scanner()->location(), | 2007 name, scanner()->location(), |
| 1911 false, // reserved words are allowed here | 2008 false, // reserved words are allowed here |
| 1912 FunctionKind::kNormalFunction, RelocInfo::kNoPosition, | 2009 FunctionKind::kNormalFunction, RelocInfo::kNoPosition, |
| 1913 FunctionLiteral::ANONYMOUS_EXPRESSION, | 2010 FunctionLiteral::ANONYMOUS_EXPRESSION, |
| 1914 is_getter ? FunctionLiteral::GETTER_ARITY | 2011 is_get ? FunctionLiteral::GETTER_ARITY : FunctionLiteral::SETTER_ARITY, |
| 1915 : FunctionLiteral::SETTER_ARITY, | |
| 1916 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2012 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 1917 return factory()->NewObjectLiteralProperty(is_getter, value, next_pos); | 2013 return factory()->NewObjectLiteralProperty(is_get, value, next_pos, |
| 2014 is_static); |
| 1918 } else { | 2015 } else { |
| 1919 Token::Value next = Next(); | 2016 Token::Value next = Next(); |
| 1920 ReportUnexpectedToken(next); | 2017 ReportUnexpectedToken(next); |
| 1921 *ok = false; | 2018 *ok = false; |
| 1922 return this->EmptyObjectLiteralProperty(); | 2019 return this->EmptyObjectLiteralProperty(); |
| 1923 } | 2020 } |
| 1924 | 2021 |
| 1925 uint32_t index; | 2022 uint32_t index; |
| 1926 LiteralT key = this->IsArrayIndex(name, &index) | 2023 LiteralT key = this->IsArrayIndex(name, &index) |
| 1927 ? factory()->NewNumberLiteral(index, next_pos) | 2024 ? factory()->NewNumberLiteral(index, next_pos) |
| 1928 : factory()->NewStringLiteral(name, next_pos); | 2025 : factory()->NewStringLiteral(name, next_pos); |
| 1929 | 2026 |
| 1930 return factory()->NewObjectLiteralProperty(key, value); | 2027 return factory()->NewObjectLiteralProperty(key, value, is_static); |
| 1931 } | 2028 } |
| 1932 | 2029 |
| 1933 | 2030 |
| 1934 template <class Traits> | 2031 template <class Traits> |
| 1935 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( | 2032 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( |
| 1936 bool* ok) { | 2033 bool* ok) { |
| 1937 // ObjectLiteral :: | 2034 // ObjectLiteral :: |
| 1938 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' | 2035 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' |
| 1939 | 2036 |
| 1940 int pos = peek_position(); | 2037 int pos = peek_position(); |
| 1941 typename Traits::Type::PropertyList properties = | 2038 typename Traits::Type::PropertyList properties = |
| 1942 this->NewPropertyList(4, zone_); | 2039 this->NewPropertyList(4, zone_); |
| 1943 int number_of_boilerplate_properties = 0; | 2040 int number_of_boilerplate_properties = 0; |
| 1944 bool has_function = false; | 2041 bool has_function = false; |
| 1945 | 2042 |
| 1946 ObjectLiteralChecker checker(this, strict_mode()); | 2043 ObjectLiteralChecker checker(this, strict_mode()); |
| 1947 | 2044 |
| 1948 Expect(Token::LBRACE, CHECK_OK); | 2045 Expect(Token::LBRACE, CHECK_OK); |
| 1949 | 2046 |
| 1950 while (peek() != Token::RBRACE) { | 2047 while (peek() != Token::RBRACE) { |
| 1951 if (fni_ != NULL) fni_->Enter(); | 2048 if (fni_ != NULL) fni_->Enter(); |
| 1952 | 2049 |
| 2050 const bool in_class = false; |
| 2051 const bool is_static = false; |
| 1953 ObjectLiteralPropertyT property = | 2052 ObjectLiteralPropertyT property = |
| 1954 this->ParsePropertyDefinition(&checker, CHECK_OK); | 2053 this->ParsePropertyDefinition(&checker, in_class, is_static, CHECK_OK); |
| 1955 | 2054 |
| 1956 // Mark top-level object literals that contain function literals and | 2055 // Mark top-level object literals that contain function literals and |
| 1957 // pretenure the literal so it can be added as a constant function | 2056 // pretenure the literal so it can be added as a constant function |
| 1958 // property. (Parser only.) | 2057 // property. (Parser only.) |
| 1959 this->CheckFunctionLiteralInsideTopLevelObjectLiteral(scope_, property, | 2058 this->CheckFunctionLiteralInsideTopLevelObjectLiteral(scope_, property, |
| 1960 &has_function); | 2059 &has_function); |
| 1961 | 2060 |
| 1962 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. | 2061 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. |
| 1963 if (this->IsBoilerplateProperty(property)) { | 2062 if (this->IsBoilerplateProperty(property)) { |
| 1964 number_of_boilerplate_properties++; | 2063 number_of_boilerplate_properties++; |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2393 } | 2492 } |
| 2394 // No 'new' or 'super' keyword. | 2493 // No 'new' or 'super' keyword. |
| 2395 return this->ParseMemberExpression(ok); | 2494 return this->ParseMemberExpression(ok); |
| 2396 } | 2495 } |
| 2397 | 2496 |
| 2398 | 2497 |
| 2399 template <class Traits> | 2498 template <class Traits> |
| 2400 typename ParserBase<Traits>::ExpressionT | 2499 typename ParserBase<Traits>::ExpressionT |
| 2401 ParserBase<Traits>::ParseMemberExpression(bool* ok) { | 2500 ParserBase<Traits>::ParseMemberExpression(bool* ok) { |
| 2402 // MemberExpression :: | 2501 // MemberExpression :: |
| 2403 // (PrimaryExpression | FunctionLiteral) | 2502 // (PrimaryExpression | FunctionLiteral | ClassLiteral) |
| 2404 // ('[' Expression ']' | '.' Identifier | Arguments)* | 2503 // ('[' Expression ']' | '.' Identifier | Arguments)* |
| 2405 | 2504 |
| 2406 // The '[' Expression ']' and '.' Identifier parts are parsed by | 2505 // The '[' Expression ']' and '.' Identifier parts are parsed by |
| 2407 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the | 2506 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the |
| 2408 // caller. | 2507 // caller. |
| 2409 | 2508 |
| 2410 // Parse the initial primary or function expression. | 2509 // Parse the initial primary or function expression. |
| 2411 ExpressionT result = this->EmptyExpression(); | 2510 ExpressionT result = this->EmptyExpression(); |
| 2412 if (peek() == Token::FUNCTION) { | 2511 if (peek() == Token::FUNCTION) { |
| 2413 Consume(Token::FUNCTION); | 2512 Consume(Token::FUNCTION); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2596 function_literal->set_function_token_position(start_pos); | 2695 function_literal->set_function_token_position(start_pos); |
| 2597 function_literal->set_ast_properties(&ast_properties); | 2696 function_literal->set_ast_properties(&ast_properties); |
| 2598 function_literal->set_dont_optimize_reason(dont_optimize_reason); | 2697 function_literal->set_dont_optimize_reason(dont_optimize_reason); |
| 2599 | 2698 |
| 2600 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); | 2699 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); |
| 2601 | 2700 |
| 2602 return function_literal; | 2701 return function_literal; |
| 2603 } | 2702 } |
| 2604 | 2703 |
| 2605 | 2704 |
| 2705 template <class Traits> |
| 2706 typename ParserBase<Traits>::ClassLiteralT |
| 2707 ParserBase<Traits>::ParseClassLiteral(IdentifierT name, |
| 2708 Scanner::Location class_name_location, |
| 2709 bool name_is_strict_reserved, int pos, |
| 2710 bool* ok) { |
| 2711 // All parts of a ClassDeclaration or a ClassExpression are strict code. |
| 2712 if (name_is_strict_reserved) { |
| 2713 ReportMessageAt(class_name_location, "unexpected_strict_reserved"); |
| 2714 *ok = false; |
| 2715 return this->EmptyClassLiteral(); |
| 2716 } |
| 2717 if (this->IsEvalOrArguments(name)) { |
| 2718 ReportMessageAt(class_name_location, "strict_eval_arguments"); |
| 2719 *ok = false; |
| 2720 return this->EmptyClassLiteral(); |
| 2721 } |
| 2722 |
| 2723 // TODO(arv): Implement scopes and name binding in class body only. |
| 2724 // TODO(arv): Maybe add CLASS_SCOPE? |
| 2725 typename Traits::Type::ScopePtr extends_scope = |
| 2726 this->NewScope(scope_, BLOCK_SCOPE); |
| 2727 FunctionState extends_function_state( |
| 2728 &function_state_, &scope_, &extends_scope, zone(), |
| 2729 this->ast_value_factory(), ast_node_id_gen_); |
| 2730 scope_->SetStrictMode(STRICT); |
| 2731 scope_->SetScopeName(name); |
| 2732 |
| 2733 ExpressionT extends = this->EmptyExpression(); |
| 2734 if (Check(Token::EXTENDS)) { |
| 2735 extends = |
| 2736 this->ParseLeftHandSideExpression(CHECK_OK_CUSTOM(EmptyClassLiteral)); |
| 2737 } |
| 2738 |
| 2739 ObjectLiteralChecker checker(this, STRICT); |
| 2740 typename Traits::Type::PropertyList properties = |
| 2741 this->NewPropertyList(4, zone_); |
| 2742 FunctionLiteralT constructor = this->EmptyFunctionLiteral(); |
| 2743 |
| 2744 Expect(Token::LBRACE, CHECK_OK_CUSTOM(EmptyClassLiteral)); |
| 2745 while (peek() != Token::RBRACE) { |
| 2746 if (Check(Token::SEMICOLON)) continue; |
| 2747 if (fni_ != NULL) fni_->Enter(); |
| 2748 |
| 2749 const bool in_class = true; |
| 2750 const bool is_static = false; |
| 2751 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( |
| 2752 &checker, in_class, is_static, CHECK_OK_CUSTOM(EmptyClassLiteral)); |
| 2753 |
| 2754 properties->Add(property, zone()); |
| 2755 |
| 2756 if (fni_ != NULL) { |
| 2757 fni_->Infer(); |
| 2758 fni_->Leave(); |
| 2759 } |
| 2760 } |
| 2761 Expect(Token::RBRACE, CHECK_OK_CUSTOM(EmptyClassLiteral)); |
| 2762 |
| 2763 return factory()->NewClassLiteral(name, extends, constructor, properties, |
| 2764 this->ast_value_factory(), pos); |
| 2765 } |
| 2766 |
| 2767 |
| 2606 template <typename Traits> | 2768 template <typename Traits> |
| 2607 typename ParserBase<Traits>::ExpressionT | 2769 typename ParserBase<Traits>::ExpressionT |
| 2608 ParserBase<Traits>::CheckAndRewriteReferenceExpression( | 2770 ParserBase<Traits>::CheckAndRewriteReferenceExpression( |
| 2609 ExpressionT expression, | 2771 ExpressionT expression, |
| 2610 Scanner::Location location, const char* message, bool* ok) { | 2772 Scanner::Location location, const char* message, bool* ok) { |
| 2611 if (strict_mode() == STRICT && this->IsIdentifier(expression) && | 2773 if (strict_mode() == STRICT && this->IsIdentifier(expression) && |
| 2612 this->IsEvalOrArguments(this->AsIdentifier(expression))) { | 2774 this->IsEvalOrArguments(this->AsIdentifier(expression))) { |
| 2613 this->ReportMessageAt(location, "strict_eval_arguments", false); | 2775 this->ReportMessageAt(location, "strict_eval_arguments", false); |
| 2614 *ok = false; | 2776 *ok = false; |
| 2615 return this->EmptyExpression(); | 2777 return this->EmptyExpression(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2655 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 2817 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
| 2656 // Both accessors of the same type. | 2818 // Both accessors of the same type. |
| 2657 parser()->ReportMessage("accessor_get_set"); | 2819 parser()->ReportMessage("accessor_get_set"); |
| 2658 } | 2820 } |
| 2659 *ok = false; | 2821 *ok = false; |
| 2660 } | 2822 } |
| 2661 } | 2823 } |
| 2662 } } // v8::internal | 2824 } } // v8::internal |
| 2663 | 2825 |
| 2664 #endif // V8_PREPARSER_H | 2826 #endif // V8_PREPARSER_H |
| OLD | NEW |