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; } | 635 bool IsEvalOrArguments() const { return type_ >= kEvalIdentifier; } |
marja
2014/09/11 09:40:58
This looks incorrect now, because you're adding mo
arv (Not doing code reviews)
2014/09/11 18:24:42
Oops.
| |
622 bool IsYield() const { return type_ == kYieldIdentifier; } | 636 bool IsYield() const { return type_ == kYieldIdentifier; } |
637 bool IsPrototype() const { return type_ >= kPrototypeIdentifier; } | |
marja
2014/09/11 09:40:58
Why >= ? And in case somebody adds new enum values
arv (Not doing code reviews)
2014/09/11 18:24:42
Ooops here too.
| |
638 bool IsConstructor() const { return type_ >= kConstructorIdentifier; } | |
623 bool IsFutureReserved() const { return type_ == kFutureReservedIdentifier; } | 639 bool IsFutureReserved() const { return type_ == kFutureReservedIdentifier; } |
624 bool IsFutureStrictReserved() const { | 640 bool IsFutureStrictReserved() const { |
625 return type_ == kFutureStrictReservedIdentifier; | 641 return type_ == kFutureStrictReservedIdentifier; |
626 } | 642 } |
627 bool IsValidStrictVariable() const { return type_ == kUnknownIdentifier; } | 643 bool IsValidStrictVariable() const { return type_ == kUnknownIdentifier; } |
628 | 644 |
629 // Allow identifier->name()[->length()] to work. The preparser | 645 // Allow identifier->name()[->length()] to work. The preparser |
630 // does not need the actual positions/lengths of the identifiers. | 646 // does not need the actual positions/lengths of the identifiers. |
631 const PreParserIdentifier* operator->() const { return this; } | 647 const PreParserIdentifier* operator->() const { return this; } |
632 const PreParserIdentifier raw_name() const { return *this; } | 648 const PreParserIdentifier raw_name() const { return *this; } |
633 | 649 |
634 int position() const { return 0; } | 650 int position() const { return 0; } |
635 int length() const { return 0; } | 651 int length() const { return 0; } |
636 | 652 |
637 private: | 653 private: |
638 enum Type { | 654 enum Type { |
639 kUnknownIdentifier, | 655 kUnknownIdentifier, |
640 kFutureReservedIdentifier, | 656 kFutureReservedIdentifier, |
641 kFutureStrictReservedIdentifier, | 657 kFutureStrictReservedIdentifier, |
642 kLetIdentifier, | 658 kLetIdentifier, |
643 kYieldIdentifier, | 659 kYieldIdentifier, |
644 kEvalIdentifier, | 660 kEvalIdentifier, |
645 kArgumentsIdentifier | 661 kArgumentsIdentifier, |
662 kPrototypeIdentifier, | |
663 kConstructorIdentifier | |
646 }; | 664 }; |
647 explicit PreParserIdentifier(Type type) : type_(type) {} | 665 explicit PreParserIdentifier(Type type) : type_(type) {} |
648 Type type_; | 666 Type type_; |
649 | 667 |
650 friend class PreParserExpression; | 668 friend class PreParserExpression; |
651 friend class PreParserScope; | 669 friend class PreParserScope; |
652 }; | 670 }; |
653 | 671 |
654 | 672 |
655 // Bits 0 and 1 are used to identify the type of expression: | 673 // Bits 0 and 1 are used to identify the type of expression: |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
862 class PreParserStatement { | 880 class PreParserStatement { |
863 public: | 881 public: |
864 static PreParserStatement Default() { | 882 static PreParserStatement Default() { |
865 return PreParserStatement(kUnknownStatement); | 883 return PreParserStatement(kUnknownStatement); |
866 } | 884 } |
867 | 885 |
868 static PreParserStatement FunctionDeclaration() { | 886 static PreParserStatement FunctionDeclaration() { |
869 return PreParserStatement(kFunctionDeclaration); | 887 return PreParserStatement(kFunctionDeclaration); |
870 } | 888 } |
871 | 889 |
890 static PreParserStatement ClassDeclaration() { | |
891 return PreParserStatement(kClassDeclaration); | |
892 } | |
893 | |
872 // Creates expression statement from expression. | 894 // Creates expression statement from expression. |
873 // Preserves being an unparenthesized string literal, possibly | 895 // Preserves being an unparenthesized string literal, possibly |
874 // "use strict". | 896 // "use strict". |
875 static PreParserStatement ExpressionStatement( | 897 static PreParserStatement ExpressionStatement( |
876 PreParserExpression expression) { | 898 PreParserExpression expression) { |
877 if (expression.IsUseStrictLiteral()) { | 899 if (expression.IsUseStrictLiteral()) { |
878 return PreParserStatement(kUseStrictExpressionStatement); | 900 return PreParserStatement(kUseStrictExpressionStatement); |
879 } | 901 } |
880 if (expression.IsStringLiteral()) { | 902 if (expression.IsStringLiteral()) { |
881 return PreParserStatement(kStringLiteralExpressionStatement); | 903 return PreParserStatement(kStringLiteralExpressionStatement); |
882 } | 904 } |
883 return Default(); | 905 return Default(); |
884 } | 906 } |
885 | 907 |
886 bool IsStringLiteral() { | 908 bool IsStringLiteral() { |
887 return code_ == kStringLiteralExpressionStatement; | 909 return code_ == kStringLiteralExpressionStatement; |
888 } | 910 } |
889 | 911 |
890 bool IsUseStrictLiteral() { | 912 bool IsUseStrictLiteral() { |
891 return code_ == kUseStrictExpressionStatement; | 913 return code_ == kUseStrictExpressionStatement; |
892 } | 914 } |
893 | 915 |
894 bool IsFunctionDeclaration() { | 916 bool IsFunctionDeclaration() { |
895 return code_ == kFunctionDeclaration; | 917 return code_ == kFunctionDeclaration; |
896 } | 918 } |
897 | 919 |
920 bool IsClassDeclaration() { return code_ == kClassDeclaration; } | |
921 | |
898 private: | 922 private: |
899 enum Type { | 923 enum Type { |
900 kUnknownStatement, | 924 kUnknownStatement, |
901 kStringLiteralExpressionStatement, | 925 kStringLiteralExpressionStatement, |
902 kUseStrictExpressionStatement, | 926 kUseStrictExpressionStatement, |
903 kFunctionDeclaration | 927 kFunctionDeclaration, |
928 kClassDeclaration | |
904 }; | 929 }; |
905 | 930 |
906 explicit PreParserStatement(Type code) : code_(code) {} | 931 explicit PreParserStatement(Type code) : code_(code) {} |
907 Type code_; | 932 Type code_; |
908 }; | 933 }; |
909 | 934 |
910 | 935 |
911 | 936 |
912 // PreParserStatementList doesn't actually store the statements because | 937 // PreParserStatementList doesn't actually store the statements because |
913 // the PreParser does not need them. | 938 // the PreParser does not need them. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
968 int pos) { | 993 int pos) { |
969 return PreParserExpression::Default(); | 994 return PreParserExpression::Default(); |
970 } | 995 } |
971 PreParserExpression NewArrayLiteral(PreParserExpressionList values, | 996 PreParserExpression NewArrayLiteral(PreParserExpressionList values, |
972 int literal_index, | 997 int literal_index, |
973 int pos) { | 998 int pos) { |
974 return PreParserExpression::Default(); | 999 return PreParserExpression::Default(); |
975 } | 1000 } |
976 PreParserExpression NewObjectLiteralProperty(bool is_getter, | 1001 PreParserExpression NewObjectLiteralProperty(bool is_getter, |
977 PreParserExpression value, | 1002 PreParserExpression value, |
978 int pos) { | 1003 int pos, bool is_static) { |
979 return PreParserExpression::Default(); | 1004 return PreParserExpression::Default(); |
980 } | 1005 } |
981 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, | 1006 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, |
982 PreParserExpression value) { | 1007 PreParserExpression value, |
1008 bool is_static) { | |
983 return PreParserExpression::Default(); | 1009 return PreParserExpression::Default(); |
984 } | 1010 } |
985 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, | 1011 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, |
986 int literal_index, | 1012 int literal_index, |
987 int boilerplate_properties, | 1013 int boilerplate_properties, |
988 bool has_function, | 1014 bool has_function, |
989 int pos) { | 1015 int pos) { |
990 return PreParserExpression::Default(); | 1016 return PreParserExpression::Default(); |
991 } | 1017 } |
992 PreParserExpression NewVariableProxy(void* generator_variable) { | 1018 PreParserExpression NewVariableProxy(void* generator_variable) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1058 const PreParserScope& scope, PreParserStatementList body, | 1084 const PreParserScope& scope, PreParserStatementList body, |
1059 int materialized_literal_count, int expected_property_count, | 1085 int materialized_literal_count, int expected_property_count, |
1060 int handler_count, int parameter_count, | 1086 int handler_count, int parameter_count, |
1061 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 1087 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
1062 FunctionLiteral::FunctionType function_type, | 1088 FunctionLiteral::FunctionType function_type, |
1063 FunctionLiteral::IsFunctionFlag is_function, | 1089 FunctionLiteral::IsFunctionFlag is_function, |
1064 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, | 1090 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, |
1065 int position) { | 1091 int position) { |
1066 return PreParserExpression::Default(); | 1092 return PreParserExpression::Default(); |
1067 } | 1093 } |
1094 PreParserExpression NewClassLiteral(PreParserIdentifier name, | |
1095 PreParserExpression extends, | |
1096 PreParserExpressionList properties, | |
1097 AstValueFactory* ast_value_factory, | |
1098 int position) { | |
1099 return PreParserExpression::Default(); | |
1100 } | |
1068 | 1101 |
1069 // Return the object itself as AstVisitor and implement the needed | 1102 // Return the object itself as AstVisitor and implement the needed |
1070 // dummy method right in this class. | 1103 // dummy method right in this class. |
1071 PreParserFactory* visitor() { return this; } | 1104 PreParserFactory* visitor() { return this; } |
1072 BailoutReason dont_optimize_reason() { return kNoReason; } | 1105 BailoutReason dont_optimize_reason() { return kNoReason; } |
1073 int* ast_properties() { | 1106 int* ast_properties() { |
1074 static int dummy = 42; | 1107 static int dummy = 42; |
1075 return &dummy; | 1108 return &dummy; |
1076 } | 1109 } |
1077 }; | 1110 }; |
(...skipping 18 matching lines...) Expand all Loading... | |
1096 typedef void Zone; | 1129 typedef void Zone; |
1097 | 1130 |
1098 typedef int AstProperties; | 1131 typedef int AstProperties; |
1099 typedef Vector<PreParserIdentifier> ParameterIdentifierVector; | 1132 typedef Vector<PreParserIdentifier> ParameterIdentifierVector; |
1100 | 1133 |
1101 // Return types for traversing functions. | 1134 // Return types for traversing functions. |
1102 typedef PreParserIdentifier Identifier; | 1135 typedef PreParserIdentifier Identifier; |
1103 typedef PreParserExpression Expression; | 1136 typedef PreParserExpression Expression; |
1104 typedef PreParserExpression YieldExpression; | 1137 typedef PreParserExpression YieldExpression; |
1105 typedef PreParserExpression FunctionLiteral; | 1138 typedef PreParserExpression FunctionLiteral; |
1139 typedef PreParserExpression ClassLiteral; | |
1106 typedef PreParserExpression ObjectLiteralProperty; | 1140 typedef PreParserExpression ObjectLiteralProperty; |
1107 typedef PreParserExpression Literal; | 1141 typedef PreParserExpression Literal; |
1108 typedef PreParserExpressionList ExpressionList; | 1142 typedef PreParserExpressionList ExpressionList; |
1109 typedef PreParserExpressionList PropertyList; | 1143 typedef PreParserExpressionList PropertyList; |
1110 typedef PreParserStatementList StatementList; | 1144 typedef PreParserStatementList StatementList; |
1111 | 1145 |
1112 // For constructing objects returned by the traversing functions. | 1146 // For constructing objects returned by the traversing functions. |
1113 typedef PreParserFactory Factory; | 1147 typedef PreParserFactory Factory; |
1114 }; | 1148 }; |
1115 | 1149 |
1116 class Checkpoint; | 1150 class Checkpoint; |
1117 | 1151 |
1118 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} | 1152 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} |
1119 | 1153 |
1120 // Custom operations executed when FunctionStates are created and | 1154 // Custom operations executed when FunctionStates are created and |
1121 // destructed. (The PreParser doesn't need to do anything.) | 1155 // destructed. (The PreParser doesn't need to do anything.) |
1122 template <typename FunctionState> | 1156 template <typename FunctionState> |
1123 static void SetUpFunctionState(FunctionState* function_state) {} | 1157 static void SetUpFunctionState(FunctionState* function_state) {} |
1124 template <typename FunctionState> | 1158 template <typename FunctionState> |
1125 static void TearDownFunctionState(FunctionState* function_state) {} | 1159 static void TearDownFunctionState(FunctionState* function_state) {} |
1126 | 1160 |
1127 // Helper functions for recursive descent. | 1161 // Helper functions for recursive descent. |
1128 static bool IsEvalOrArguments(PreParserIdentifier identifier) { | 1162 static bool IsEvalOrArguments(PreParserIdentifier identifier) { |
1129 return identifier.IsEvalOrArguments(); | 1163 return identifier.IsEvalOrArguments(); |
1130 } | 1164 } |
1131 | 1165 |
1166 static bool IsPrototype(PreParserIdentifier identifier) { | |
1167 return identifier.IsPrototype(); | |
1168 } | |
1169 | |
1170 static bool IsConstructor(PreParserIdentifier identifier) { | |
1171 return identifier.IsConstructor(); | |
1172 } | |
1173 | |
1132 // Returns true if the expression is of type "this.foo". | 1174 // Returns true if the expression is of type "this.foo". |
1133 static bool IsThisProperty(PreParserExpression expression) { | 1175 static bool IsThisProperty(PreParserExpression expression) { |
1134 return expression.IsThisProperty(); | 1176 return expression.IsThisProperty(); |
1135 } | 1177 } |
1136 | 1178 |
1137 static bool IsIdentifier(PreParserExpression expression) { | 1179 static bool IsIdentifier(PreParserExpression expression) { |
1138 return expression.IsIdentifier(); | 1180 return expression.IsIdentifier(); |
1139 } | 1181 } |
1140 | 1182 |
1141 static PreParserIdentifier AsIdentifier(PreParserExpression expression) { | 1183 static PreParserIdentifier AsIdentifier(PreParserExpression expression) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1242 } | 1284 } |
1243 static PreParserExpression EmptyArrowParamList() { | 1285 static PreParserExpression EmptyArrowParamList() { |
1244 return PreParserExpression::EmptyArrowParamList(); | 1286 return PreParserExpression::EmptyArrowParamList(); |
1245 } | 1287 } |
1246 static PreParserExpression EmptyLiteral() { | 1288 static PreParserExpression EmptyLiteral() { |
1247 return PreParserExpression::Default(); | 1289 return PreParserExpression::Default(); |
1248 } | 1290 } |
1249 static PreParserExpression EmptyObjectLiteralProperty() { | 1291 static PreParserExpression EmptyObjectLiteralProperty() { |
1250 return PreParserExpression::Default(); | 1292 return PreParserExpression::Default(); |
1251 } | 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_); |
1925 | |
1861 case Token::NUMBER: | 1926 case Token::NUMBER: |
1862 Consume(Token::NUMBER); | 1927 Consume(Token::NUMBER); |
1863 return this->GetNumberAsSymbol(scanner_); | 1928 return this->GetNumberAsSymbol(scanner_); |
1929 | |
1930 case Token::STATIC: | |
1931 *is_static = true; | |
1932 // Fall through. | |
1933 | |
1864 default: | 1934 default: |
1865 return ParseIdentifierNameOrGetOrSet(is_getter, is_setter, | 1935 return ParseIdentifierNameOrGetOrSet(is_get, is_set, ok); |
1866 CHECK_OK_CUSTOM(EmptyIdentifier)); | |
1867 } | 1936 } |
1937 | |
1938 UNREACHABLE(); | |
1939 return this->EmptyIdentifier(); | |
1868 } | 1940 } |
1869 | 1941 |
1870 | 1942 |
1871 template <class Traits> | 1943 template <class Traits> |
1872 typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase< | 1944 typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase< |
1873 Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, bool* ok) { | 1945 Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, |
1946 bool in_class, bool is_static, bool* ok) { | |
1874 // TODO(arv): Add support for concise generator methods. | 1947 // TODO(arv): Add support for concise generator methods. |
1875 ExpressionT value = this->EmptyExpression(); | 1948 ExpressionT value = this->EmptyExpression(); |
1876 bool is_getter = false; | 1949 bool is_get = false; |
1877 bool is_setter = false; | 1950 bool is_set = false; |
1951 bool name_is_static = false; | |
1878 Token::Value name_token = peek(); | 1952 Token::Value name_token = peek(); |
1879 int next_pos = peek_position(); | 1953 int next_pos = peek_position(); |
1880 IdentifierT name = ParsePropertyName( | 1954 IdentifierT name = |
1881 &is_getter, &is_setter, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1955 ParsePropertyName(&is_get, &is_set, &name_is_static, |
1956 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | |
1957 | |
1882 if (fni_ != NULL) this->PushLiteralName(fni_, name); | 1958 if (fni_ != NULL) this->PushLiteralName(fni_, name); |
1883 | 1959 |
1884 if (peek() == Token::COLON) { | 1960 if (!in_class && peek() == Token::COLON) { |
1885 // PropertyDefinition : PropertyName ':' AssignmentExpression | 1961 // PropertyDefinition : PropertyName ':' AssignmentExpression |
1886 checker->CheckProperty(name_token, kValueProperty, | 1962 checker->CheckProperty(name_token, kValueProperty, |
1887 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1963 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1888 Consume(Token::COLON); | 1964 Consume(Token::COLON); |
1889 value = this->ParseAssignmentExpression( | 1965 value = this->ParseAssignmentExpression( |
1890 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1966 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1891 | 1967 |
1892 } else if (allow_harmony_object_literals_ && peek() == Token::LPAREN) { | 1968 } else if (allow_harmony_object_literals_ && peek() == Token::LPAREN) { |
1893 // Concise Method | 1969 // Concise Method |
1970 | |
1971 if (is_static && this->IsPrototype(name)) { | |
1972 ReportMessageAt(scanner()->location(), "static_prototype"); | |
1973 *ok = false; | |
1974 return this->EmptyObjectLiteralProperty(); | |
1975 } | |
1976 | |
1894 checker->CheckProperty(name_token, kValueProperty, | 1977 checker->CheckProperty(name_token, kValueProperty, |
1895 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1978 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1896 value = this->ParseFunctionLiteral( | 1979 value = this->ParseFunctionLiteral( |
1897 name, scanner()->location(), | 1980 name, scanner()->location(), |
1898 false, // reserved words are allowed here | 1981 false, // reserved words are allowed here |
1899 FunctionKind::kConciseMethod, RelocInfo::kNoPosition, | 1982 FunctionKind::kConciseMethod, RelocInfo::kNoPosition, |
1900 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::NORMAL_ARITY, | 1983 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::NORMAL_ARITY, |
1901 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1984 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1902 | 1985 |
1903 } else if (is_getter || is_setter) { | 1986 } else if (in_class && name_is_static && !is_static) { |
1987 // static MethodDefinition | |
1988 return ParsePropertyDefinition(checker, true, true, ok); | |
1989 | |
1990 } else if (is_get || is_set) { | |
1904 // Accessor | 1991 // Accessor |
1905 bool dont_care = false; | 1992 bool dont_care = false; |
1906 name_token = peek(); | 1993 name_token = peek(); |
1907 name = ParsePropertyName(&dont_care, &dont_care, | 1994 name = ParsePropertyName(&dont_care, &dont_care, &dont_care, |
1908 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1995 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1996 | |
1909 // Validate the property. | 1997 // Validate the property. |
1998 if (is_static && this->IsPrototype(name)) { | |
1999 ReportMessageAt(scanner()->location(), "static_prototype"); | |
2000 *ok = false; | |
2001 return this->EmptyObjectLiteralProperty(); | |
2002 } else if (this->IsConstructor(name)) { | |
2003 ReportMessageAt(scanner()->location(), "constructor_special_method"); | |
2004 *ok = false; | |
2005 return this->EmptyObjectLiteralProperty(); | |
2006 } | |
1910 checker->CheckProperty(name_token, | 2007 checker->CheckProperty(name_token, |
1911 is_getter ? kGetterProperty : kSetterProperty, | 2008 is_get ? kGetterProperty : kSetterProperty, |
1912 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2009 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2010 | |
1913 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( | 2011 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( |
1914 name, scanner()->location(), | 2012 name, scanner()->location(), |
1915 false, // reserved words are allowed here | 2013 false, // reserved words are allowed here |
1916 FunctionKind::kNormalFunction, RelocInfo::kNoPosition, | 2014 FunctionKind::kNormalFunction, RelocInfo::kNoPosition, |
1917 FunctionLiteral::ANONYMOUS_EXPRESSION, | 2015 FunctionLiteral::ANONYMOUS_EXPRESSION, |
1918 is_getter ? FunctionLiteral::GETTER_ARITY | 2016 is_get ? FunctionLiteral::GETTER_ARITY : FunctionLiteral::SETTER_ARITY, |
1919 : FunctionLiteral::SETTER_ARITY, | |
1920 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2017 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1921 return factory()->NewObjectLiteralProperty(is_getter, value, next_pos); | 2018 return factory()->NewObjectLiteralProperty(is_get, value, next_pos, |
2019 is_static); | |
1922 } else { | 2020 } else { |
1923 Token::Value next = Next(); | 2021 Token::Value next = Next(); |
1924 ReportUnexpectedToken(next); | 2022 ReportUnexpectedToken(next); |
1925 *ok = false; | 2023 *ok = false; |
1926 return this->EmptyObjectLiteralProperty(); | 2024 return this->EmptyObjectLiteralProperty(); |
1927 } | 2025 } |
1928 | 2026 |
1929 uint32_t index; | 2027 uint32_t index; |
1930 LiteralT key = this->IsArrayIndex(name, &index) | 2028 LiteralT key = this->IsArrayIndex(name, &index) |
1931 ? factory()->NewNumberLiteral(index, next_pos) | 2029 ? factory()->NewNumberLiteral(index, next_pos) |
1932 : factory()->NewStringLiteral(name, next_pos); | 2030 : factory()->NewStringLiteral(name, next_pos); |
1933 | 2031 |
1934 return factory()->NewObjectLiteralProperty(key, value); | 2032 return factory()->NewObjectLiteralProperty(key, value, is_static); |
1935 } | 2033 } |
1936 | 2034 |
1937 | 2035 |
1938 template <class Traits> | 2036 template <class Traits> |
1939 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( | 2037 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( |
1940 bool* ok) { | 2038 bool* ok) { |
1941 // ObjectLiteral :: | 2039 // ObjectLiteral :: |
1942 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' | 2040 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' |
1943 | 2041 |
1944 int pos = peek_position(); | 2042 int pos = peek_position(); |
1945 typename Traits::Type::PropertyList properties = | 2043 typename Traits::Type::PropertyList properties = |
1946 this->NewPropertyList(4, zone_); | 2044 this->NewPropertyList(4, zone_); |
1947 int number_of_boilerplate_properties = 0; | 2045 int number_of_boilerplate_properties = 0; |
1948 bool has_function = false; | 2046 bool has_function = false; |
1949 | 2047 |
1950 ObjectLiteralChecker checker(this, strict_mode()); | 2048 ObjectLiteralChecker checker(this, strict_mode()); |
1951 | 2049 |
1952 Expect(Token::LBRACE, CHECK_OK); | 2050 Expect(Token::LBRACE, CHECK_OK); |
1953 | 2051 |
2052 const bool in_class = false; | |
2053 const bool is_static = false; | |
1954 while (peek() != Token::RBRACE) { | 2054 while (peek() != Token::RBRACE) { |
1955 if (fni_ != NULL) fni_->Enter(); | 2055 if (fni_ != NULL) fni_->Enter(); |
1956 | 2056 |
1957 ObjectLiteralPropertyT property = | 2057 ObjectLiteralPropertyT property = |
1958 this->ParsePropertyDefinition(&checker, CHECK_OK); | 2058 this->ParsePropertyDefinition(&checker, in_class, is_static, CHECK_OK); |
1959 | 2059 |
1960 // Mark top-level object literals that contain function literals and | 2060 // Mark top-level object literals that contain function literals and |
1961 // pretenure the literal so it can be added as a constant function | 2061 // pretenure the literal so it can be added as a constant function |
1962 // property. (Parser only.) | 2062 // property. (Parser only.) |
1963 this->CheckFunctionLiteralInsideTopLevelObjectLiteral(scope_, property, | 2063 this->CheckFunctionLiteralInsideTopLevelObjectLiteral(scope_, property, |
1964 &has_function); | 2064 &has_function); |
1965 | 2065 |
1966 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. | 2066 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. |
1967 if (this->IsBoilerplateProperty(property)) { | 2067 if (this->IsBoilerplateProperty(property)) { |
1968 number_of_boilerplate_properties++; | 2068 number_of_boilerplate_properties++; |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2397 } | 2497 } |
2398 // No 'new' or 'super' keyword. | 2498 // No 'new' or 'super' keyword. |
2399 return this->ParseMemberExpression(ok); | 2499 return this->ParseMemberExpression(ok); |
2400 } | 2500 } |
2401 | 2501 |
2402 | 2502 |
2403 template <class Traits> | 2503 template <class Traits> |
2404 typename ParserBase<Traits>::ExpressionT | 2504 typename ParserBase<Traits>::ExpressionT |
2405 ParserBase<Traits>::ParseMemberExpression(bool* ok) { | 2505 ParserBase<Traits>::ParseMemberExpression(bool* ok) { |
2406 // MemberExpression :: | 2506 // MemberExpression :: |
2407 // (PrimaryExpression | FunctionLiteral) | 2507 // (PrimaryExpression | FunctionLiteral | ClassLiteral) |
2408 // ('[' Expression ']' | '.' Identifier | Arguments)* | 2508 // ('[' Expression ']' | '.' Identifier | Arguments)* |
2409 | 2509 |
2410 // The '[' Expression ']' and '.' Identifier parts are parsed by | 2510 // The '[' Expression ']' and '.' Identifier parts are parsed by |
2411 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the | 2511 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the |
2412 // caller. | 2512 // caller. |
2413 | 2513 |
2414 // Parse the initial primary or function expression. | 2514 // Parse the initial primary or function expression. |
2415 ExpressionT result = this->EmptyExpression(); | 2515 ExpressionT result = this->EmptyExpression(); |
2416 if (peek() == Token::FUNCTION) { | 2516 if (peek() == Token::FUNCTION) { |
2417 Consume(Token::FUNCTION); | 2517 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); | 2700 function_literal->set_function_token_position(start_pos); |
2601 function_literal->set_ast_properties(&ast_properties); | 2701 function_literal->set_ast_properties(&ast_properties); |
2602 function_literal->set_dont_optimize_reason(dont_optimize_reason); | 2702 function_literal->set_dont_optimize_reason(dont_optimize_reason); |
2603 | 2703 |
2604 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); | 2704 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); |
2605 | 2705 |
2606 return function_literal; | 2706 return function_literal; |
2607 } | 2707 } |
2608 | 2708 |
2609 | 2709 |
2710 template <class Traits> | |
2711 typename ParserBase<Traits>::ClassLiteralT | |
2712 ParserBase<Traits>::ParseClassLiteral(IdentifierT name, | |
2713 Scanner::Location class_name_location, | |
2714 bool name_is_strict_reserved, int pos, | |
2715 bool* ok) { | |
2716 // Classes are always strict. | |
2717 if (name_is_strict_reserved) { | |
2718 ReportMessageAt(class_name_location, "unexpected_strict_reserved"); | |
2719 *ok = false; | |
2720 return this->EmptyClassLiteral(); | |
2721 } | |
2722 if (this->IsEvalOrArguments(name)) { | |
2723 ReportMessageAt(class_name_location, "strict_eval_arguments"); | |
2724 *ok = false; | |
2725 return this->EmptyClassLiteral(); | |
2726 } | |
2727 | |
2728 ExpressionT extends = this->EmptyExpression(); | |
2729 if (Check(Token::EXTENDS)) { | |
2730 extends = | |
2731 this->ParseLeftHandSideExpression(CHECK_OK_CUSTOM(EmptyClassLiteral)); | |
2732 } | |
2733 | |
2734 ObjectLiteralChecker checker(this, strict_mode()); | |
2735 const bool in_class = true; | |
2736 const bool is_static = false; | |
2737 typename Traits::Type::PropertyList properties = | |
2738 this->NewPropertyList(4, zone_); | |
2739 | |
2740 Expect(Token::LBRACE, CHECK_OK_CUSTOM(EmptyClassLiteral)); | |
2741 while (peek() != Token::RBRACE) { | |
2742 if (Check(Token::SEMICOLON)) continue; | |
2743 if (fni_ != NULL) fni_->Enter(); | |
2744 | |
2745 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( | |
2746 &checker, in_class, is_static, CHECK_OK_CUSTOM(EmptyClassLiteral)); | |
2747 properties->Add(property, zone()); | |
2748 | |
2749 if (fni_ != NULL) { | |
2750 fni_->Infer(); | |
2751 fni_->Leave(); | |
2752 } | |
2753 } | |
2754 Expect(Token::RBRACE, CHECK_OK_CUSTOM(EmptyClassLiteral)); | |
2755 | |
2756 return factory()->NewClassLiteral(name, extends, properties, | |
2757 this->ast_value_factory(), pos); | |
2758 } | |
2759 | |
2760 | |
2610 template <typename Traits> | 2761 template <typename Traits> |
2611 typename ParserBase<Traits>::ExpressionT | 2762 typename ParserBase<Traits>::ExpressionT |
2612 ParserBase<Traits>::CheckAndRewriteReferenceExpression( | 2763 ParserBase<Traits>::CheckAndRewriteReferenceExpression( |
2613 ExpressionT expression, | 2764 ExpressionT expression, |
2614 Scanner::Location location, const char* message, bool* ok) { | 2765 Scanner::Location location, const char* message, bool* ok) { |
2615 if (strict_mode() == STRICT && this->IsIdentifier(expression) && | 2766 if (strict_mode() == STRICT && this->IsIdentifier(expression) && |
2616 this->IsEvalOrArguments(this->AsIdentifier(expression))) { | 2767 this->IsEvalOrArguments(this->AsIdentifier(expression))) { |
2617 this->ReportMessageAt(location, "strict_eval_arguments", false); | 2768 this->ReportMessageAt(location, "strict_eval_arguments", false); |
2618 *ok = false; | 2769 *ok = false; |
2619 return this->EmptyExpression(); | 2770 return this->EmptyExpression(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2659 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 2810 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
2660 // Both accessors of the same type. | 2811 // Both accessors of the same type. |
2661 parser()->ReportMessage("accessor_get_set"); | 2812 parser()->ReportMessage("accessor_get_set"); |
2662 } | 2813 } |
2663 *ok = false; | 2814 *ok = false; |
2664 } | 2815 } |
2665 } | 2816 } |
2666 } } // v8::internal | 2817 } } // v8::internal |
2667 | 2818 |
2668 #endif // V8_PREPARSER_H | 2819 #endif // V8_PREPARSER_H |
OLD | NEW |