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 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2215 *is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2215 *is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
2216 } | 2216 } |
2217 | 2217 |
2218 FunctionKind kind = is_generator | 2218 FunctionKind kind = is_generator |
2219 ? FunctionKind::kConciseGeneratorMethod | 2219 ? FunctionKind::kConciseGeneratorMethod |
2220 : is_async ? FunctionKind::kAsyncConciseMethod | 2220 : is_async ? FunctionKind::kAsyncConciseMethod |
2221 : FunctionKind::kConciseMethod; | 2221 : FunctionKind::kConciseMethod; |
2222 | 2222 |
2223 if (!*is_static && impl()->IsConstructor(name)) { | 2223 if (!*is_static && impl()->IsConstructor(name)) { |
2224 *has_seen_constructor = true; | 2224 *has_seen_constructor = true; |
2225 kind = has_extends ? FunctionKind::kSubclassConstructor | 2225 kind = has_extends ? FunctionKind::kDerivedConstructor |
2226 : FunctionKind::kBaseConstructor; | 2226 : FunctionKind::kBaseConstructor; |
2227 } | 2227 } |
2228 | 2228 |
2229 ExpressionT value = impl()->ParseFunctionLiteral( | 2229 ExpressionT value = impl()->ParseFunctionLiteral( |
2230 name, scanner()->location(), kSkipFunctionNameCheck, kind, | 2230 name, scanner()->location(), kSkipFunctionNameCheck, kind, |
2231 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, | 2231 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, |
2232 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2232 language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
2233 | 2233 |
2234 *property_kind = ClassLiteralProperty::METHOD; | 2234 *property_kind = ClassLiteralProperty::METHOD; |
2235 return factory()->NewClassLiteralProperty(name_expression, value, | 2235 return factory()->NewClassLiteralProperty(name_expression, value, |
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3331 DeclarationScope* scope = GetReceiverScope(); | 3331 DeclarationScope* scope = GetReceiverScope(); |
3332 FunctionKind kind = scope->function_kind(); | 3332 FunctionKind kind = scope->function_kind(); |
3333 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || | 3333 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || |
3334 IsClassConstructor(kind)) { | 3334 IsClassConstructor(kind)) { |
3335 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { | 3335 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { |
3336 scope->RecordSuperPropertyUsage(); | 3336 scope->RecordSuperPropertyUsage(); |
3337 return impl()->NewSuperPropertyReference(pos); | 3337 return impl()->NewSuperPropertyReference(pos); |
3338 } | 3338 } |
3339 // new super() is never allowed. | 3339 // new super() is never allowed. |
3340 // super() is only allowed in derived constructor | 3340 // super() is only allowed in derived constructor |
3341 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { | 3341 if (!is_new && peek() == Token::LPAREN && IsDerivedConstructor(kind)) { |
3342 // TODO(rossberg): This might not be the correct FunctionState for the | 3342 // TODO(rossberg): This might not be the correct FunctionState for the |
3343 // method here. | 3343 // method here. |
3344 return impl()->NewSuperCallReference(pos); | 3344 return impl()->NewSuperCallReference(pos); |
3345 } | 3345 } |
3346 } | 3346 } |
3347 | 3347 |
3348 impl()->ReportMessageAt(scanner()->location(), | 3348 impl()->ReportMessageAt(scanner()->location(), |
3349 MessageTemplate::kUnexpectedSuper); | 3349 MessageTemplate::kUnexpectedSuper); |
3350 *ok = false; | 3350 *ok = false; |
3351 return impl()->EmptyExpression(); | 3351 return impl()->EmptyExpression(); |
(...skipping 1553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4905 *ok = false; | 4905 *ok = false; |
4906 return impl()->NullStatement(); | 4906 return impl()->NullStatement(); |
4907 default: | 4907 default: |
4908 break; | 4908 break; |
4909 } | 4909 } |
4910 | 4910 |
4911 Token::Value tok = peek(); | 4911 Token::Value tok = peek(); |
4912 ExpressionT return_value = impl()->EmptyExpression(); | 4912 ExpressionT return_value = impl()->EmptyExpression(); |
4913 if (scanner()->HasAnyLineTerminatorBeforeNext() || tok == Token::SEMICOLON || | 4913 if (scanner()->HasAnyLineTerminatorBeforeNext() || tok == Token::SEMICOLON || |
4914 tok == Token::RBRACE || tok == Token::EOS) { | 4914 tok == Token::RBRACE || tok == Token::EOS) { |
4915 if (IsSubclassConstructor(function_state_->kind())) { | 4915 if (IsDerivedConstructor(function_state_->kind())) { |
4916 return_value = impl()->ThisExpression(loc.beg_pos); | 4916 return_value = impl()->ThisExpression(loc.beg_pos); |
4917 } else { | 4917 } else { |
4918 return_value = impl()->GetLiteralUndefined(position()); | 4918 return_value = impl()->GetLiteralUndefined(position()); |
4919 } | 4919 } |
4920 } else { | 4920 } else { |
4921 if (IsSubclassConstructor(function_state_->kind())) { | 4921 if (IsDerivedConstructor(function_state_->kind())) { |
4922 // Because of the return code rewriting that happens in case of a subclass | 4922 // Because of the return code rewriting that happens in case of a subclass |
4923 // constructor we don't want to accept tail calls, therefore we don't set | 4923 // constructor we don't want to accept tail calls, therefore we don't set |
4924 // ReturnExprScope to kInsideValidReturnStatement here. | 4924 // ReturnExprScope to kInsideValidReturnStatement here. |
4925 return_value = ParseExpression(true, CHECK_OK); | 4925 return_value = ParseExpression(true, CHECK_OK); |
4926 } else { | 4926 } else { |
4927 ReturnExprScope maybe_allow_tail_calls( | 4927 ReturnExprScope maybe_allow_tail_calls( |
4928 function_state_, ReturnExprContext::kInsideValidReturnStatement); | 4928 function_state_, ReturnExprContext::kInsideValidReturnStatement); |
4929 return_value = ParseExpression(true, CHECK_OK); | 4929 return_value = ParseExpression(true, CHECK_OK); |
4930 | 4930 |
4931 if (allow_tailcalls() && !is_sloppy(language_mode()) && !is_resumable()) { | 4931 if (allow_tailcalls() && !is_sloppy(language_mode()) && !is_resumable()) { |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5499 has_seen_constructor_ = true; | 5499 has_seen_constructor_ = true; |
5500 return; | 5500 return; |
5501 } | 5501 } |
5502 } | 5502 } |
5503 | 5503 |
5504 | 5504 |
5505 } // namespace internal | 5505 } // namespace internal |
5506 } // namespace v8 | 5506 } // namespace v8 |
5507 | 5507 |
5508 #endif // V8_PARSING_PARSER_BASE_H | 5508 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |