| 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 2136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2147 DCHECK(has_seen_constructor != nullptr); | 2147 DCHECK(has_seen_constructor != nullptr); |
| 2148 bool is_get = false; | 2148 bool is_get = false; |
| 2149 bool is_set = false; | 2149 bool is_set = false; |
| 2150 bool is_generator = false; | 2150 bool is_generator = false; |
| 2151 bool is_async = false; | 2151 bool is_async = false; |
| 2152 bool is_static = false; | 2152 bool is_static = false; |
| 2153 PropertyKind kind = PropertyKind::kNotSet; | 2153 PropertyKind kind = PropertyKind::kNotSet; |
| 2154 | 2154 |
| 2155 Token::Value name_token = peek(); | 2155 Token::Value name_token = peek(); |
| 2156 | 2156 |
| 2157 int function_token_position = scanner()->peek_location().beg_pos; |
| 2157 IdentifierT name = impl()->EmptyIdentifier(); | 2158 IdentifierT name = impl()->EmptyIdentifier(); |
| 2158 ExpressionT name_expression; | 2159 ExpressionT name_expression; |
| 2159 if (name_token == Token::STATIC) { | 2160 if (name_token == Token::STATIC) { |
| 2160 Consume(Token::STATIC); | 2161 Consume(Token::STATIC); |
| 2162 function_token_position = scanner()->peek_location().beg_pos; |
| 2161 if (peek() == Token::LPAREN) { | 2163 if (peek() == Token::LPAREN) { |
| 2162 kind = PropertyKind::kMethodProperty; | 2164 kind = PropertyKind::kMethodProperty; |
| 2163 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' | 2165 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' |
| 2164 name_expression = factory()->NewStringLiteral(name, position()); | 2166 name_expression = factory()->NewStringLiteral(name, position()); |
| 2165 } else if (peek() == Token::ASSIGN || peek() == Token::SEMICOLON || | 2167 } else if (peek() == Token::ASSIGN || peek() == Token::SEMICOLON || |
| 2166 peek() == Token::RBRACE) { | 2168 peek() == Token::RBRACE) { |
| 2167 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' | 2169 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' |
| 2168 name_expression = factory()->NewStringLiteral(name, position()); | 2170 name_expression = factory()->NewStringLiteral(name, position()); |
| 2169 } else { | 2171 } else { |
| 2170 is_static = true; | 2172 is_static = true; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2222 : FunctionKind::kConciseMethod; | 2224 : FunctionKind::kConciseMethod; |
| 2223 | 2225 |
| 2224 if (!is_static && impl()->IsConstructor(name)) { | 2226 if (!is_static && impl()->IsConstructor(name)) { |
| 2225 *has_seen_constructor = true; | 2227 *has_seen_constructor = true; |
| 2226 kind = has_extends ? FunctionKind::kSubclassConstructor | 2228 kind = has_extends ? FunctionKind::kSubclassConstructor |
| 2227 : FunctionKind::kBaseConstructor; | 2229 : FunctionKind::kBaseConstructor; |
| 2228 } | 2230 } |
| 2229 | 2231 |
| 2230 ExpressionT value = impl()->ParseFunctionLiteral( | 2232 ExpressionT value = impl()->ParseFunctionLiteral( |
| 2231 name, scanner()->location(), kSkipFunctionNameCheck, kind, | 2233 name, scanner()->location(), kSkipFunctionNameCheck, kind, |
| 2232 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, | 2234 FLAG_harmony_function_tostring ? function_token_position |
| 2233 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2235 : kNoSourcePosition, |
| 2236 FunctionLiteral::kAccessorOrMethod, language_mode(), |
| 2237 CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
| 2234 | 2238 |
| 2235 return factory()->NewClassLiteralProperty(name_expression, value, | 2239 return factory()->NewClassLiteralProperty(name_expression, value, |
| 2236 ClassLiteralProperty::METHOD, | 2240 ClassLiteralProperty::METHOD, |
| 2237 is_static, *is_computed_name); | 2241 is_static, *is_computed_name); |
| 2238 } | 2242 } |
| 2239 | 2243 |
| 2240 case PropertyKind::kAccessorProperty: { | 2244 case PropertyKind::kAccessorProperty: { |
| 2241 DCHECK((is_get || is_set) && !is_generator && !is_async); | 2245 DCHECK((is_get || is_set) && !is_generator && !is_async); |
| 2242 | 2246 |
| 2243 if (!*is_computed_name) { | 2247 if (!*is_computed_name) { |
| 2244 checker->CheckClassMethodName( | 2248 checker->CheckClassMethodName( |
| 2245 name_token, PropertyKind::kAccessorProperty, false, false, | 2249 name_token, PropertyKind::kAccessorProperty, false, false, |
| 2246 is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2250 is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
| 2247 // Make sure the name expression is a string since we need a Name for | 2251 // Make sure the name expression is a string since we need a Name for |
| 2248 // Runtime_DefineAccessorPropertyUnchecked and since we can determine | 2252 // Runtime_DefineAccessorPropertyUnchecked and since we can determine |
| 2249 // this statically we can skip the extra runtime check. | 2253 // this statically we can skip the extra runtime check. |
| 2250 name_expression = | 2254 name_expression = |
| 2251 factory()->NewStringLiteral(name, name_expression->position()); | 2255 factory()->NewStringLiteral(name, name_expression->position()); |
| 2252 } | 2256 } |
| 2253 | 2257 |
| 2254 FunctionKind kind = is_get ? FunctionKind::kGetterFunction | 2258 FunctionKind kind = is_get ? FunctionKind::kGetterFunction |
| 2255 : FunctionKind::kSetterFunction; | 2259 : FunctionKind::kSetterFunction; |
| 2256 | 2260 |
| 2257 FunctionLiteralT value = impl()->ParseFunctionLiteral( | 2261 FunctionLiteralT value = impl()->ParseFunctionLiteral( |
| 2258 name, scanner()->location(), kSkipFunctionNameCheck, kind, | 2262 name, scanner()->location(), kSkipFunctionNameCheck, kind, |
| 2259 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, | 2263 FLAG_harmony_function_tostring ? function_token_position |
| 2260 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2264 : kNoSourcePosition, |
| 2265 FunctionLiteral::kAccessorOrMethod, language_mode(), |
| 2266 CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
| 2261 | 2267 |
| 2262 if (!*is_computed_name) { | 2268 if (!*is_computed_name) { |
| 2263 impl()->AddAccessorPrefixToFunctionName(is_get, value, name); | 2269 impl()->AddAccessorPrefixToFunctionName(is_get, value, name); |
| 2264 } | 2270 } |
| 2265 | 2271 |
| 2266 return factory()->NewClassLiteralProperty( | 2272 return factory()->NewClassLiteralProperty( |
| 2267 name_expression, value, | 2273 name_expression, value, |
| 2268 is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER, | 2274 is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER, |
| 2269 is_static, *is_computed_name); | 2275 is_static, *is_computed_name); |
| 2270 } | 2276 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2430 Scanner::Location(next_beg_pos, scanner()->location().end_pos), | 2436 Scanner::Location(next_beg_pos, scanner()->location().end_pos), |
| 2431 MessageTemplate::kInvalidDestructuringTarget); | 2437 MessageTemplate::kInvalidDestructuringTarget); |
| 2432 | 2438 |
| 2433 FunctionKind kind = is_generator | 2439 FunctionKind kind = is_generator |
| 2434 ? FunctionKind::kConciseGeneratorMethod | 2440 ? FunctionKind::kConciseGeneratorMethod |
| 2435 : is_async ? FunctionKind::kAsyncConciseMethod | 2441 : is_async ? FunctionKind::kAsyncConciseMethod |
| 2436 : FunctionKind::kConciseMethod; | 2442 : FunctionKind::kConciseMethod; |
| 2437 | 2443 |
| 2438 ExpressionT value = impl()->ParseFunctionLiteral( | 2444 ExpressionT value = impl()->ParseFunctionLiteral( |
| 2439 name, scanner()->location(), kSkipFunctionNameCheck, kind, | 2445 name, scanner()->location(), kSkipFunctionNameCheck, kind, |
| 2440 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, | 2446 FLAG_harmony_function_tostring ? next_beg_pos : kNoSourcePosition, |
| 2441 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2447 FunctionLiteral::kAccessorOrMethod, language_mode(), |
| 2448 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2442 | 2449 |
| 2443 return factory()->NewObjectLiteralProperty( | 2450 return factory()->NewObjectLiteralProperty( |
| 2444 name_expression, value, ObjectLiteralProperty::COMPUTED, | 2451 name_expression, value, ObjectLiteralProperty::COMPUTED, |
| 2445 *is_computed_name); | 2452 *is_computed_name); |
| 2446 } | 2453 } |
| 2447 | 2454 |
| 2448 case PropertyKind::kAccessorProperty: { | 2455 case PropertyKind::kAccessorProperty: { |
| 2449 DCHECK((is_get || is_set) && !(is_set && is_get) && !is_generator && | 2456 DCHECK((is_get || is_set) && !(is_set && is_get) && !is_generator && |
| 2450 !is_async); | 2457 !is_async); |
| 2451 | 2458 |
| 2452 classifier()->RecordPatternError( | 2459 classifier()->RecordPatternError( |
| 2453 Scanner::Location(next_beg_pos, scanner()->location().end_pos), | 2460 Scanner::Location(next_beg_pos, scanner()->location().end_pos), |
| 2454 MessageTemplate::kInvalidDestructuringTarget); | 2461 MessageTemplate::kInvalidDestructuringTarget); |
| 2455 | 2462 |
| 2456 if (!*is_computed_name) { | 2463 if (!*is_computed_name) { |
| 2457 // Make sure the name expression is a string since we need a Name for | 2464 // Make sure the name expression is a string since we need a Name for |
| 2458 // Runtime_DefineAccessorPropertyUnchecked and since we can determine | 2465 // Runtime_DefineAccessorPropertyUnchecked and since we can determine |
| 2459 // this statically we can skip the extra runtime check. | 2466 // this statically we can skip the extra runtime check. |
| 2460 name_expression = | 2467 name_expression = |
| 2461 factory()->NewStringLiteral(name, name_expression->position()); | 2468 factory()->NewStringLiteral(name, name_expression->position()); |
| 2462 } | 2469 } |
| 2463 | 2470 |
| 2464 FunctionKind kind = is_get ? FunctionKind::kGetterFunction | 2471 FunctionKind kind = is_get ? FunctionKind::kGetterFunction |
| 2465 : FunctionKind::kSetterFunction; | 2472 : FunctionKind::kSetterFunction; |
| 2466 | 2473 |
| 2467 FunctionLiteralT value = impl()->ParseFunctionLiteral( | 2474 FunctionLiteralT value = impl()->ParseFunctionLiteral( |
| 2468 name, scanner()->location(), kSkipFunctionNameCheck, kind, | 2475 name, scanner()->location(), kSkipFunctionNameCheck, kind, |
| 2469 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, | 2476 FLAG_harmony_function_tostring ? next_beg_pos : kNoSourcePosition, |
| 2470 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2477 FunctionLiteral::kAccessorOrMethod, language_mode(), |
| 2478 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| 2471 | 2479 |
| 2472 if (!*is_computed_name) { | 2480 if (!*is_computed_name) { |
| 2473 impl()->AddAccessorPrefixToFunctionName(is_get, value, name); | 2481 impl()->AddAccessorPrefixToFunctionName(is_get, value, name); |
| 2474 } | 2482 } |
| 2475 | 2483 |
| 2476 return factory()->NewObjectLiteralProperty( | 2484 return factory()->NewObjectLiteralProperty( |
| 2477 name_expression, value, is_get ? ObjectLiteralProperty::GETTER | 2485 name_expression, value, is_get ? ObjectLiteralProperty::GETTER |
| 2478 : ObjectLiteralProperty::SETTER, | 2486 : ObjectLiteralProperty::SETTER, |
| 2479 *is_computed_name); | 2487 *is_computed_name); |
| 2480 } | 2488 } |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3290 } | 3298 } |
| 3291 | 3299 |
| 3292 FunctionKind function_kind = Check(Token::MUL) | 3300 FunctionKind function_kind = Check(Token::MUL) |
| 3293 ? FunctionKind::kGeneratorFunction | 3301 ? FunctionKind::kGeneratorFunction |
| 3294 : FunctionKind::kNormalFunction; | 3302 : FunctionKind::kNormalFunction; |
| 3295 IdentifierT name = impl()->EmptyIdentifier(); | 3303 IdentifierT name = impl()->EmptyIdentifier(); |
| 3296 bool is_strict_reserved_name = false; | 3304 bool is_strict_reserved_name = false; |
| 3297 Scanner::Location function_name_location = Scanner::Location::invalid(); | 3305 Scanner::Location function_name_location = Scanner::Location::invalid(); |
| 3298 FunctionLiteral::FunctionType function_type = | 3306 FunctionLiteral::FunctionType function_type = |
| 3299 FunctionLiteral::kAnonymousExpression; | 3307 FunctionLiteral::kAnonymousExpression; |
| 3300 if (peek_any_identifier()) { | 3308 if (impl()->IgnoreFunctionName()) { |
| 3309 // Consume and discard the next token, which is always the identifier |
| 3310 // "anonymous". |
| 3311 Consume(Token::IDENTIFIER); |
| 3312 } else if (peek_any_identifier()) { |
| 3301 name = ParseIdentifierOrStrictReservedWord( | 3313 name = ParseIdentifierOrStrictReservedWord( |
| 3302 function_kind, &is_strict_reserved_name, CHECK_OK); | 3314 function_kind, &is_strict_reserved_name, CHECK_OK); |
| 3303 function_name_location = scanner()->location(); | 3315 function_name_location = scanner()->location(); |
| 3304 function_type = FunctionLiteral::kNamedExpression; | 3316 function_type = FunctionLiteral::kNamedExpression; |
| 3305 } | 3317 } |
| 3306 result = impl()->ParseFunctionLiteral( | 3318 result = impl()->ParseFunctionLiteral( |
| 3307 name, function_name_location, | 3319 name, function_name_location, |
| 3308 is_strict_reserved_name ? kFunctionNameIsStrictReserved | 3320 is_strict_reserved_name ? kFunctionNameIsStrictReserved |
| 3309 : kFunctionNameValidityUnknown, | 3321 : kFunctionNameValidityUnknown, |
| 3310 function_kind, function_token_position, function_type, language_mode(), | 3322 function_kind, function_token_position, function_type, language_mode(), |
| (...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4156 // | 4168 // |
| 4157 // async [no LineTerminator here] function BindingIdentifier[Await] | 4169 // async [no LineTerminator here] function BindingIdentifier[Await] |
| 4158 // ( FormalParameters[Await] ) { AsyncFunctionBody } | 4170 // ( FormalParameters[Await] ) { AsyncFunctionBody } |
| 4159 DCHECK_EQ(scanner()->current_token(), Token::ASYNC); | 4171 DCHECK_EQ(scanner()->current_token(), Token::ASYNC); |
| 4160 int pos = position(); | 4172 int pos = position(); |
| 4161 Expect(Token::FUNCTION, CHECK_OK); | 4173 Expect(Token::FUNCTION, CHECK_OK); |
| 4162 bool is_strict_reserved = false; | 4174 bool is_strict_reserved = false; |
| 4163 IdentifierT name = impl()->EmptyIdentifier(); | 4175 IdentifierT name = impl()->EmptyIdentifier(); |
| 4164 FunctionLiteral::FunctionType type = FunctionLiteral::kAnonymousExpression; | 4176 FunctionLiteral::FunctionType type = FunctionLiteral::kAnonymousExpression; |
| 4165 | 4177 |
| 4166 if (peek_any_identifier()) { | 4178 if (impl()->IgnoreFunctionName()) { |
| 4179 // Consume and discard the next token, which is always the identifier |
| 4180 // "anonymous". |
| 4181 Consume(Token::IDENTIFIER); |
| 4182 } else if (peek_any_identifier()) { |
| 4167 type = FunctionLiteral::kNamedExpression; | 4183 type = FunctionLiteral::kNamedExpression; |
| 4168 name = ParseIdentifierOrStrictReservedWord(FunctionKind::kAsyncFunction, | 4184 name = ParseIdentifierOrStrictReservedWord(FunctionKind::kAsyncFunction, |
| 4169 &is_strict_reserved, CHECK_OK); | 4185 &is_strict_reserved, CHECK_OK); |
| 4170 } | 4186 } |
| 4171 return impl()->ParseFunctionLiteral( | 4187 return impl()->ParseFunctionLiteral( |
| 4172 name, scanner()->location(), | 4188 name, scanner()->location(), |
| 4173 is_strict_reserved ? kFunctionNameIsStrictReserved | 4189 is_strict_reserved ? kFunctionNameIsStrictReserved |
| 4174 : kFunctionNameValidityUnknown, | 4190 : kFunctionNameValidityUnknown, |
| 4175 FunctionKind::kAsyncFunction, pos, type, language_mode(), CHECK_OK); | 4191 FunctionKind::kAsyncFunction, pos, type, language_mode(), CHECK_OK); |
| 4176 } | 4192 } |
| (...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5463 has_seen_constructor_ = true; | 5479 has_seen_constructor_ = true; |
| 5464 return; | 5480 return; |
| 5465 } | 5481 } |
| 5466 } | 5482 } |
| 5467 | 5483 |
| 5468 | 5484 |
| 5469 } // namespace internal | 5485 } // namespace internal |
| 5470 } // namespace v8 | 5486 } // namespace v8 |
| 5471 | 5487 |
| 5472 #endif // V8_PARSING_PARSER_BASE_H | 5488 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |