Commit 13cbf545 authored by verwaest's avatar verwaest Committed by Commit bot

Inline Scope::Initialize into the only constructor that's always called right before

This additionally makes the invariant obvious that outer_scope==nullptr+is_with_scope is impossible.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2165923002
Cr-Commit-Position: refs/heads/master@{#37902}
parent a76d133f
...@@ -98,17 +98,20 @@ Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, ...@@ -98,17 +98,20 @@ Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type,
sloppy_block_function_map_(zone), sloppy_block_function_map_(zone),
already_resolved_(false) { already_resolved_(false) {
SetDefaults(); SetDefaults();
if (outer_scope != nullptr) { if (outer_scope == nullptr) {
// If the outer scope is null, this cannot be a with scope. The outermost
// scope must be a script scope.
DCHECK_EQ(SCRIPT_SCOPE, scope_type);
} else {
asm_function_ = outer_scope_->asm_module_; asm_function_ = outer_scope_->asm_module_;
// Inherit the language mode from the parent scope unless we're a module // Inherit the language mode from the parent scope unless we're a module
// scope. // scope.
if (!is_module_scope()) language_mode_ = outer_scope->language_mode_; if (!is_module_scope()) language_mode_ = outer_scope->language_mode_;
force_context_allocation_ = force_context_allocation_ =
!is_function_scope() && outer_scope->has_forced_context_allocation(); !is_function_scope() && outer_scope->has_forced_context_allocation();
outer_scope_->inner_scopes_.Add(this, zone);
scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope();
} }
// The outermost scope must be a script scope.
DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != nullptr);
} }
Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type,
...@@ -285,17 +288,6 @@ bool Scope::Analyze(ParseInfo* info) { ...@@ -285,17 +288,6 @@ bool Scope::Analyze(ParseInfo* info) {
return true; return true;
} }
void Scope::Initialize() {
DCHECK(!already_resolved());
if (outer_scope_ == nullptr) {
scope_inside_with_ = is_with_scope();
} else {
outer_scope_->inner_scopes_.Add(this, zone());
scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope();
}
}
void Scope::DeclareThis(AstValueFactory* ast_value_factory) { void Scope::DeclareThis(AstValueFactory* ast_value_factory) {
DCHECK(!already_resolved()); DCHECK(!already_resolved());
DCHECK(is_declaration_scope()); DCHECK(is_declaration_scope());
......
...@@ -106,7 +106,6 @@ class Scope: public ZoneObject { ...@@ -106,7 +106,6 @@ class Scope: public ZoneObject {
scope_name_ = scope_name; scope_name_ = scope_name;
} }
void Initialize();
void DeclareThis(AstValueFactory* ast_value_factory); void DeclareThis(AstValueFactory* ast_value_factory);
void DeclareDefaultFunctionVariables(AstValueFactory* ast_value_factory); void DeclareDefaultFunctionVariables(AstValueFactory* ast_value_factory);
......
...@@ -620,7 +620,6 @@ class ParserBase : public Traits { ...@@ -620,7 +620,6 @@ class ParserBase : public Traits {
DCHECK(scope_type != FUNCTION_SCOPE); DCHECK(scope_type != FUNCTION_SCOPE);
Scope* result = Scope* result =
new (zone()) Scope(zone(), parent, scope_type, kNormalFunction); new (zone()) Scope(zone(), parent, scope_type, kNormalFunction);
result->Initialize();
if (scope_type == MODULE_SCOPE) result->DeclareThis(ast_value_factory()); if (scope_type == MODULE_SCOPE) result->DeclareThis(ast_value_factory());
return result; return result;
} }
...@@ -628,7 +627,6 @@ class ParserBase : public Traits { ...@@ -628,7 +627,6 @@ class ParserBase : public Traits {
Scope* NewFunctionScope(FunctionKind kind) { Scope* NewFunctionScope(FunctionKind kind) {
DCHECK(ast_value_factory()); DCHECK(ast_value_factory());
Scope* result = new (zone()) Scope(zone(), scope(), FUNCTION_SCOPE, kind); Scope* result = new (zone()) Scope(zone(), scope(), FUNCTION_SCOPE, kind);
result->Initialize();
if (!IsArrowFunction(kind)) { if (!IsArrowFunction(kind)) {
result->DeclareThis(ast_value_factory()); result->DeclareThis(ast_value_factory());
result->DeclareDefaultFunctionVariables(ast_value_factory()); result->DeclareDefaultFunctionVariables(ast_value_factory());
......
...@@ -3362,7 +3362,6 @@ TEST(SerializationOfMaybeAssignmentFlag) { ...@@ -3362,7 +3362,6 @@ TEST(SerializationOfMaybeAssignmentFlag) {
CHECK(str->IsInternalizedString()); CHECK(str->IsInternalizedString());
i::Scope* script_scope = i::Scope* script_scope =
new (&zone) i::Scope(&zone, nullptr, i::SCRIPT_SCOPE); new (&zone) i::Scope(&zone, nullptr, i::SCRIPT_SCOPE);
script_scope->Initialize();
i::Scope* s = i::Scope::DeserializeScopeChain(isolate, &zone, context, i::Scope* s = i::Scope::DeserializeScopeChain(isolate, &zone, context,
script_scope, &avf); script_scope, &avf);
CHECK(s != script_scope); CHECK(s != script_scope);
...@@ -3410,7 +3409,6 @@ TEST(IfArgumentsArrayAccessedThenParametersMaybeAssigned) { ...@@ -3410,7 +3409,6 @@ TEST(IfArgumentsArrayAccessedThenParametersMaybeAssigned) {
i::Scope* script_scope = i::Scope* script_scope =
new (&zone) i::Scope(&zone, nullptr, i::SCRIPT_SCOPE); new (&zone) i::Scope(&zone, nullptr, i::SCRIPT_SCOPE);
script_scope->Initialize();
i::Scope* s = i::Scope::DeserializeScopeChain(isolate, &zone, context, i::Scope* s = i::Scope::DeserializeScopeChain(isolate, &zone, context,
script_scope, &avf); script_scope, &avf);
CHECK(s != script_scope); CHECK(s != script_scope);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment