Make the condition for when this is predeclared easier to understand.

Just always predeclare it

R=marja@chromium.org,verwaest@chromium.org
BUG=v8:5215

Review-Url: https://codereview.chromium.org/2298743002
Cr-Commit-Position: refs/heads/master@{#39048}
This commit is contained in:
jochen 2016-08-31 06:33:17 -07:00 committed by Commit bot
parent 8a086d8cc3
commit 60a783c246
4 changed files with 15 additions and 12 deletions

View File

@ -129,12 +129,18 @@ Scope::Snapshot::Snapshot(Scope* scope)
top_local_(scope->GetClosureScope()->locals_.length()),
top_decl_(scope->GetClosureScope()->decls_.length()) {}
DeclarationScope::DeclarationScope(Zone* zone)
DeclarationScope::DeclarationScope(Zone* zone,
AstValueFactory* ast_value_factory)
: Scope(zone),
function_kind_(kNormalFunction),
params_(4, zone),
sloppy_block_function_map_(zone) {
DCHECK_EQ(scope_type_, SCRIPT_SCOPE);
SetDefaults();
// Make sure that if we don't find the global 'this', it won't be declared as
// a regular dynamic global by predeclaring it with the right variable kind.
DeclareDynamicGlobal(ast_value_factory->this_string(), Variable::THIS);
}
DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope,
@ -144,6 +150,7 @@ DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope,
function_kind_(function_kind),
params_(4, zone),
sloppy_block_function_map_(zone) {
DCHECK_NE(scope_type, SCRIPT_SCOPE);
SetDefaults();
asm_function_ = outer_scope_->IsAsmModule();
}
@ -182,6 +189,7 @@ DeclarationScope::DeclarationScope(Zone* zone, ScopeType scope_type,
function_kind_(scope_info->function_kind()),
params_(0, zone),
sloppy_block_function_map_(zone) {
DCHECK_NE(scope_type, SCRIPT_SCOPE);
SetDefaults();
}
@ -420,13 +428,6 @@ void DeclarationScope::Analyze(ParseInfo* info, AnalyzeMode mode) {
scope->outer_scope()->scope_type() == SCRIPT_SCOPE ||
scope->outer_scope()->already_resolved_);
// If there's a chance that there's a reference to global 'this', predeclare
// it as a dynamic global on the script scope.
if (scope->GetReceiverScope()->is_script_scope()) {
info->script_scope()->DeclareDynamicGlobal(
info->ast_value_factory()->this_string(), Variable::THIS);
}
scope->AllocateVariables(info, mode);
#ifdef DEBUG

View File

@ -587,7 +587,7 @@ class DeclarationScope : public Scope {
DeclarationScope(Zone* zone, ScopeType scope_type,
Handle<ScopeInfo> scope_info);
// Creates a script scope.
explicit DeclarationScope(Zone* zone);
DeclarationScope(Zone* zone, AstValueFactory* ast_value_factory);
bool IsDeclaredParameter(const AstRawString* name) {
// If IsSimpleParameterList is false, duplicate parameters are not allowed,

View File

@ -667,7 +667,7 @@ class ParserBase {
};
DeclarationScope* NewScriptScope() const {
return new (zone()) DeclarationScope(zone());
return new (zone()) DeclarationScope(zone(), ast_value_factory());
}
DeclarationScope* NewVarblockScope() const {

View File

@ -3321,7 +3321,8 @@ 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);
i::DeclarationScope* script_scope =
new (&zone) i::DeclarationScope(&zone, &avf);
i::Scope* s = i::Scope::DeserializeScopeChain(
isolate, &zone, context, script_scope, &avf,
i::Scope::DeserializationMode::kKeepScopeInfo);
@ -3368,7 +3369,8 @@ TEST(IfArgumentsArrayAccessedThenParametersMaybeAssigned) {
i::AstValueFactory avf(&zone, isolate->heap()->HashSeed());
avf.Internalize(isolate);
i::DeclarationScope* script_scope = new (&zone) i::DeclarationScope(&zone);
i::DeclarationScope* script_scope =
new (&zone) i::DeclarationScope(&zone, &avf);
i::Scope* s = i::Scope::DeserializeScopeChain(
isolate, &zone, context, script_scope, &avf,
i::Scope::DeserializationMode::kKeepScopeInfo);