OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 1670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 | 1681 |
1682 | 1682 |
1683 template<class Traits> | 1683 template<class Traits> |
1684 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { | 1684 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { |
1685 Scanner::Location source_location = scanner()->location(); | 1685 Scanner::Location source_location = scanner()->location(); |
1686 | 1686 |
1687 // Four of the tokens are treated specially | 1687 // Four of the tokens are treated specially |
1688 switch (token) { | 1688 switch (token) { |
1689 case Token::EOS: | 1689 case Token::EOS: |
1690 return ReportMessageAt(source_location, "unexpected_eos"); | 1690 return ReportMessageAt(source_location, "unexpected_eos"); |
| 1691 case Token::SMI: |
1691 case Token::NUMBER: | 1692 case Token::NUMBER: |
1692 return ReportMessageAt(source_location, "unexpected_token_number"); | 1693 return ReportMessageAt(source_location, "unexpected_token_number"); |
1693 case Token::STRING: | 1694 case Token::STRING: |
1694 return ReportMessageAt(source_location, "unexpected_token_string"); | 1695 return ReportMessageAt(source_location, "unexpected_token_string"); |
1695 case Token::IDENTIFIER: | 1696 case Token::IDENTIFIER: |
1696 return ReportMessageAt(source_location, "unexpected_token_identifier"); | 1697 return ReportMessageAt(source_location, "unexpected_token_identifier"); |
1697 case Token::FUTURE_RESERVED_WORD: | 1698 case Token::FUTURE_RESERVED_WORD: |
1698 return ReportMessageAt(source_location, "unexpected_reserved"); | 1699 return ReportMessageAt(source_location, "unexpected_reserved"); |
1699 case Token::LET: | 1700 case Token::LET: |
1700 case Token::STATIC: | 1701 case Token::STATIC: |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1867 case Token::THIS: { | 1868 case Token::THIS: { |
1868 Consume(Token::THIS); | 1869 Consume(Token::THIS); |
1869 scope_->RecordThisUsage(); | 1870 scope_->RecordThisUsage(); |
1870 result = this->ThisExpression(scope_, factory(), beg_pos); | 1871 result = this->ThisExpression(scope_, factory(), beg_pos); |
1871 break; | 1872 break; |
1872 } | 1873 } |
1873 | 1874 |
1874 case Token::NULL_LITERAL: | 1875 case Token::NULL_LITERAL: |
1875 case Token::TRUE_LITERAL: | 1876 case Token::TRUE_LITERAL: |
1876 case Token::FALSE_LITERAL: | 1877 case Token::FALSE_LITERAL: |
| 1878 case Token::SMI: |
1877 case Token::NUMBER: | 1879 case Token::NUMBER: |
1878 Next(); | 1880 Next(); |
1879 result = | 1881 result = |
1880 this->ExpressionFromLiteral(token, beg_pos, scanner(), factory()); | 1882 this->ExpressionFromLiteral(token, beg_pos, scanner(), factory()); |
1881 break; | 1883 break; |
1882 | 1884 |
1883 case Token::IDENTIFIER: | 1885 case Token::IDENTIFIER: |
1884 case Token::LET: | 1886 case Token::LET: |
1885 case Token::STATIC: | 1887 case Token::STATIC: |
1886 case Token::YIELD: | 1888 case Token::YIELD: |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2048 // identifier -> "identifier" | 2050 // identifier -> "identifier" |
2049 // | 2051 // |
2050 // This is important because we use the property name as a key in a hash | 2052 // This is important because we use the property name as a key in a hash |
2051 // table when we compute constant properties. | 2053 // table when we compute constant properties. |
2052 switch (token) { | 2054 switch (token) { |
2053 case Token::STRING: | 2055 case Token::STRING: |
2054 Consume(Token::STRING); | 2056 Consume(Token::STRING); |
2055 *name = this->GetSymbol(scanner()); | 2057 *name = this->GetSymbol(scanner()); |
2056 break; | 2058 break; |
2057 | 2059 |
| 2060 case Token::SMI: |
| 2061 Consume(Token::SMI); |
| 2062 *name = this->GetNumberAsSymbol(scanner()); |
| 2063 break; |
| 2064 |
2058 case Token::NUMBER: | 2065 case Token::NUMBER: |
2059 Consume(Token::NUMBER); | 2066 Consume(Token::NUMBER); |
2060 *name = this->GetNumberAsSymbol(scanner()); | 2067 *name = this->GetNumberAsSymbol(scanner()); |
2061 break; | 2068 break; |
2062 | 2069 |
2063 case Token::LBRACK: | 2070 case Token::LBRACK: |
2064 if (allow_harmony_computed_property_names_) { | 2071 if (allow_harmony_computed_property_names_) { |
2065 *is_computed_name = true; | 2072 *is_computed_name = true; |
2066 Consume(Token::LBRACK); | 2073 Consume(Token::LBRACK); |
2067 ExpressionT expression = ParseAssignmentExpression(true, CHECK_OK); | 2074 ExpressionT expression = ParseAssignmentExpression(true, CHECK_OK); |
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3062 #undef CHECK_OK_CUSTOM | 3069 #undef CHECK_OK_CUSTOM |
3063 | 3070 |
3064 | 3071 |
3065 template <typename Traits> | 3072 template <typename Traits> |
3066 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( | 3073 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( |
3067 Token::Value property, PropertyKind type, bool is_static, bool is_generator, | 3074 Token::Value property, PropertyKind type, bool is_static, bool is_generator, |
3068 bool* ok) { | 3075 bool* ok) { |
3069 DCHECK(!is_static); | 3076 DCHECK(!is_static); |
3070 DCHECK(!is_generator || type == kMethodProperty); | 3077 DCHECK(!is_generator || type == kMethodProperty); |
3071 | 3078 |
3072 if (property == Token::NUMBER) return; | 3079 if (property == Token::SMI || property == Token::NUMBER) return; |
3073 | 3080 |
3074 if (type == kValueProperty && IsProto()) { | 3081 if (type == kValueProperty && IsProto()) { |
3075 if (has_seen_proto_) { | 3082 if (has_seen_proto_) { |
3076 this->parser()->ReportMessage("duplicate_proto"); | 3083 this->parser()->ReportMessage("duplicate_proto"); |
3077 *ok = false; | 3084 *ok = false; |
3078 return; | 3085 return; |
3079 } | 3086 } |
3080 has_seen_proto_ = true; | 3087 has_seen_proto_ = true; |
3081 return; | 3088 return; |
3082 } | 3089 } |
3083 } | 3090 } |
3084 | 3091 |
3085 | 3092 |
3086 template <typename Traits> | 3093 template <typename Traits> |
3087 void ParserBase<Traits>::ClassLiteralChecker::CheckProperty( | 3094 void ParserBase<Traits>::ClassLiteralChecker::CheckProperty( |
3088 Token::Value property, PropertyKind type, bool is_static, bool is_generator, | 3095 Token::Value property, PropertyKind type, bool is_static, bool is_generator, |
3089 bool* ok) { | 3096 bool* ok) { |
3090 DCHECK(type == kMethodProperty || type == kAccessorProperty); | 3097 DCHECK(type == kMethodProperty || type == kAccessorProperty); |
3091 | 3098 |
3092 if (property == Token::NUMBER) return; | 3099 if (property == Token::SMI || property == Token::NUMBER) return; |
3093 | 3100 |
3094 if (is_static) { | 3101 if (is_static) { |
3095 if (IsPrototype()) { | 3102 if (IsPrototype()) { |
3096 this->parser()->ReportMessage("static_prototype"); | 3103 this->parser()->ReportMessage("static_prototype"); |
3097 *ok = false; | 3104 *ok = false; |
3098 return; | 3105 return; |
3099 } | 3106 } |
3100 } else if (IsConstructor()) { | 3107 } else if (IsConstructor()) { |
3101 if (is_generator || type == kAccessorProperty) { | 3108 if (is_generator || type == kAccessorProperty) { |
3102 this->parser()->ReportMessage("constructor_special_method"); | 3109 this->parser()->ReportMessage("constructor_special_method"); |
3103 *ok = false; | 3110 *ok = false; |
3104 return; | 3111 return; |
3105 } | 3112 } |
3106 if (has_seen_constructor_) { | 3113 if (has_seen_constructor_) { |
3107 this->parser()->ReportMessage("duplicate_constructor"); | 3114 this->parser()->ReportMessage("duplicate_constructor"); |
3108 *ok = false; | 3115 *ok = false; |
3109 return; | 3116 return; |
3110 } | 3117 } |
3111 has_seen_constructor_ = true; | 3118 has_seen_constructor_ = true; |
3112 return; | 3119 return; |
3113 } | 3120 } |
3114 } | 3121 } |
3115 } } // v8::internal | 3122 } } // v8::internal |
3116 | 3123 |
3117 #endif // V8_PREPARSER_H | 3124 #endif // V8_PREPARSER_H |
OLD | NEW |