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_PARSING_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
7 | 7 |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 }; | 1096 }; |
1097 | 1097 |
1098 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); | 1098 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); |
1099 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, | 1099 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, |
1100 bool* is_generator, bool* is_get, bool* is_set, | 1100 bool* is_generator, bool* is_get, bool* is_set, |
1101 bool* is_async, bool* is_computed_name, | 1101 bool* is_async, bool* is_computed_name, |
1102 bool* ok); | 1102 bool* ok); |
1103 ExpressionT ParseObjectLiteral(bool* ok); | 1103 ExpressionT ParseObjectLiteral(bool* ok); |
1104 ClassLiteralPropertyT ParseClassPropertyDefinition( | 1104 ClassLiteralPropertyT ParseClassPropertyDefinition( |
1105 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, | 1105 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, |
1106 bool* has_seen_constructor, IdentifierT* name, bool* ok); | 1106 bool* has_seen_constructor, bool* ok); |
1107 ObjectLiteralPropertyT ParseObjectPropertyDefinition( | 1107 ObjectLiteralPropertyT ParseObjectPropertyDefinition( |
1108 ObjectLiteralChecker* checker, bool* is_computed_name, IdentifierT* name, | 1108 ObjectLiteralChecker* checker, bool* is_computed_name, bool* ok); |
1109 bool* ok); | |
1110 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, | 1109 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, |
1111 bool maybe_arrow, bool* ok); | 1110 bool maybe_arrow, bool* ok); |
1112 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, | 1111 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, |
1113 bool* ok) { | 1112 bool* ok) { |
1114 return ParseArguments(first_spread_pos, false, ok); | 1113 return ParseArguments(first_spread_pos, false, ok); |
1115 } | 1114 } |
1116 | 1115 |
1117 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); | 1116 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); |
1118 ExpressionT ParseYieldExpression(bool accept_IN, bool* ok); | 1117 ExpressionT ParseYieldExpression(bool accept_IN, bool* ok); |
1119 ExpressionT ParseTailCallExpression(bool* ok); | 1118 ExpressionT ParseTailCallExpression(bool* ok); |
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2002 ? factory()->NewNumberLiteral(index, pos) | 2001 ? factory()->NewNumberLiteral(index, pos) |
2003 : factory()->NewStringLiteral(*name, pos); | 2002 : factory()->NewStringLiteral(*name, pos); |
2004 } | 2003 } |
2005 | 2004 |
2006 template <typename Impl> | 2005 template <typename Impl> |
2007 typename ParserBase<Impl>::ClassLiteralPropertyT | 2006 typename ParserBase<Impl>::ClassLiteralPropertyT |
2008 ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker, | 2007 ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker, |
2009 bool has_extends, | 2008 bool has_extends, |
2010 bool* is_computed_name, | 2009 bool* is_computed_name, |
2011 bool* has_seen_constructor, | 2010 bool* has_seen_constructor, |
2012 IdentifierT* name, bool* ok) { | 2011 bool* ok) { |
2013 DCHECK(has_seen_constructor != nullptr); | 2012 DCHECK(has_seen_constructor != nullptr); |
2014 bool is_get = false; | 2013 bool is_get = false; |
2015 bool is_set = false; | 2014 bool is_set = false; |
2016 bool is_generator = false; | 2015 bool is_generator = false; |
2017 bool is_async = false; | 2016 bool is_async = false; |
2018 bool is_static = false; | 2017 bool is_static = false; |
2019 PropertyKind kind = PropertyKind::kNotSet; | 2018 PropertyKind kind = PropertyKind::kNotSet; |
2020 | 2019 |
2021 Token::Value name_token = peek(); | 2020 Token::Value name_token = peek(); |
2022 | 2021 |
| 2022 IdentifierT name = impl()->EmptyIdentifier(); |
2023 ExpressionT name_expression; | 2023 ExpressionT name_expression; |
2024 if (name_token == Token::STATIC) { | 2024 if (name_token == Token::STATIC) { |
2025 Consume(Token::STATIC); | 2025 Consume(Token::STATIC); |
2026 if (peek() == Token::LPAREN) { | 2026 if (peek() == Token::LPAREN) { |
2027 kind = PropertyKind::kMethodProperty; | 2027 kind = PropertyKind::kMethodProperty; |
2028 *name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' | 2028 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' |
2029 name_expression = factory()->NewStringLiteral(*name, position()); | 2029 name_expression = factory()->NewStringLiteral(name, position()); |
2030 } else { | 2030 } else { |
2031 is_static = true; | 2031 is_static = true; |
2032 name_expression = ParsePropertyName( | 2032 name_expression = ParsePropertyName( |
2033 name, &kind, &is_generator, &is_get, &is_set, &is_async, | 2033 &name, &kind, &is_generator, &is_get, &is_set, &is_async, |
2034 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2034 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
2035 } | 2035 } |
2036 } else { | 2036 } else { |
2037 name_expression = ParsePropertyName( | 2037 name_expression = ParsePropertyName( |
2038 name, &kind, &is_generator, &is_get, &is_set, &is_async, | 2038 &name, &kind, &is_generator, &is_get, &is_set, &is_async, |
2039 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2039 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
2040 } | 2040 } |
2041 | 2041 |
2042 switch (kind) { | 2042 switch (kind) { |
2043 case PropertyKind::kShorthandProperty: | 2043 case PropertyKind::kShorthandProperty: |
2044 case PropertyKind::kValueProperty: | 2044 case PropertyKind::kValueProperty: |
2045 ReportUnexpectedToken(Next()); | 2045 ReportUnexpectedToken(Next()); |
2046 *ok = false; | 2046 *ok = false; |
2047 return impl()->EmptyClassLiteralProperty(); | 2047 return impl()->EmptyClassLiteralProperty(); |
2048 | 2048 |
2049 case PropertyKind::kMethodProperty: { | 2049 case PropertyKind::kMethodProperty: { |
2050 DCHECK(!is_get && !is_set); | 2050 DCHECK(!is_get && !is_set); |
2051 | 2051 |
2052 // MethodDefinition | 2052 // MethodDefinition |
2053 // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' | 2053 // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' |
2054 // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' | 2054 // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' |
2055 | 2055 |
2056 if (!*is_computed_name) { | 2056 if (!*is_computed_name) { |
2057 checker->CheckClassMethodName( | 2057 checker->CheckClassMethodName( |
2058 name_token, PropertyKind::kMethodProperty, is_generator, is_async, | 2058 name_token, PropertyKind::kMethodProperty, is_generator, is_async, |
2059 is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2059 is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
2060 } | 2060 } |
2061 | 2061 |
2062 FunctionKind kind = is_generator | 2062 FunctionKind kind = is_generator |
2063 ? FunctionKind::kConciseGeneratorMethod | 2063 ? FunctionKind::kConciseGeneratorMethod |
2064 : is_async ? FunctionKind::kAsyncConciseMethod | 2064 : is_async ? FunctionKind::kAsyncConciseMethod |
2065 : FunctionKind::kConciseMethod; | 2065 : FunctionKind::kConciseMethod; |
2066 | 2066 |
2067 if (!is_static && impl()->IsConstructor(*name)) { | 2067 if (!is_static && impl()->IsConstructor(name)) { |
2068 *has_seen_constructor = true; | 2068 *has_seen_constructor = true; |
2069 kind = has_extends ? FunctionKind::kSubclassConstructor | 2069 kind = has_extends ? FunctionKind::kSubclassConstructor |
2070 : FunctionKind::kBaseConstructor; | 2070 : FunctionKind::kBaseConstructor; |
2071 } | 2071 } |
2072 | 2072 |
2073 ExpressionT value = impl()->ParseFunctionLiteral( | 2073 ExpressionT value = impl()->ParseFunctionLiteral( |
2074 *name, scanner()->location(), kSkipFunctionNameCheck, kind, | 2074 name, scanner()->location(), kSkipFunctionNameCheck, kind, |
2075 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, | 2075 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, |
2076 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2076 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
2077 | 2077 |
2078 return factory()->NewClassLiteralProperty(name_expression, value, | 2078 return factory()->NewClassLiteralProperty(name_expression, value, |
2079 ClassLiteralProperty::METHOD, | 2079 ClassLiteralProperty::METHOD, |
2080 is_static, *is_computed_name); | 2080 is_static, *is_computed_name); |
2081 } | 2081 } |
2082 | 2082 |
2083 case PropertyKind::kAccessorProperty: { | 2083 case PropertyKind::kAccessorProperty: { |
2084 DCHECK((is_get || is_set) && !is_generator && !is_async); | 2084 DCHECK((is_get || is_set) && !is_generator && !is_async); |
2085 | 2085 |
2086 if (!*is_computed_name) { | 2086 if (!*is_computed_name) { |
2087 checker->CheckClassMethodName( | 2087 checker->CheckClassMethodName( |
2088 name_token, PropertyKind::kAccessorProperty, false, false, | 2088 name_token, PropertyKind::kAccessorProperty, false, false, |
2089 is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2089 is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
2090 // Make sure the name expression is a string since we need a Name for | 2090 // Make sure the name expression is a string since we need a Name for |
2091 // Runtime_DefineAccessorPropertyUnchecked and since we can determine | 2091 // Runtime_DefineAccessorPropertyUnchecked and since we can determine |
2092 // this statically we can skip the extra runtime check. | 2092 // this statically we can skip the extra runtime check. |
2093 name_expression = | 2093 name_expression = |
2094 factory()->NewStringLiteral(*name, name_expression->position()); | 2094 factory()->NewStringLiteral(name, name_expression->position()); |
2095 } | 2095 } |
2096 | 2096 |
2097 FunctionKind kind = is_get ? FunctionKind::kGetterFunction | 2097 FunctionKind kind = is_get ? FunctionKind::kGetterFunction |
2098 : FunctionKind::kSetterFunction; | 2098 : FunctionKind::kSetterFunction; |
2099 | 2099 |
2100 ExpressionT value = impl()->ParseFunctionLiteral( | 2100 FunctionLiteralT value = impl()->ParseFunctionLiteral( |
2101 *name, scanner()->location(), kSkipFunctionNameCheck, kind, | 2101 name, scanner()->location(), kSkipFunctionNameCheck, kind, |
2102 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, | 2102 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, |
2103 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2103 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
2104 | 2104 |
| 2105 if (!*is_computed_name) { |
| 2106 impl()->AddAccessorPrefixToFunctionName(is_get, value, name); |
| 2107 } |
| 2108 |
2105 return factory()->NewClassLiteralProperty( | 2109 return factory()->NewClassLiteralProperty( |
2106 name_expression, value, | 2110 name_expression, value, |
2107 is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER, | 2111 is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER, |
2108 is_static, *is_computed_name); | 2112 is_static, *is_computed_name); |
2109 } | 2113 } |
2110 | 2114 |
2111 case PropertyKind::kNotSet: | 2115 case PropertyKind::kNotSet: |
2112 ReportUnexpectedToken(Next()); | 2116 ReportUnexpectedToken(Next()); |
2113 *ok = false; | 2117 *ok = false; |
2114 return impl()->EmptyClassLiteralProperty(); | 2118 return impl()->EmptyClassLiteralProperty(); |
2115 } | 2119 } |
2116 UNREACHABLE(); | 2120 UNREACHABLE(); |
2117 return impl()->EmptyClassLiteralProperty(); | 2121 return impl()->EmptyClassLiteralProperty(); |
2118 } | 2122 } |
2119 | 2123 |
2120 template <typename Impl> | 2124 template <typename Impl> |
2121 typename ParserBase<Impl>::ObjectLiteralPropertyT | 2125 typename ParserBase<Impl>::ObjectLiteralPropertyT |
2122 ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker, | 2126 ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker, |
2123 bool* is_computed_name, | 2127 bool* is_computed_name, |
2124 IdentifierT* name, bool* ok) { | 2128 bool* ok) { |
2125 bool is_get = false; | 2129 bool is_get = false; |
2126 bool is_set = false; | 2130 bool is_set = false; |
2127 bool is_generator = false; | 2131 bool is_generator = false; |
2128 bool is_async = false; | 2132 bool is_async = false; |
2129 PropertyKind kind = PropertyKind::kNotSet; | 2133 PropertyKind kind = PropertyKind::kNotSet; |
2130 | 2134 |
| 2135 IdentifierT name = impl()->EmptyIdentifier(); |
2131 Token::Value name_token = peek(); | 2136 Token::Value name_token = peek(); |
2132 int next_beg_pos = scanner()->peek_location().beg_pos; | 2137 int next_beg_pos = scanner()->peek_location().beg_pos; |
2133 int next_end_pos = scanner()->peek_location().end_pos; | 2138 int next_end_pos = scanner()->peek_location().end_pos; |
2134 | 2139 |
2135 ExpressionT name_expression = ParsePropertyName( | 2140 ExpressionT name_expression = ParsePropertyName( |
2136 name, &kind, &is_generator, &is_get, &is_set, &is_async, is_computed_name, | 2141 &name, &kind, &is_generator, &is_get, &is_set, &is_async, |
2137 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2142 is_computed_name, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2138 | 2143 |
2139 switch (kind) { | 2144 switch (kind) { |
2140 case PropertyKind::kValueProperty: { | 2145 case PropertyKind::kValueProperty: { |
2141 DCHECK(!is_get && !is_set && !is_generator && !is_async); | 2146 DCHECK(!is_get && !is_set && !is_generator && !is_async); |
2142 | 2147 |
2143 if (!*is_computed_name) { | 2148 if (!*is_computed_name) { |
2144 checker->CheckDuplicateProto(name_token); | 2149 checker->CheckDuplicateProto(name_token); |
2145 } | 2150 } |
2146 Consume(Token::COLON); | 2151 Consume(Token::COLON); |
2147 int beg_pos = peek_position(); | 2152 int beg_pos = peek_position(); |
2148 ExpressionT value = ParseAssignmentExpression( | 2153 ExpressionT value = ParseAssignmentExpression( |
2149 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2154 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2150 CheckDestructuringElement(value, beg_pos, scanner()->location().end_pos); | 2155 CheckDestructuringElement(value, beg_pos, scanner()->location().end_pos); |
2151 | 2156 |
2152 return factory()->NewObjectLiteralProperty(name_expression, value, | 2157 ObjectLiteralPropertyT result = factory()->NewObjectLiteralProperty( |
2153 *is_computed_name); | 2158 name_expression, value, *is_computed_name); |
| 2159 |
| 2160 if (!*is_computed_name) { |
| 2161 impl()->SetFunctionNameFromPropertyName(result, name); |
| 2162 } |
| 2163 |
| 2164 return result; |
2154 } | 2165 } |
2155 | 2166 |
2156 case PropertyKind::kShorthandProperty: { | 2167 case PropertyKind::kShorthandProperty: { |
2157 // PropertyDefinition | 2168 // PropertyDefinition |
2158 // IdentifierReference | 2169 // IdentifierReference |
2159 // CoverInitializedName | 2170 // CoverInitializedName |
2160 // | 2171 // |
2161 // CoverInitializedName | 2172 // CoverInitializedName |
2162 // IdentifierReference Initializer? | 2173 // IdentifierReference Initializer? |
2163 DCHECK(!is_get && !is_set && !is_generator && !is_async); | 2174 DCHECK(!is_get && !is_set && !is_generator && !is_async); |
2164 | 2175 |
2165 if (!Token::IsIdentifier(name_token, language_mode(), | 2176 if (!Token::IsIdentifier(name_token, language_mode(), |
2166 this->is_generator(), | 2177 this->is_generator(), |
2167 parsing_module_ || is_async_function())) { | 2178 parsing_module_ || is_async_function())) { |
2168 ReportUnexpectedToken(Next()); | 2179 ReportUnexpectedToken(Next()); |
2169 *ok = false; | 2180 *ok = false; |
2170 return impl()->EmptyObjectLiteralProperty(); | 2181 return impl()->EmptyObjectLiteralProperty(); |
2171 } | 2182 } |
2172 | 2183 |
2173 DCHECK(!*is_computed_name); | 2184 DCHECK(!*is_computed_name); |
2174 | 2185 |
2175 if (classifier()->duplicate_finder() != nullptr && | 2186 if (classifier()->duplicate_finder() != nullptr && |
2176 scanner()->FindSymbol(classifier()->duplicate_finder(), 1) != 0) { | 2187 scanner()->FindSymbol(classifier()->duplicate_finder(), 1) != 0) { |
2177 classifier()->RecordDuplicateFormalParameterError( | 2188 classifier()->RecordDuplicateFormalParameterError( |
2178 scanner()->location()); | 2189 scanner()->location()); |
2179 } | 2190 } |
2180 | 2191 |
2181 if (impl()->IsEvalOrArguments(*name) && is_strict(language_mode())) { | 2192 if (impl()->IsEvalOrArguments(name) && is_strict(language_mode())) { |
2182 classifier()->RecordBindingPatternError( | 2193 classifier()->RecordBindingPatternError( |
2183 scanner()->location(), MessageTemplate::kStrictEvalArguments); | 2194 scanner()->location(), MessageTemplate::kStrictEvalArguments); |
2184 } | 2195 } |
2185 | 2196 |
2186 if (name_token == Token::LET) { | 2197 if (name_token == Token::LET) { |
2187 classifier()->RecordLetPatternError( | 2198 classifier()->RecordLetPatternError( |
2188 scanner()->location(), MessageTemplate::kLetInLexicalBinding); | 2199 scanner()->location(), MessageTemplate::kLetInLexicalBinding); |
2189 } | 2200 } |
2190 if (name_token == Token::AWAIT) { | 2201 if (name_token == Token::AWAIT) { |
2191 DCHECK(!is_async_function()); | 2202 DCHECK(!is_async_function()); |
2192 classifier()->RecordAsyncArrowFormalParametersError( | 2203 classifier()->RecordAsyncArrowFormalParametersError( |
2193 Scanner::Location(next_beg_pos, next_end_pos), | 2204 Scanner::Location(next_beg_pos, next_end_pos), |
2194 MessageTemplate::kAwaitBindingIdentifier); | 2205 MessageTemplate::kAwaitBindingIdentifier); |
2195 } | 2206 } |
2196 ExpressionT lhs = | 2207 ExpressionT lhs = |
2197 impl()->ExpressionFromIdentifier(*name, next_beg_pos, next_end_pos); | 2208 impl()->ExpressionFromIdentifier(name, next_beg_pos, next_end_pos); |
2198 CheckDestructuringElement(lhs, next_beg_pos, next_end_pos); | 2209 CheckDestructuringElement(lhs, next_beg_pos, next_end_pos); |
2199 | 2210 |
2200 ExpressionT value; | 2211 ExpressionT value; |
2201 if (peek() == Token::ASSIGN) { | 2212 if (peek() == Token::ASSIGN) { |
2202 Consume(Token::ASSIGN); | 2213 Consume(Token::ASSIGN); |
2203 ExpressionClassifier rhs_classifier(this); | 2214 ExpressionClassifier rhs_classifier(this); |
2204 ExpressionT rhs = ParseAssignmentExpression( | 2215 ExpressionT rhs = ParseAssignmentExpression( |
2205 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2216 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2206 impl()->RewriteNonPattern(CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2217 impl()->RewriteNonPattern(CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2207 impl()->AccumulateFormalParameterContainmentErrors(); | 2218 impl()->AccumulateFormalParameterContainmentErrors(); |
(...skipping 22 matching lines...) Expand all Loading... |
2230 classifier()->RecordPatternError( | 2241 classifier()->RecordPatternError( |
2231 Scanner::Location(next_beg_pos, scanner()->location().end_pos), | 2242 Scanner::Location(next_beg_pos, scanner()->location().end_pos), |
2232 MessageTemplate::kInvalidDestructuringTarget); | 2243 MessageTemplate::kInvalidDestructuringTarget); |
2233 | 2244 |
2234 FunctionKind kind = is_generator | 2245 FunctionKind kind = is_generator |
2235 ? FunctionKind::kConciseGeneratorMethod | 2246 ? FunctionKind::kConciseGeneratorMethod |
2236 : is_async ? FunctionKind::kAsyncConciseMethod | 2247 : is_async ? FunctionKind::kAsyncConciseMethod |
2237 : FunctionKind::kConciseMethod; | 2248 : FunctionKind::kConciseMethod; |
2238 | 2249 |
2239 ExpressionT value = impl()->ParseFunctionLiteral( | 2250 ExpressionT value = impl()->ParseFunctionLiteral( |
2240 *name, scanner()->location(), kSkipFunctionNameCheck, kind, | 2251 name, scanner()->location(), kSkipFunctionNameCheck, kind, |
2241 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, | 2252 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, |
2242 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2253 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2243 | 2254 |
2244 return factory()->NewObjectLiteralProperty( | 2255 return factory()->NewObjectLiteralProperty( |
2245 name_expression, value, ObjectLiteralProperty::COMPUTED, | 2256 name_expression, value, ObjectLiteralProperty::COMPUTED, |
2246 *is_computed_name); | 2257 *is_computed_name); |
2247 } | 2258 } |
2248 | 2259 |
2249 case PropertyKind::kAccessorProperty: { | 2260 case PropertyKind::kAccessorProperty: { |
2250 DCHECK((is_get || is_set) && !(is_set && is_get) && !is_generator && | 2261 DCHECK((is_get || is_set) && !(is_set && is_get) && !is_generator && |
2251 !is_async); | 2262 !is_async); |
2252 | 2263 |
2253 classifier()->RecordPatternError( | 2264 classifier()->RecordPatternError( |
2254 Scanner::Location(next_beg_pos, scanner()->location().end_pos), | 2265 Scanner::Location(next_beg_pos, scanner()->location().end_pos), |
2255 MessageTemplate::kInvalidDestructuringTarget); | 2266 MessageTemplate::kInvalidDestructuringTarget); |
2256 | 2267 |
2257 if (!*is_computed_name) { | 2268 if (!*is_computed_name) { |
2258 // Make sure the name expression is a string since we need a Name for | 2269 // Make sure the name expression is a string since we need a Name for |
2259 // Runtime_DefineAccessorPropertyUnchecked and since we can determine | 2270 // Runtime_DefineAccessorPropertyUnchecked and since we can determine |
2260 // this statically we can skip the extra runtime check. | 2271 // this statically we can skip the extra runtime check. |
2261 name_expression = | 2272 name_expression = |
2262 factory()->NewStringLiteral(*name, name_expression->position()); | 2273 factory()->NewStringLiteral(name, name_expression->position()); |
2263 } | 2274 } |
2264 | 2275 |
2265 FunctionKind kind = is_get ? FunctionKind::kGetterFunction | 2276 FunctionKind kind = is_get ? FunctionKind::kGetterFunction |
2266 : FunctionKind::kSetterFunction; | 2277 : FunctionKind::kSetterFunction; |
2267 | 2278 |
2268 ExpressionT value = impl()->ParseFunctionLiteral( | 2279 FunctionLiteralT value = impl()->ParseFunctionLiteral( |
2269 *name, scanner()->location(), kSkipFunctionNameCheck, kind, | 2280 name, scanner()->location(), kSkipFunctionNameCheck, kind, |
2270 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, | 2281 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, |
2271 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2282 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2272 | 2283 |
| 2284 if (!*is_computed_name) { |
| 2285 impl()->AddAccessorPrefixToFunctionName(is_get, value, name); |
| 2286 } |
| 2287 |
2273 return factory()->NewObjectLiteralProperty( | 2288 return factory()->NewObjectLiteralProperty( |
2274 name_expression, value, is_get ? ObjectLiteralProperty::GETTER | 2289 name_expression, value, is_get ? ObjectLiteralProperty::GETTER |
2275 : ObjectLiteralProperty::SETTER, | 2290 : ObjectLiteralProperty::SETTER, |
2276 *is_computed_name); | 2291 *is_computed_name); |
2277 } | 2292 } |
2278 | 2293 |
2279 case PropertyKind::kNotSet: | 2294 case PropertyKind::kNotSet: |
2280 ReportUnexpectedToken(Next()); | 2295 ReportUnexpectedToken(Next()); |
2281 *ok = false; | 2296 *ok = false; |
2282 return impl()->EmptyObjectLiteralProperty(); | 2297 return impl()->EmptyObjectLiteralProperty(); |
(...skipping 13 matching lines...) Expand all Loading... |
2296 int number_of_boilerplate_properties = 0; | 2311 int number_of_boilerplate_properties = 0; |
2297 bool has_computed_names = false; | 2312 bool has_computed_names = false; |
2298 ObjectLiteralChecker checker(this); | 2313 ObjectLiteralChecker checker(this); |
2299 | 2314 |
2300 Expect(Token::LBRACE, CHECK_OK); | 2315 Expect(Token::LBRACE, CHECK_OK); |
2301 | 2316 |
2302 while (peek() != Token::RBRACE) { | 2317 while (peek() != Token::RBRACE) { |
2303 FuncNameInferrer::State fni_state(fni_); | 2318 FuncNameInferrer::State fni_state(fni_); |
2304 | 2319 |
2305 bool is_computed_name = false; | 2320 bool is_computed_name = false; |
2306 IdentifierT name = impl()->EmptyIdentifier(); | 2321 ObjectLiteralPropertyT property = |
2307 ObjectLiteralPropertyT property = ParseObjectPropertyDefinition( | 2322 ParseObjectPropertyDefinition(&checker, &is_computed_name, CHECK_OK); |
2308 &checker, &is_computed_name, &name, CHECK_OK); | |
2309 | 2323 |
2310 if (is_computed_name) { | 2324 if (is_computed_name) { |
2311 has_computed_names = true; | 2325 has_computed_names = true; |
2312 } | 2326 } |
2313 | 2327 |
2314 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. | 2328 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. |
2315 if (!has_computed_names && impl()->IsBoilerplateProperty(property)) { | 2329 if (!has_computed_names && impl()->IsBoilerplateProperty(property)) { |
2316 number_of_boilerplate_properties++; | 2330 number_of_boilerplate_properties++; |
2317 } | 2331 } |
2318 properties->Add(property, zone()); | 2332 properties->Add(property, zone()); |
2319 | 2333 |
2320 if (peek() != Token::RBRACE) { | 2334 if (peek() != Token::RBRACE) { |
2321 // Need {} because of the CHECK_OK macro. | 2335 // Need {} because of the CHECK_OK macro. |
2322 Expect(Token::COMMA, CHECK_OK); | 2336 Expect(Token::COMMA, CHECK_OK); |
2323 } | 2337 } |
2324 | 2338 |
2325 if (fni_ != nullptr) fni_->Infer(); | 2339 if (fni_ != nullptr) fni_->Infer(); |
2326 | |
2327 impl()->SetFunctionNameFromPropertyName(property, name); | |
2328 } | 2340 } |
2329 Expect(Token::RBRACE, CHECK_OK); | 2341 Expect(Token::RBRACE, CHECK_OK); |
2330 | 2342 |
2331 // Computation of literal_index must happen before pre parse bailout. | 2343 // Computation of literal_index must happen before pre parse bailout. |
2332 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 2344 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
2333 | 2345 |
2334 return factory()->NewObjectLiteral(properties, | 2346 return factory()->NewObjectLiteral(properties, |
2335 literal_index, | 2347 literal_index, |
2336 number_of_boilerplate_properties, | 2348 number_of_boilerplate_properties, |
2337 pos); | 2349 pos); |
(...skipping 1892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4230 has_seen_constructor_ = true; | 4242 has_seen_constructor_ = true; |
4231 return; | 4243 return; |
4232 } | 4244 } |
4233 } | 4245 } |
4234 | 4246 |
4235 | 4247 |
4236 } // namespace internal | 4248 } // namespace internal |
4237 } // namespace v8 | 4249 } // namespace v8 |
4238 | 4250 |
4239 #endif // V8_PARSING_PARSER_BASE_H | 4251 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |