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