| 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/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
| (...skipping 3493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3504 int pos = position(); | 3504 int pos = position(); |
| 3505 Expect(Token::SUPER, CHECK_OK); | 3505 Expect(Token::SUPER, CHECK_OK); |
| 3506 | 3506 |
| 3507 Scope* scope = scope_->DeclarationScope(); | 3507 Scope* scope = scope_->DeclarationScope(); |
| 3508 while (scope->is_eval_scope() || scope->is_arrow_scope()) { | 3508 while (scope->is_eval_scope() || scope->is_arrow_scope()) { |
| 3509 scope = scope->outer_scope(); | 3509 scope = scope->outer_scope(); |
| 3510 DCHECK_NOT_NULL(scope); | 3510 DCHECK_NOT_NULL(scope); |
| 3511 scope = scope->DeclarationScope(); | 3511 scope = scope->DeclarationScope(); |
| 3512 } | 3512 } |
| 3513 | 3513 |
| 3514 if (scope->is_block_scope() && scope->is_declaration_scope()) { |
| 3515 scope = scope->outer_scope(); |
| 3516 DCHECK(scope->is_function_scope()); |
| 3517 } |
| 3518 |
| 3514 FunctionKind kind = scope->function_kind(); | 3519 FunctionKind kind = scope->function_kind(); |
| 3515 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || | 3520 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || |
| 3516 i::IsConstructor(kind)) { | 3521 i::IsConstructor(kind)) { |
| 3517 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { | 3522 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { |
| 3518 scope->RecordSuperPropertyUsage(); | 3523 scope->RecordSuperPropertyUsage(); |
| 3519 return this->SuperPropertyReference(scope_, factory(), pos); | 3524 return this->SuperPropertyReference(scope_, factory(), pos); |
| 3520 } | 3525 } |
| 3521 // new super() is never allowed. | 3526 // new super() is never allowed. |
| 3522 // super() is only allowed in derived constructor | 3527 // super() is only allowed in derived constructor |
| 3523 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { | 3528 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3547 int pos = position(); | 3552 int pos = position(); |
| 3548 Consume(Token::PERIOD); | 3553 Consume(Token::PERIOD); |
| 3549 ExpectContextualKeyword(CStrVector("target"), CHECK_OK); | 3554 ExpectContextualKeyword(CStrVector("target"), CHECK_OK); |
| 3550 | 3555 |
| 3551 Scope* scope = scope_->DeclarationScope(); | 3556 Scope* scope = scope_->DeclarationScope(); |
| 3552 while (scope->is_eval_scope() || scope->is_arrow_scope()) { | 3557 while (scope->is_eval_scope() || scope->is_arrow_scope()) { |
| 3553 scope = scope->outer_scope(); | 3558 scope = scope->outer_scope(); |
| 3554 DCHECK_NOT_NULL(scope); | 3559 DCHECK_NOT_NULL(scope); |
| 3555 scope = scope->DeclarationScope(); | 3560 scope = scope->DeclarationScope(); |
| 3556 } | 3561 } |
| 3557 | 3562 if (scope->is_block_scope() && scope->is_declaration_scope()) { |
| 3563 // Inner function scope |
| 3564 scope = scope->outer_scope(); |
| 3565 DCHECK(scope->is_function_scope()); |
| 3566 } |
| 3558 if (!scope->is_function_scope()) { | 3567 if (!scope->is_function_scope()) { |
| 3559 ReportMessageAt(scanner()->location(), | 3568 ReportMessageAt(scanner()->location(), |
| 3560 MessageTemplate::kUnexpectedNewTarget); | 3569 MessageTemplate::kUnexpectedNewTarget); |
| 3561 *ok = false; | 3570 *ok = false; |
| 3562 return this->EmptyExpression(); | 3571 return this->EmptyExpression(); |
| 3563 } | 3572 } |
| 3564 | 3573 |
| 3565 return this->NewTargetExpression(scope_, factory(), pos); | 3574 return this->NewTargetExpression(scope_, factory(), pos); |
| 3566 } | 3575 } |
| 3567 | 3576 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3693 if (!*ok) return -1; | 3702 if (!*ok) return -1; |
| 3694 } while (!parsing_state->has_rest && Check(Token::COMMA)); | 3703 } while (!parsing_state->has_rest && Check(Token::COMMA)); |
| 3695 | 3704 |
| 3696 if (parsing_state->has_rest && peek() == Token::COMMA) { | 3705 if (parsing_state->has_rest && peek() == Token::COMMA) { |
| 3697 ReportMessageAt(scanner()->peek_location(), | 3706 ReportMessageAt(scanner()->peek_location(), |
| 3698 MessageTemplate::kParamAfterRest); | 3707 MessageTemplate::kParamAfterRest); |
| 3699 *ok = false; | 3708 *ok = false; |
| 3700 return -1; | 3709 return -1; |
| 3701 } | 3710 } |
| 3702 } | 3711 } |
| 3703 | |
| 3704 return parameter_count; | 3712 return parameter_count; |
| 3705 } | 3713 } |
| 3706 | 3714 |
| 3707 | 3715 |
| 3708 template <class Traits> | 3716 template <class Traits> |
| 3709 void ParserBase<Traits>::CheckArityRestrictions( | 3717 void ParserBase<Traits>::CheckArityRestrictions( |
| 3710 int param_count, FunctionLiteral::ArityRestriction arity_restriction, | 3718 int param_count, FunctionLiteral::ArityRestriction arity_restriction, |
| 3711 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok) { | 3719 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok) { |
| 3712 switch (arity_restriction) { | 3720 switch (arity_restriction) { |
| 3713 case FunctionLiteral::GETTER_ARITY: | 3721 case FunctionLiteral::GETTER_ARITY: |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4025 *ok = false; | 4033 *ok = false; |
| 4026 return; | 4034 return; |
| 4027 } | 4035 } |
| 4028 has_seen_constructor_ = true; | 4036 has_seen_constructor_ = true; |
| 4029 return; | 4037 return; |
| 4030 } | 4038 } |
| 4031 } | 4039 } |
| 4032 } } // v8::internal | 4040 } } // v8::internal |
| 4033 | 4041 |
| 4034 #endif // V8_PREPARSER_H | 4042 #endif // V8_PREPARSER_H |
| OLD | NEW |