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 1918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1929 } | 1929 } |
1930 UNREACHABLE(); | 1930 UNREACHABLE(); |
1931 return this->EmptyIdentifier(); | 1931 return this->EmptyIdentifier(); |
1932 } | 1932 } |
1933 | 1933 |
1934 | 1934 |
1935 template <class Traits> | 1935 template <class Traits> |
1936 typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase< | 1936 typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase< |
1937 Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, | 1937 Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, |
1938 bool in_class, bool is_static, bool* ok) { | 1938 bool in_class, bool is_static, bool* ok) { |
1939 // TODO(arv): Add support for concise generator methods. | |
1940 ExpressionT value = this->EmptyExpression(); | 1939 ExpressionT value = this->EmptyExpression(); |
1941 bool is_get = false; | 1940 bool is_get = false; |
1942 bool is_set = false; | 1941 bool is_set = false; |
1943 bool name_is_static = false; | 1942 bool name_is_static = false; |
1943 bool is_generator = allow_harmony_object_literals_ && Check(Token::MUL); | |
1944 | |
1944 Token::Value name_token = peek(); | 1945 Token::Value name_token = peek(); |
1945 int next_pos = peek_position(); | 1946 int next_pos = peek_position(); |
1946 IdentifierT name = | 1947 IdentifierT name = |
1947 ParsePropertyName(&is_get, &is_set, &name_is_static, | 1948 ParsePropertyName(&is_get, &is_set, &name_is_static, |
1948 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1949 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1949 | 1950 |
1950 if (fni_ != NULL) this->PushLiteralName(fni_, name); | 1951 if (fni_ != NULL) this->PushLiteralName(fni_, name); |
1951 | 1952 |
1952 if (!in_class && peek() == Token::COLON) { | 1953 if (!in_class && !is_generator && peek() == Token::COLON) { |
1953 // PropertyDefinition : PropertyName ':' AssignmentExpression | 1954 // PropertyDefinition : PropertyName ':' AssignmentExpression |
1954 checker->CheckProperty(name_token, kValueProperty, | 1955 checker->CheckProperty(name_token, kValueProperty, |
1955 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1956 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1956 Consume(Token::COLON); | 1957 Consume(Token::COLON); |
1957 value = this->ParseAssignmentExpression( | 1958 value = this->ParseAssignmentExpression( |
1958 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1959 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1959 | 1960 |
1960 } else if (allow_harmony_object_literals_ && peek() == Token::LPAREN) { | 1961 } else if (is_generator || |
1962 (allow_harmony_object_literals_ && peek() == Token::LPAREN)) { | |
1961 // Concise Method | 1963 // Concise Method |
1962 | 1964 |
1963 if (is_static && this->IsPrototype(name)) { | 1965 if (is_static && this->IsPrototype(name)) { |
1964 ReportMessageAt(scanner()->location(), "static_prototype"); | 1966 ReportMessageAt(scanner()->location(), "static_prototype"); |
1965 *ok = false; | 1967 *ok = false; |
1966 return this->EmptyObjectLiteralProperty(); | 1968 return this->EmptyObjectLiteralProperty(); |
1967 } | 1969 } |
1970 if (is_generator && in_class && !is_static && this->IsConstructor(name)) { | |
1971 ReportMessageAt(scanner()->location(), "constructor_special_method"); | |
1972 *ok = false; | |
1973 return this->EmptyObjectLiteralProperty(); | |
1974 } | |
1968 | 1975 |
1969 checker->CheckProperty(name_token, kValueProperty, | 1976 checker->CheckProperty(name_token, kValueProperty, |
1970 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1977 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1978 FunctionKind kind = FunctionKind::kConciseMethod; | |
1979 if (is_generator) { | |
Dmitry Lomov (no reviews)
2014/09/18 07:43:57
Nit: maybe the following is better:
1) add ``kConc
arv (Not doing code reviews)
2014/09/18 15:59:02
Thanks. That is much better.
| |
1980 kind = static_cast<FunctionKind>(kind | FunctionKind::kGeneratorFunction); | |
1981 } | |
1971 value = this->ParseFunctionLiteral( | 1982 value = this->ParseFunctionLiteral( |
1972 name, scanner()->location(), | 1983 name, scanner()->location(), |
1973 false, // reserved words are allowed here | 1984 false, // reserved words are allowed here |
1974 FunctionKind::kConciseMethod, RelocInfo::kNoPosition, | 1985 kind, RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, |
1975 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::NORMAL_ARITY, | 1986 FunctionLiteral::NORMAL_ARITY, |
1976 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1987 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1977 | 1988 |
1978 } else if (in_class && name_is_static && !is_static) { | 1989 } else if (in_class && name_is_static && !is_static) { |
1979 // static MethodDefinition | 1990 // static MethodDefinition |
1980 return ParsePropertyDefinition(checker, true, true, ok); | 1991 return ParsePropertyDefinition(checker, true, true, ok); |
1981 | 1992 |
1982 } else if (is_get || is_set) { | 1993 } else if (is_get || is_set) { |
1983 // Accessor | 1994 // Accessor |
1984 bool dont_care = false; | 1995 bool dont_care = false; |
1985 name_token = peek(); | 1996 name_token = peek(); |
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2817 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 2828 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
2818 // Both accessors of the same type. | 2829 // Both accessors of the same type. |
2819 parser()->ReportMessage("accessor_get_set"); | 2830 parser()->ReportMessage("accessor_get_set"); |
2820 } | 2831 } |
2821 *ok = false; | 2832 *ok = false; |
2822 } | 2833 } |
2823 } | 2834 } |
2824 } } // v8::internal | 2835 } } // v8::internal |
2825 | 2836 |
2826 #endif // V8_PREPARSER_H | 2837 #endif // V8_PREPARSER_H |
OLD | NEW |