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