Introduce NewScriptScope that creates a top-level scope

It's the only Scope type that has outer scope nullptr; and it always has outer scope nullptr.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2158913005
Cr-Commit-Position: refs/heads/master@{#37907}
This commit is contained in:
verwaest 2016-07-20 05:54:41 -07:00 committed by Commit bot
parent 04ba79eb72
commit d6a38645ef
4 changed files with 13 additions and 6 deletions

View File

@ -615,9 +615,16 @@ class ParserBase : public Traits {
Mode old_mode_;
};
Scope* NewScriptScope() {
return new (zone()) Scope(zone(), nullptr, SCRIPT_SCOPE, kNormalFunction);
}
Scope* NewScope(Scope* parent, ScopeType scope_type) {
// Must always pass the function kind for FUNCTION_SCOPE.
DCHECK(scope_type != FUNCTION_SCOPE);
// Must always use the specific constructors for the blacklisted scope
// types.
DCHECK_NE(FUNCTION_SCOPE, scope_type);
DCHECK_NE(SCRIPT_SCOPE, scope_type);
DCHECK_NOT_NULL(parent);
Scope* result =
new (zone()) Scope(zone(), parent, scope_type, kNormalFunction);
if (scope_type == MODULE_SCOPE) result->DeclareThis(ast_value_factory());

View File

@ -939,7 +939,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
{
// TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native
// context, which will have the "this" binding for script scopes.
Scope* scope = NewScope(nullptr, SCRIPT_SCOPE);
Scope* scope = NewScriptScope();
info->set_script_scope(scope);
if (!info->context().is_null() && !info->context()->IsNativeContext()) {
scope = Scope::DeserializeScopeChain(info->isolate(), zone(),
@ -1103,7 +1103,7 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
{
// Parse the function literal.
Scope* scope = NewScope(nullptr, SCRIPT_SCOPE);
Scope* scope = NewScriptScope();
info->set_script_scope(scope);
if (!info->context().is_null()) {
// Ok to use Isolate here, since lazy function parsing is only done in the

View File

@ -131,7 +131,7 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
use_counts_ = use_counts;
// Lazy functions always have trivial outer scopes (no with/catch scopes).
DCHECK_NULL(scope_state_);
Scope* top_scope = NewScope(nullptr, SCRIPT_SCOPE);
Scope* top_scope = NewScriptScope();
PreParserFactory top_factory(nullptr);
FunctionState top_state(&function_state_, &scope_state_, top_scope,
kNormalFunction, &top_factory);

View File

@ -1040,7 +1040,7 @@ class PreParser : public ParserBase<PreParserTraits> {
PreParseResult PreParseProgram(int* materialized_literals = 0,
bool is_module = false) {
DCHECK_NULL(scope_state_);
Scope* scope = NewScope(nullptr, SCRIPT_SCOPE);
Scope* scope = NewScriptScope();
// ModuleDeclarationInstantiation for Source Text Module Records creates a
// new Module Environment Record whose outer lexical environment record is