Implicitly pass 'scope()' as parent scope for function scopes

This creates the guarantee that we can compute the parent scope later on. We'll do the same for other types of scopes as well (with perhaps a limited number of exceptions that will need to be eagerly allocated).

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2168563002
Cr-Commit-Position: refs/heads/master@{#37898}
This commit is contained in:
verwaest 2016-07-20 02:35:35 -07:00 committed by Commit bot
parent f2c2ef1f0e
commit 90015a1fe0
4 changed files with 21 additions and 20 deletions

View File

@ -625,9 +625,9 @@ class ParserBase : public Traits {
return result;
}
Scope* NewFunctionScope(Scope* parent, FunctionKind kind) {
Scope* NewFunctionScope(FunctionKind kind) {
DCHECK(ast_value_factory());
Scope* result = new (zone()) Scope(zone(), parent, FUNCTION_SCOPE, kind);
Scope* result = new (zone()) Scope(zone(), scope(), FUNCTION_SCOPE, kind);
result->Initialize();
if (!IsArrowFunction(kind)) {
result->DeclareThis(ast_value_factory());
@ -2314,9 +2314,9 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
ValidateFormalParameterInitializer(&arrow_formals_classifier, ok);
Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos);
Scope* scope = this->NewFunctionScope(
this->scope(), is_async ? FunctionKind::kAsyncArrowFunction
: FunctionKind::kArrowFunction);
Scope* scope =
this->NewFunctionScope(is_async ? FunctionKind::kAsyncArrowFunction
: FunctionKind::kArrowFunction);
// Because the arrow's parameters were parsed in the outer scope, any
// usage flags that might have been triggered there need to be copied
// to the arrow scope.

View File

@ -200,8 +200,8 @@ void Parser::SetCachedData(ParseInfo* info) {
}
FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
bool call_super, Scope* scope,
int pos, int end_pos,
bool call_super, int pos,
int end_pos,
LanguageMode language_mode) {
int materialized_literal_count = -1;
int expected_property_count = -1;
@ -210,7 +210,7 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor
: FunctionKind::kDefaultBaseConstructor;
Scope* function_scope = NewFunctionScope(scope, kind);
Scope* function_scope = NewFunctionScope(kind);
SetLanguageMode(function_scope,
static_cast<LanguageMode>(language_mode | STRICT));
// Set start and end position to the same value
@ -1138,8 +1138,7 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
}
// TODO(adamk): We should construct this scope from the ScopeInfo.
Scope* scope =
NewFunctionScope(this->scope(), FunctionKind::kArrowFunction);
Scope* scope = NewFunctionScope(FunctionKind::kArrowFunction);
// These two bits only need to be explicitly set because we're
// not passing the ScopeInfo to the Scope constructor.
@ -1197,8 +1196,9 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
}
}
} else if (shared_info->is_default_constructor()) {
DCHECK_EQ(this->scope(), scope);
result = DefaultConstructor(
raw_name, IsSubclassConstructor(shared_info->kind()), scope,
raw_name, IsSubclassConstructor(shared_info->kind()),
shared_info->start_position(), shared_info->end_position(),
shared_info->language_mode());
} else {
@ -4294,7 +4294,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
function_name = ast_value_factory()->empty_string();
}
Scope* scope = NewFunctionScope(this->scope(), kind);
Scope* scope = NewFunctionScope(kind);
SetLanguageMode(scope, language_mode);
ZoneList<Statement*>* body = NULL;
int arity = -1;
@ -5091,8 +5091,9 @@ ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
int end_pos = scanner()->location().end_pos;
if (constructor == NULL) {
constructor = DefaultConstructor(name, has_extends, block_scope, pos,
end_pos, block_scope->language_mode());
DCHECK_EQ(this->scope(), block_scope);
constructor = DefaultConstructor(name, has_extends, pos, end_pos,
block_scope->language_mode());
}
// Note that we do not finalize this block scope because it is

View File

@ -543,7 +543,7 @@ class ParserTraits {
Type::ExpressionClassifier* classifier, int pos, bool* ok);
V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type);
V8_INLINE Scope* NewFunctionScope(Scope* parent_scope, FunctionKind kind);
V8_INLINE Scope* NewFunctionScope(FunctionKind kind);
V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters,
Expression* pattern,
@ -1048,7 +1048,7 @@ class Parser : public ParserBase<ParserTraits> {
// Factory methods.
FunctionLiteral* DefaultConstructor(const AstRawString* name, bool call_super,
Scope* scope, int pos, int end_pos,
int pos, int end_pos,
LanguageMode language_mode);
// Skip over a lazy function, either using cached data if we have it, or
@ -1147,8 +1147,8 @@ Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type) {
return parser_->NewScope(parent_scope, scope_type);
}
Scope* ParserTraits::NewFunctionScope(Scope* parent_scope, FunctionKind kind) {
return parser_->NewFunctionScope(parent_scope, kind);
Scope* ParserTraits::NewFunctionScope(FunctionKind kind) {
return parser_->NewFunctionScope(kind);
}
const AstRawString* ParserTraits::EmptyIdentifierString() {

View File

@ -136,7 +136,7 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
FunctionState top_state(&function_state_, &scope_state_, top_scope,
kNormalFunction, &top_factory);
scope()->SetLanguageMode(language_mode);
Scope* function_scope = NewFunctionScope(scope(), kind);
Scope* function_scope = NewFunctionScope(kind);
if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters();
PreParserFactory function_factory(nullptr);
FunctionState function_state(&function_state_, &scope_state_, function_scope,
@ -1111,7 +1111,7 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
// Parse function body.
bool outer_is_script_scope = scope()->is_script_scope();
Scope* function_scope = NewFunctionScope(scope(), kind);
Scope* function_scope = NewFunctionScope(kind);
function_scope->SetLanguageMode(language_mode);
PreParserFactory factory(NULL);
FunctionState function_state(&function_state_, &scope_state_, function_scope,