Commit 22cb3cba authored by verwaest's avatar verwaest Committed by Commit bot

Allocate script scopes using a separate constructor

This avoids checking for outer_scope == nullptr in Scope::Scope

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2266973002
Cr-Commit-Position: refs/heads/master@{#38812}
parent 239f9816
......@@ -77,6 +77,16 @@ void SloppyBlockFunctionMap::Declare(Zone* zone, const AstRawString* name,
// ----------------------------------------------------------------------------
// Implementation of Scope
Scope::Scope(Zone* zone)
: zone_(zone),
outer_scope_(nullptr),
variables_(zone),
ordered_variables_(4, zone),
decls_(4, zone),
scope_type_(SCRIPT_SCOPE) {
SetDefaults();
}
Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type)
: zone_(zone),
outer_scope_(outer_scope),
......@@ -84,17 +94,12 @@ Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type)
ordered_variables_(4, zone),
decls_(4, zone),
scope_type_(scope_type) {
DCHECK_NE(SCRIPT_SCOPE, scope_type);
SetDefaults();
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 {
set_language_mode(outer_scope->language_mode());
force_context_allocation_ =
!is_function_scope() && outer_scope->has_forced_context_allocation();
outer_scope_->AddInnerScope(this);
}
set_language_mode(outer_scope->language_mode());
force_context_allocation_ =
!is_function_scope() && outer_scope->has_forced_context_allocation();
outer_scope_->AddInnerScope(this);
}
Scope::Snapshot::Snapshot(Scope* scope)
......@@ -103,6 +108,15 @@ Scope::Snapshot::Snapshot(Scope* scope)
top_unresolved_(scope->unresolved_),
top_temp_(scope->GetClosureScope()->temps()->length()) {}
DeclarationScope::DeclarationScope(Zone* zone)
: Scope(zone),
function_kind_(kNormalFunction),
temps_(4, zone),
params_(4, zone),
sloppy_block_function_map_(zone) {
SetDefaults();
}
DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope,
ScopeType scope_type,
FunctionKind function_kind)
......@@ -112,7 +126,7 @@ DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope,
params_(4, zone),
sloppy_block_function_map_(zone) {
SetDefaults();
if (outer_scope != nullptr) asm_function_ = outer_scope_->IsAsmModule();
asm_function_ = outer_scope_->IsAsmModule();
}
ModuleScope::ModuleScope(Zone* zone, DeclarationScope* script_scope,
......
......@@ -443,6 +443,9 @@ class Scope: public ZoneObject {
void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; }
protected:
// Creates a script scope.
explicit Scope(Zone* zone);
void set_language_mode(LanguageMode language_mode) {
is_strict_ = is_strict(language_mode);
}
......@@ -657,6 +660,8 @@ class DeclarationScope : public Scope {
FunctionKind function_kind = kNormalFunction);
DeclarationScope(Zone* zone, Scope* inner_scope, ScopeType scope_type,
Handle<ScopeInfo> scope_info);
// Creates a script scope.
explicit DeclarationScope(Zone* zone);
bool IsDeclaredParameter(const AstRawString* name) {
// If IsSimpleParameterList is false, duplicate parameters are not allowed,
......
......@@ -607,7 +607,7 @@ class ParserBase : public Traits {
};
DeclarationScope* NewScriptScope() {
return new (zone()) DeclarationScope(zone(), nullptr, SCRIPT_SCOPE);
return new (zone()) DeclarationScope(zone());
}
DeclarationScope* NewVarblockScope() {
......
......@@ -3393,8 +3393,7 @@ TEST(SerializationOfMaybeAssignmentFlag) {
const i::AstRawString* name = avf.GetOneByteString("result");
i::Handle<i::String> str = name->string();
CHECK(str->IsInternalizedString());
i::DeclarationScope* script_scope =
new (&zone) i::DeclarationScope(&zone, nullptr, i::SCRIPT_SCOPE);
i::DeclarationScope* script_scope = new (&zone) i::DeclarationScope(&zone);
i::Scope* s = i::Scope::DeserializeScopeChain(
isolate, &zone, context, script_scope, &avf,
i::Scope::DeserializationMode::kKeepScopeInfo);
......@@ -3441,8 +3440,7 @@ TEST(IfArgumentsArrayAccessedThenParametersMaybeAssigned) {
i::AstValueFactory avf(&zone, isolate->heap()->HashSeed());
avf.Internalize(isolate);
i::DeclarationScope* script_scope =
new (&zone) i::DeclarationScope(&zone, nullptr, i::SCRIPT_SCOPE);
i::DeclarationScope* script_scope = new (&zone) i::DeclarationScope(&zone);
i::Scope* s = i::Scope::DeserializeScopeChain(
isolate, &zone, context, script_scope, &avf,
i::Scope::DeserializationMode::kKeepScopeInfo);
......
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