Index: src/preparser.h |
diff --git a/src/preparser.h b/src/preparser.h |
index c14fb9b20cdc067c3f37b86938138aa648b73daa..a505b45960fb713eb32e93c3a87d40b5809eb9e0 100644 |
--- a/src/preparser.h |
+++ b/src/preparser.h |
@@ -334,12 +334,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(); |
@@ -1705,7 +1709,8 @@ class PreParserTraits { |
} |
static PreParserExpression SuperReference(Scope* scope, |
- PreParserFactory* factory) { |
+ PreParserFactory* factory, |
+ int pos) { |
return PreParserExpression::Default(); |
} |
@@ -2387,7 +2392,8 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, |
classifier->RecordBindingPatternError(scanner()->location(), |
MessageTemplate::kUnexpectedToken, |
Token::String(Token::RPAREN)); |
- Scope* scope = this->NewScope(scope_, ARROW_SCOPE); |
+ Scope* scope = |
+ this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
scope->set_start_position(beg_pos); |
ExpressionClassifier args_classifier; |
bool has_rest = false; |
@@ -2913,7 +2919,8 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, |
CHECK_OK); |
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); |
Scanner::Location duplicate_loc = Scanner::Location::invalid(); |
this->ParseArrowFunctionFormalParameters(scope, expression, loc, &has_rest, |
@@ -3500,7 +3507,7 @@ ParserBase<Traits>::ParseStrongSuperCallExpression( |
Consume(Token::SUPER); |
int pos = position(); |
Scanner::Location super_loc = scanner()->location(); |
- ExpressionT expr = this->SuperReference(scope_, factory()); |
+ ExpressionT expr = this->SuperReference(scope_, factory(), pos); |
if (peek() != Token::LPAREN) { |
ReportMessage(MessageTemplate::kStrongConstructorSuper); |
@@ -3549,21 +3556,23 @@ typename ParserBase<Traits>::ExpressionT |
ParserBase<Traits>::ParseSuperExpression(bool is_new, |
ExpressionClassifier* classifier, |
bool* ok) { |
+ int pos = position(); |
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(); |
} |
- // 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(), pos); |
} |
// new super() is never allowed. |
// super() is only allowed in derived constructor |
@@ -3575,8 +3584,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 |
+ // method here. |
+ function_state_->set_super_location(scanner()->location()); |
+ return this->SuperReference(scope_, factory(), pos); |
} |
} |