Chromium Code Reviews| Index: src/preparser.h |
| diff --git a/src/preparser.h b/src/preparser.h |
| index 36320513adb872f5ef4f51d450551af9ab1499d8..5dc561b671dedff68138aee8475c6871b3704d28 100644 |
| --- a/src/preparser.h |
| +++ b/src/preparser.h |
| @@ -345,12 +345,16 @@ class ParserBase : public Traits { |
| Mode old_mode_; |
| }; |
| - Scope* NewScope(Scope* parent, ScopeType scope_type, |
| - FunctionKind kind = kNormalFunction) { |
| + Scope* NewScope(Scope* parent, ScopeType scope_type) { |
| + // Must always pass the function kind for FUNCTION_SCOPE and ARROW_SCOPE. |
| + DCHECK(scope_type != FUNCTION_SCOPE && scope_type != ARROW_SCOPE); |
| + return NewScope(parent, scope_type, kNormalFunction); |
| + } |
| + |
| + Scope* NewScope(Scope* parent, ScopeType scope_type, FunctionKind kind) { |
| DCHECK(ast_value_factory()); |
| DCHECK(scope_type != MODULE_SCOPE || allow_harmony_modules()); |
| - DCHECK((scope_type == FUNCTION_SCOPE && IsValidFunctionKind(kind)) || |
| - kind == kNormalFunction); |
| + DCHECK(scope_type != ARROW_SCOPE || IsArrowFunction(kind)); |
| Scope* result = new (zone()) |
| Scope(zone(), parent, scope_type, ast_value_factory(), kind); |
| result->Initialize(); |
| @@ -2173,7 +2177,8 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, |
| Consume(Token::LPAREN); |
| if (allow_harmony_arrow_functions() && Check(Token::RPAREN)) { |
| // As a primary expression, the only thing that can follow "()" is "=>". |
| - Scope* scope = this->NewScope(scope_, ARROW_SCOPE); |
| + Scope* scope = |
| + this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
| scope->set_start_position(beg_pos); |
| FormalParameterErrorLocations error_locs; |
| bool has_rest = false; |
| @@ -2654,7 +2659,8 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, |
| FormalParameterErrorLocations error_locs; |
| Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos); |
| bool has_rest = false; |
| - Scope* scope = this->NewScope(scope_, ARROW_SCOPE); |
| + Scope* scope = |
| + this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
| scope->set_start_position(lhs_location.beg_pos); |
| this->ParseArrowFunctionFormalParameters(scope, expression, loc, |
| &error_locs, &has_rest, CHECK_OK); |
| @@ -3251,19 +3257,20 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new, |
| bool* ok) { |
| Expect(Token::SUPER, CHECK_OK); |
| - // TODO(wingo): Does this actually work with lazily compiled arrows? |
| - FunctionState* function_state = function_state_; |
| - while (IsArrowFunction(function_state->kind())) { |
| - function_state = function_state->outer(); |
| + Scope* scope = scope_->DeclarationScope(); |
| + |
| + while (scope->is_eval_scope() || scope->is_arrow_scope()) { |
| + scope = scope->outer_scope(); |
| + DCHECK_NOT_NULL(scope); |
| + scope = scope->DeclarationScope(); |
| } |
|
wingo
2015/05/06 14:47:38
Sounds like we could use a this_declaration_scope(
arv (Not doing code reviews)
2015/05/06 14:57:19
Yes. That would be perfect for both super and new.
|
| - // TODO(arv): Handle eval scopes similarly. |
| - FunctionKind kind = function_state->kind(); |
| + FunctionKind kind = scope->function_kind(); |
| if (IsConciseMethod(kind) || IsAccessorFunction(kind) || |
| i::IsConstructor(kind)) { |
| if (peek() == Token::PERIOD || peek() == Token::LBRACK) { |
| - scope_->RecordSuperPropertyUsage(); |
| - return this->SuperReference(scope_, factory()); |
| + scope->RecordSuperPropertyUsage(); |
| + return this->SuperReference(scope, factory()); |
| } |
| // new super() is never allowed. |
| // super() is only allowed in derived constructor |
| @@ -3274,8 +3281,10 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new, |
| *ok = false; |
| return this->EmptyExpression(); |
| } |
| - function_state->set_super_location(scanner()->location()); |
| - return this->SuperReference(scope_, factory()); |
| + // TODO(rossberg): This might not be the correct FunctionState for the |
|
arv (Not doing code reviews)
2015/04/24 15:15:41
Andreas, I'll remove this todo since you said you
|
| + // method here. |
| + function_state_->set_super_location(scanner()->location()); |
| + return this->SuperReference(scope, factory()); |
| } |
| } |