| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 ast_node_factory_(ast_value_factory), | 202 ast_node_factory_(ast_value_factory), |
| 203 runtime_call_stats_(runtime_call_stats), | 203 runtime_call_stats_(runtime_call_stats), |
| 204 parsing_on_main_thread_(parsing_on_main_thread), | 204 parsing_on_main_thread_(parsing_on_main_thread), |
| 205 parsing_module_(false), | 205 parsing_module_(false), |
| 206 stack_limit_(stack_limit), | 206 stack_limit_(stack_limit), |
| 207 zone_(zone), | 207 zone_(zone), |
| 208 classifier_(nullptr), | 208 classifier_(nullptr), |
| 209 scanner_(scanner), | 209 scanner_(scanner), |
| 210 stack_overflow_(false), | 210 stack_overflow_(false), |
| 211 default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile), | 211 default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile), |
| 212 function_literal_id_(0), |
| 212 allow_natives_(false), | 213 allow_natives_(false), |
| 213 allow_tailcalls_(false), | 214 allow_tailcalls_(false), |
| 214 allow_harmony_do_expressions_(false), | 215 allow_harmony_do_expressions_(false), |
| 215 allow_harmony_function_sent_(false), | 216 allow_harmony_function_sent_(false), |
| 216 allow_harmony_async_await_(false), | 217 allow_harmony_async_await_(false), |
| 217 allow_harmony_restrictive_generators_(false), | 218 allow_harmony_restrictive_generators_(false), |
| 218 allow_harmony_trailing_commas_(false), | 219 allow_harmony_trailing_commas_(false), |
| 219 allow_harmony_class_fields_(false) {} | 220 allow_harmony_class_fields_(false) {} |
| 220 | 221 |
| 221 #define ALLOW_ACCESSORS(name) \ | 222 #define ALLOW_ACCESSORS(name) \ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 239 | 240 |
| 240 void set_default_eager_compile_hint( | 241 void set_default_eager_compile_hint( |
| 241 FunctionLiteral::EagerCompileHint eager_compile_hint) { | 242 FunctionLiteral::EagerCompileHint eager_compile_hint) { |
| 242 default_eager_compile_hint_ = eager_compile_hint; | 243 default_eager_compile_hint_ = eager_compile_hint; |
| 243 } | 244 } |
| 244 | 245 |
| 245 FunctionLiteral::EagerCompileHint default_eager_compile_hint() const { | 246 FunctionLiteral::EagerCompileHint default_eager_compile_hint() const { |
| 246 return default_eager_compile_hint_; | 247 return default_eager_compile_hint_; |
| 247 } | 248 } |
| 248 | 249 |
| 250 int GetNextFunctionLiteralId() { return ++function_literal_id_; } |
| 251 int GetLastFunctionLiteralId() const { return function_literal_id_; } |
| 252 |
| 253 void SkipFunctionLiterals(int delta) { function_literal_id_ += delta; } |
| 254 |
| 255 void ResetFunctionLiteralId() { function_literal_id_ = 0; } |
| 256 |
| 249 Zone* zone() const { return zone_; } | 257 Zone* zone() const { return zone_; } |
| 250 | 258 |
| 251 protected: | 259 protected: |
| 252 friend class v8::internal::ExpressionClassifier<ParserTypes<Impl>>; | 260 friend class v8::internal::ExpressionClassifier<ParserTypes<Impl>>; |
| 253 | 261 |
| 254 enum AllowRestrictedIdentifiers { | 262 enum AllowRestrictedIdentifiers { |
| 255 kAllowRestrictedIdentifiers, | 263 kAllowRestrictedIdentifiers, |
| 256 kDontAllowRestrictedIdentifiers | 264 kDontAllowRestrictedIdentifiers |
| 257 }; | 265 }; |
| 258 | 266 |
| (...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 }; | 1150 }; |
| 1143 | 1151 |
| 1144 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); | 1152 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); |
| 1145 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, | 1153 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, |
| 1146 bool* is_generator, bool* is_get, bool* is_set, | 1154 bool* is_generator, bool* is_get, bool* is_set, |
| 1147 bool* is_async, bool* is_computed_name, | 1155 bool* is_async, bool* is_computed_name, |
| 1148 bool* ok); | 1156 bool* ok); |
| 1149 ExpressionT ParseObjectLiteral(bool* ok); | 1157 ExpressionT ParseObjectLiteral(bool* ok); |
| 1150 ClassLiteralPropertyT ParseClassPropertyDefinition( | 1158 ClassLiteralPropertyT ParseClassPropertyDefinition( |
| 1151 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, | 1159 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, |
| 1152 bool* has_seen_constructor, bool* ok); | 1160 bool* has_seen_constructor, ClassLiteralProperty::Kind* property_kind, |
| 1161 bool* is_static, bool* ok); |
| 1153 FunctionLiteralT ParseClassFieldForInitializer(bool has_initializer, | 1162 FunctionLiteralT ParseClassFieldForInitializer(bool has_initializer, |
| 1154 bool* ok); | 1163 bool* ok); |
| 1155 ObjectLiteralPropertyT ParseObjectPropertyDefinition( | 1164 ObjectLiteralPropertyT ParseObjectPropertyDefinition( |
| 1156 ObjectLiteralChecker* checker, bool* is_computed_name, bool* ok); | 1165 ObjectLiteralChecker* checker, bool* is_computed_name, bool* ok); |
| 1157 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, | 1166 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, |
| 1158 bool maybe_arrow, bool* ok); | 1167 bool maybe_arrow, bool* ok); |
| 1159 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, | 1168 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, |
| 1160 bool* ok) { | 1169 bool* ok) { |
| 1161 return ParseArguments(first_spread_pos, false, ok); | 1170 return ParseArguments(first_spread_pos, false, ok); |
| 1162 } | 1171 } |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 | 1435 |
| 1427 private: | 1436 private: |
| 1428 Zone* zone_; | 1437 Zone* zone_; |
| 1429 ExpressionClassifier* classifier_; | 1438 ExpressionClassifier* classifier_; |
| 1430 | 1439 |
| 1431 Scanner* scanner_; | 1440 Scanner* scanner_; |
| 1432 bool stack_overflow_; | 1441 bool stack_overflow_; |
| 1433 | 1442 |
| 1434 FunctionLiteral::EagerCompileHint default_eager_compile_hint_; | 1443 FunctionLiteral::EagerCompileHint default_eager_compile_hint_; |
| 1435 | 1444 |
| 1445 int function_literal_id_; |
| 1446 |
| 1436 bool allow_natives_; | 1447 bool allow_natives_; |
| 1437 bool allow_tailcalls_; | 1448 bool allow_tailcalls_; |
| 1438 bool allow_harmony_do_expressions_; | 1449 bool allow_harmony_do_expressions_; |
| 1439 bool allow_harmony_function_sent_; | 1450 bool allow_harmony_function_sent_; |
| 1440 bool allow_harmony_async_await_; | 1451 bool allow_harmony_async_await_; |
| 1441 bool allow_harmony_restrictive_generators_; | 1452 bool allow_harmony_restrictive_generators_; |
| 1442 bool allow_harmony_trailing_commas_; | 1453 bool allow_harmony_trailing_commas_; |
| 1443 bool allow_harmony_class_fields_; | 1454 bool allow_harmony_class_fields_; |
| 1444 | 1455 |
| 1445 friend class DiscardableZoneScope; | 1456 friend class DiscardableZoneScope; |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2100 impl()->PushLiteralName(*name); | 2111 impl()->PushLiteralName(*name); |
| 2101 | 2112 |
| 2102 uint32_t index; | 2113 uint32_t index; |
| 2103 return impl()->IsArrayIndex(*name, &index) | 2114 return impl()->IsArrayIndex(*name, &index) |
| 2104 ? factory()->NewNumberLiteral(index, pos) | 2115 ? factory()->NewNumberLiteral(index, pos) |
| 2105 : factory()->NewStringLiteral(*name, pos); | 2116 : factory()->NewStringLiteral(*name, pos); |
| 2106 } | 2117 } |
| 2107 | 2118 |
| 2108 template <typename Impl> | 2119 template <typename Impl> |
| 2109 typename ParserBase<Impl>::ClassLiteralPropertyT | 2120 typename ParserBase<Impl>::ClassLiteralPropertyT |
| 2110 ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker, | 2121 ParserBase<Impl>::ParseClassPropertyDefinition( |
| 2111 bool has_extends, | 2122 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, |
| 2112 bool* is_computed_name, | 2123 bool* has_seen_constructor, ClassLiteralProperty::Kind* property_kind, |
| 2113 bool* has_seen_constructor, | 2124 bool* is_static, bool* ok) { |
| 2114 bool* ok) { | |
| 2115 DCHECK(has_seen_constructor != nullptr); | 2125 DCHECK(has_seen_constructor != nullptr); |
| 2116 bool is_get = false; | 2126 bool is_get = false; |
| 2117 bool is_set = false; | 2127 bool is_set = false; |
| 2118 bool is_generator = false; | 2128 bool is_generator = false; |
| 2119 bool is_async = false; | 2129 bool is_async = false; |
| 2120 bool is_static = false; | 2130 *is_static = false; |
| 2131 *property_kind = ClassLiteralProperty::METHOD; |
| 2121 PropertyKind kind = PropertyKind::kNotSet; | 2132 PropertyKind kind = PropertyKind::kNotSet; |
| 2122 | 2133 |
| 2123 Token::Value name_token = peek(); | 2134 Token::Value name_token = peek(); |
| 2124 | 2135 |
| 2125 IdentifierT name = impl()->EmptyIdentifier(); | 2136 IdentifierT name = impl()->EmptyIdentifier(); |
| 2126 ExpressionT name_expression; | 2137 ExpressionT name_expression; |
| 2127 if (name_token == Token::STATIC) { | 2138 if (name_token == Token::STATIC) { |
| 2128 Consume(Token::STATIC); | 2139 Consume(Token::STATIC); |
| 2129 if (peek() == Token::LPAREN) { | 2140 if (peek() == Token::LPAREN) { |
| 2130 kind = PropertyKind::kMethodProperty; | 2141 kind = PropertyKind::kMethodProperty; |
| 2131 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' | 2142 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' |
| 2132 name_expression = factory()->NewStringLiteral(name, position()); | 2143 name_expression = factory()->NewStringLiteral(name, position()); |
| 2133 } else if (peek() == Token::ASSIGN || peek() == Token::SEMICOLON || | 2144 } else if (peek() == Token::ASSIGN || peek() == Token::SEMICOLON || |
| 2134 peek() == Token::RBRACE) { | 2145 peek() == Token::RBRACE) { |
| 2135 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' | 2146 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' |
| 2136 name_expression = factory()->NewStringLiteral(name, position()); | 2147 name_expression = factory()->NewStringLiteral(name, position()); |
| 2137 } else { | 2148 } else { |
| 2138 is_static = true; | 2149 *is_static = true; |
| 2139 name_expression = ParsePropertyName( | 2150 name_expression = ParsePropertyName( |
| 2140 &name, &kind, &is_generator, &is_get, &is_set, &is_async, | 2151 &name, &kind, &is_generator, &is_get, &is_set, &is_async, |
| 2141 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2152 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
| 2142 } | 2153 } |
| 2143 } else { | 2154 } else { |
| 2144 name_expression = ParsePropertyName( | 2155 name_expression = ParsePropertyName( |
| 2145 &name, &kind, &is_generator, &is_get, &is_set, &is_async, | 2156 &name, &kind, &is_generator, &is_get, &is_set, &is_async, |
| 2146 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2157 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
| 2147 } | 2158 } |
| 2148 | 2159 |
| 2149 switch (kind) { | 2160 switch (kind) { |
| 2150 case PropertyKind::kClassField: | 2161 case PropertyKind::kClassField: |
| 2151 case PropertyKind::kNotSet: // This case is a name followed by a name or | 2162 case PropertyKind::kNotSet: // This case is a name followed by a name or |
| 2152 // other property. Here we have to assume | 2163 // other property. Here we have to assume |
| 2153 // that's an uninitialized field followed by a | 2164 // that's an uninitialized field followed by a |
| 2154 // linebreak followed by a property, with ASI | 2165 // linebreak followed by a property, with ASI |
| 2155 // adding the semicolon. If not, there will be | 2166 // adding the semicolon. If not, there will be |
| 2156 // a syntax error after parsing the first name | 2167 // a syntax error after parsing the first name |
| 2157 // as an uninitialized field. | 2168 // as an uninitialized field. |
| 2158 case PropertyKind::kShorthandProperty: | 2169 case PropertyKind::kShorthandProperty: |
| 2159 case PropertyKind::kValueProperty: | 2170 case PropertyKind::kValueProperty: |
| 2160 if (allow_harmony_class_fields()) { | 2171 if (allow_harmony_class_fields()) { |
| 2161 bool has_initializer = Check(Token::ASSIGN); | 2172 bool has_initializer = Check(Token::ASSIGN); |
| 2162 ExpressionT function_literal = ParseClassFieldForInitializer( | 2173 ExpressionT function_literal = ParseClassFieldForInitializer( |
| 2163 has_initializer, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2174 has_initializer, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
| 2164 ExpectSemicolon(CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2175 ExpectSemicolon(CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
| 2176 *property_kind = ClassLiteralProperty::FIELD; |
| 2165 return factory()->NewClassLiteralProperty( | 2177 return factory()->NewClassLiteralProperty( |
| 2166 name_expression, function_literal, ClassLiteralProperty::FIELD, | 2178 name_expression, function_literal, *property_kind, *is_static, |
| 2167 is_static, *is_computed_name); | 2179 *is_computed_name); |
| 2168 } else { | 2180 } else { |
| 2169 ReportUnexpectedToken(Next()); | 2181 ReportUnexpectedToken(Next()); |
| 2170 *ok = false; | 2182 *ok = false; |
| 2171 return impl()->EmptyClassLiteralProperty(); | 2183 return impl()->EmptyClassLiteralProperty(); |
| 2172 } | 2184 } |
| 2173 | 2185 |
| 2174 case PropertyKind::kMethodProperty: { | 2186 case PropertyKind::kMethodProperty: { |
| 2175 DCHECK(!is_get && !is_set); | 2187 DCHECK(!is_get && !is_set); |
| 2176 | 2188 |
| 2177 // MethodDefinition | 2189 // MethodDefinition |
| 2178 // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' | 2190 // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' |
| 2179 // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' | 2191 // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' |
| 2180 | 2192 |
| 2181 if (!*is_computed_name) { | 2193 if (!*is_computed_name) { |
| 2182 checker->CheckClassMethodName( | 2194 checker->CheckClassMethodName( |
| 2183 name_token, PropertyKind::kMethodProperty, is_generator, is_async, | 2195 name_token, PropertyKind::kMethodProperty, is_generator, is_async, |
| 2184 is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2196 *is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
| 2185 } | 2197 } |
| 2186 | 2198 |
| 2187 FunctionKind kind = is_generator | 2199 FunctionKind kind = is_generator |
| 2188 ? FunctionKind::kConciseGeneratorMethod | 2200 ? FunctionKind::kConciseGeneratorMethod |
| 2189 : is_async ? FunctionKind::kAsyncConciseMethod | 2201 : is_async ? FunctionKind::kAsyncConciseMethod |
| 2190 : FunctionKind::kConciseMethod; | 2202 : FunctionKind::kConciseMethod; |
| 2191 | 2203 |
| 2192 if (!is_static && impl()->IsConstructor(name)) { | 2204 if (!*is_static && impl()->IsConstructor(name)) { |
| 2193 *has_seen_constructor = true; | 2205 *has_seen_constructor = true; |
| 2194 kind = has_extends ? FunctionKind::kSubclassConstructor | 2206 kind = has_extends ? FunctionKind::kSubclassConstructor |
| 2195 : FunctionKind::kBaseConstructor; | 2207 : FunctionKind::kBaseConstructor; |
| 2196 } | 2208 } |
| 2197 | 2209 |
| 2198 ExpressionT value = impl()->ParseFunctionLiteral( | 2210 ExpressionT value = impl()->ParseFunctionLiteral( |
| 2199 name, scanner()->location(), kSkipFunctionNameCheck, kind, | 2211 name, scanner()->location(), kSkipFunctionNameCheck, kind, |
| 2200 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, | 2212 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, |
| 2201 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2213 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
| 2202 | 2214 |
| 2215 *property_kind = ClassLiteralProperty::METHOD; |
| 2203 return factory()->NewClassLiteralProperty(name_expression, value, | 2216 return factory()->NewClassLiteralProperty(name_expression, value, |
| 2204 ClassLiteralProperty::METHOD, | 2217 *property_kind, *is_static, |
| 2205 is_static, *is_computed_name); | 2218 *is_computed_name); |
| 2206 } | 2219 } |
| 2207 | 2220 |
| 2208 case PropertyKind::kAccessorProperty: { | 2221 case PropertyKind::kAccessorProperty: { |
| 2209 DCHECK((is_get || is_set) && !is_generator && !is_async); | 2222 DCHECK((is_get || is_set) && !is_generator && !is_async); |
| 2210 | 2223 |
| 2211 if (!*is_computed_name) { | 2224 if (!*is_computed_name) { |
| 2212 checker->CheckClassMethodName( | 2225 checker->CheckClassMethodName( |
| 2213 name_token, PropertyKind::kAccessorProperty, false, false, | 2226 name_token, PropertyKind::kAccessorProperty, false, false, |
| 2214 is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2227 *is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
| 2215 // Make sure the name expression is a string since we need a Name for | 2228 // Make sure the name expression is a string since we need a Name for |
| 2216 // Runtime_DefineAccessorPropertyUnchecked and since we can determine | 2229 // Runtime_DefineAccessorPropertyUnchecked and since we can determine |
| 2217 // this statically we can skip the extra runtime check. | 2230 // this statically we can skip the extra runtime check. |
| 2218 name_expression = | 2231 name_expression = |
| 2219 factory()->NewStringLiteral(name, name_expression->position()); | 2232 factory()->NewStringLiteral(name, name_expression->position()); |
| 2220 } | 2233 } |
| 2221 | 2234 |
| 2222 FunctionKind kind = is_get ? FunctionKind::kGetterFunction | 2235 FunctionKind kind = is_get ? FunctionKind::kGetterFunction |
| 2223 : FunctionKind::kSetterFunction; | 2236 : FunctionKind::kSetterFunction; |
| 2224 | 2237 |
| 2225 FunctionLiteralT value = impl()->ParseFunctionLiteral( | 2238 FunctionLiteralT value = impl()->ParseFunctionLiteral( |
| 2226 name, scanner()->location(), kSkipFunctionNameCheck, kind, | 2239 name, scanner()->location(), kSkipFunctionNameCheck, kind, |
| 2227 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, | 2240 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, |
| 2228 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2241 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
| 2229 | 2242 |
| 2230 if (!*is_computed_name) { | 2243 if (!*is_computed_name) { |
| 2231 impl()->AddAccessorPrefixToFunctionName(is_get, value, name); | 2244 impl()->AddAccessorPrefixToFunctionName(is_get, value, name); |
| 2232 } | 2245 } |
| 2233 | 2246 |
| 2234 return factory()->NewClassLiteralProperty( | 2247 *property_kind = |
| 2235 name_expression, value, | 2248 is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER; |
| 2236 is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER, | 2249 return factory()->NewClassLiteralProperty(name_expression, value, |
| 2237 is_static, *is_computed_name); | 2250 *property_kind, *is_static, |
| 2251 *is_computed_name); |
| 2238 } | 2252 } |
| 2239 } | 2253 } |
| 2240 UNREACHABLE(); | 2254 UNREACHABLE(); |
| 2241 return impl()->EmptyClassLiteralProperty(); | 2255 return impl()->EmptyClassLiteralProperty(); |
| 2242 } | 2256 } |
| 2243 | 2257 |
| 2244 template <typename Impl> | 2258 template <typename Impl> |
| 2245 typename ParserBase<Impl>::FunctionLiteralT | 2259 typename ParserBase<Impl>::FunctionLiteralT |
| 2246 ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer, | 2260 ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer, |
| 2247 bool* ok) { | 2261 bool* ok) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2265 } | 2279 } |
| 2266 initializer_scope->set_end_position(scanner()->location().end_pos); | 2280 initializer_scope->set_end_position(scanner()->location().end_pos); |
| 2267 typename Types::StatementList body = impl()->NewStatementList(1); | 2281 typename Types::StatementList body = impl()->NewStatementList(1); |
| 2268 body->Add(factory()->NewReturnStatement(value, kNoSourcePosition), zone()); | 2282 body->Add(factory()->NewReturnStatement(value, kNoSourcePosition), zone()); |
| 2269 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( | 2283 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( |
| 2270 impl()->EmptyIdentifierString(), initializer_scope, body, | 2284 impl()->EmptyIdentifierString(), initializer_scope, body, |
| 2271 initializer_state.materialized_literal_count(), | 2285 initializer_state.materialized_literal_count(), |
| 2272 initializer_state.expected_property_count(), 0, 0, | 2286 initializer_state.expected_property_count(), 0, 0, |
| 2273 FunctionLiteral::kNoDuplicateParameters, | 2287 FunctionLiteral::kNoDuplicateParameters, |
| 2274 FunctionLiteral::kAnonymousExpression, default_eager_compile_hint_, | 2288 FunctionLiteral::kAnonymousExpression, default_eager_compile_hint_, |
| 2275 initializer_scope->start_position(), true); | 2289 initializer_scope->start_position(), true, GetNextFunctionLiteralId()); |
| 2276 function_literal->set_is_class_field_initializer(true); | 2290 function_literal->set_is_class_field_initializer(true); |
| 2277 return function_literal; | 2291 return function_literal; |
| 2278 } | 2292 } |
| 2279 | 2293 |
| 2280 template <typename Impl> | 2294 template <typename Impl> |
| 2281 typename ParserBase<Impl>::ObjectLiteralPropertyT | 2295 typename ParserBase<Impl>::ObjectLiteralPropertyT |
| 2282 ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker, | 2296 ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker, |
| 2283 bool* is_computed_name, | 2297 bool* is_computed_name, |
| 2284 bool* ok) { | 2298 bool* ok) { |
| 2285 bool is_get = false; | 2299 bool is_get = false; |
| (...skipping 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3903 // `=> ...` is never a valid expression, so report as syntax error. | 3917 // `=> ...` is never a valid expression, so report as syntax error. |
| 3904 // If next token is not `=>`, it's a syntax error anyways. | 3918 // If next token is not `=>`, it's a syntax error anyways. |
| 3905 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); | 3919 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); |
| 3906 *ok = false; | 3920 *ok = false; |
| 3907 return impl()->EmptyExpression(); | 3921 return impl()->EmptyExpression(); |
| 3908 } | 3922 } |
| 3909 | 3923 |
| 3910 StatementListT body = impl()->NullStatementList(); | 3924 StatementListT body = impl()->NullStatementList(); |
| 3911 int materialized_literal_count = -1; | 3925 int materialized_literal_count = -1; |
| 3912 int expected_property_count = -1; | 3926 int expected_property_count = -1; |
| 3927 int function_literal_id = GetNextFunctionLiteralId(); |
| 3913 | 3928 |
| 3914 FunctionKind kind = formal_parameters.scope->function_kind(); | 3929 FunctionKind kind = formal_parameters.scope->function_kind(); |
| 3915 FunctionLiteral::EagerCompileHint eager_compile_hint = | 3930 FunctionLiteral::EagerCompileHint eager_compile_hint = |
| 3916 default_eager_compile_hint_; | 3931 default_eager_compile_hint_; |
| 3917 bool can_preparse = impl()->parse_lazily() && | 3932 bool can_preparse = impl()->parse_lazily() && |
| 3918 eager_compile_hint == FunctionLiteral::kShouldLazyCompile; | 3933 eager_compile_hint == FunctionLiteral::kShouldLazyCompile; |
| 3919 // TODO(marja): consider lazy-parsing inner arrow functions too. is_this | 3934 // TODO(marja): consider lazy-parsing inner arrow functions too. is_this |
| 3920 // handling in Scope::ResolveVariable needs to change. | 3935 // handling in Scope::ResolveVariable needs to change. |
| 3921 bool is_lazy_top_level_function = | 3936 bool is_lazy_top_level_function = |
| 3922 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables(); | 3937 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables(); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4040 PrintF(" [%s]: %i-%i (arrow function)\n", | 4055 PrintF(" [%s]: %i-%i (arrow function)\n", |
| 4041 is_lazy_top_level_function ? "Preparse no-resolution" : "Full parse", | 4056 is_lazy_top_level_function ? "Preparse no-resolution" : "Full parse", |
| 4042 scope->start_position(), scope->end_position()); | 4057 scope->start_position(), scope->end_position()); |
| 4043 } | 4058 } |
| 4044 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( | 4059 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( |
| 4045 impl()->EmptyIdentifierString(), formal_parameters.scope, body, | 4060 impl()->EmptyIdentifierString(), formal_parameters.scope, body, |
| 4046 materialized_literal_count, expected_property_count, | 4061 materialized_literal_count, expected_property_count, |
| 4047 formal_parameters.num_parameters(), formal_parameters.function_length, | 4062 formal_parameters.num_parameters(), formal_parameters.function_length, |
| 4048 FunctionLiteral::kNoDuplicateParameters, | 4063 FunctionLiteral::kNoDuplicateParameters, |
| 4049 FunctionLiteral::kAnonymousExpression, eager_compile_hint, | 4064 FunctionLiteral::kAnonymousExpression, eager_compile_hint, |
| 4050 formal_parameters.scope->start_position(), has_braces); | 4065 formal_parameters.scope->start_position(), has_braces, |
| 4066 function_literal_id); |
| 4051 | 4067 |
| 4052 function_literal->set_function_token_position( | 4068 function_literal->set_function_token_position( |
| 4053 formal_parameters.scope->start_position()); | 4069 formal_parameters.scope->start_position()); |
| 4054 if (should_be_used_once_hint) { | 4070 if (should_be_used_once_hint) { |
| 4055 function_literal->set_should_be_used_once_hint(); | 4071 function_literal->set_should_be_used_once_hint(); |
| 4056 } | 4072 } |
| 4057 | 4073 |
| 4058 impl()->AddFunctionForNameInference(function_literal); | 4074 impl()->AddFunctionForNameInference(function_literal); |
| 4059 | 4075 |
| 4060 return function_literal; | 4076 return function_literal; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4098 ClassLiteralChecker checker(this); | 4114 ClassLiteralChecker checker(this); |
| 4099 | 4115 |
| 4100 Expect(Token::LBRACE, CHECK_OK); | 4116 Expect(Token::LBRACE, CHECK_OK); |
| 4101 | 4117 |
| 4102 const bool has_extends = !impl()->IsEmptyExpression(class_info.extends); | 4118 const bool has_extends = !impl()->IsEmptyExpression(class_info.extends); |
| 4103 while (peek() != Token::RBRACE) { | 4119 while (peek() != Token::RBRACE) { |
| 4104 if (Check(Token::SEMICOLON)) continue; | 4120 if (Check(Token::SEMICOLON)) continue; |
| 4105 FuncNameInferrer::State fni_state(fni_); | 4121 FuncNameInferrer::State fni_state(fni_); |
| 4106 bool is_computed_name = false; // Classes do not care about computed | 4122 bool is_computed_name = false; // Classes do not care about computed |
| 4107 // property names here. | 4123 // property names here. |
| 4124 bool is_static; |
| 4125 ClassLiteralProperty::Kind property_kind; |
| 4108 ExpressionClassifier property_classifier(this); | 4126 ExpressionClassifier property_classifier(this); |
| 4109 ClassLiteralPropertyT property = ParseClassPropertyDefinition( | 4127 ClassLiteralPropertyT property = ParseClassPropertyDefinition( |
| 4110 &checker, has_extends, &is_computed_name, | 4128 &checker, has_extends, &is_computed_name, |
| 4111 &class_info.has_seen_constructor, CHECK_OK); | 4129 &class_info.has_seen_constructor, &property_kind, &is_static, CHECK_OK); |
| 4112 impl()->RewriteNonPattern(CHECK_OK); | 4130 impl()->RewriteNonPattern(CHECK_OK); |
| 4113 impl()->AccumulateFormalParameterContainmentErrors(); | 4131 impl()->AccumulateFormalParameterContainmentErrors(); |
| 4114 | 4132 |
| 4115 impl()->DeclareClassProperty(name, property, &class_info, CHECK_OK); | 4133 impl()->DeclareClassProperty(name, property, property_kind, is_static, |
| 4134 &class_info, CHECK_OK); |
| 4116 impl()->InferFunctionName(); | 4135 impl()->InferFunctionName(); |
| 4117 } | 4136 } |
| 4118 | 4137 |
| 4119 Expect(Token::RBRACE, CHECK_OK); | 4138 Expect(Token::RBRACE, CHECK_OK); |
| 4120 return impl()->RewriteClassLiteral(name, &class_info, class_token_pos, ok); | 4139 return impl()->RewriteClassLiteral(name, &class_info, class_token_pos, ok); |
| 4121 } | 4140 } |
| 4122 | 4141 |
| 4123 template <typename Impl> | 4142 template <typename Impl> |
| 4124 void ParserBase<Impl>::ParseAsyncFunctionBody(Scope* scope, StatementListT body, | 4143 void ParserBase<Impl>::ParseAsyncFunctionBody(Scope* scope, StatementListT body, |
| 4125 FunctionKind kind, | 4144 FunctionKind kind, |
| (...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5457 has_seen_constructor_ = true; | 5476 has_seen_constructor_ = true; |
| 5458 return; | 5477 return; |
| 5459 } | 5478 } |
| 5460 } | 5479 } |
| 5461 | 5480 |
| 5462 | 5481 |
| 5463 } // namespace internal | 5482 } // namespace internal |
| 5464 } // namespace v8 | 5483 } // namespace v8 |
| 5465 | 5484 |
| 5466 #endif // V8_PARSING_PARSER_BASE_H | 5485 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |