[cleanup] Global variable declarations are never hole initialized

Globals used to be hole-initialized in the case of toplevel legacy
const declarations. But now that the only use of legacy const is
for sloppy function expression names, we can unconditionally
initialize globals to undefined instead of the_hole.

Review-Url: https://codereview.chromium.org/1964993002
Cr-Commit-Position: refs/heads/master@{#36151}
This commit is contained in:
adamk 2016-05-10 11:57:46 -07:00 committed by Commit bot
parent 2d090ee46a
commit bdf8dc4257
12 changed files with 26 additions and 49 deletions

View File

@ -1092,14 +1092,11 @@ void AstGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) {
bool hole_init = mode == CONST || mode == LET;
switch (variable->location()) {
case VariableLocation::GLOBAL:
case VariableLocation::UNALLOCATED: {
Handle<Oddball> value = variable->binding_needs_init()
? isolate()->factory()->the_hole_value()
: isolate()->factory()->undefined_value();
case VariableLocation::UNALLOCATED:
DCHECK(!variable->binding_needs_init());
globals()->push_back(variable->name());
globals()->push_back(value);
globals()->push_back(isolate()->factory()->undefined_value());
break;
}
case VariableLocation::PARAMETER:
case VariableLocation::LOCAL:
if (hole_init) {

View File

@ -12296,10 +12296,9 @@ void HOptimizedGraphBuilder::VisitVariableDeclaration(
switch (variable->location()) {
case VariableLocation::GLOBAL:
case VariableLocation::UNALLOCATED:
DCHECK(!variable->binding_needs_init());
globals_.Add(variable->name(), zone());
globals_.Add(variable->binding_needs_init()
? isolate()->factory()->the_hole_value()
: isolate()->factory()->undefined_value(), zone());
globals_.Add(isolate()->factory()->undefined_value(), zone());
return;
case VariableLocation::PARAMETER:
case VariableLocation::LOCAL:

View File

@ -768,11 +768,9 @@ void FullCodeGenerator::VisitVariableDeclaration(
switch (variable->location()) {
case VariableLocation::GLOBAL:
case VariableLocation::UNALLOCATED:
DCHECK(!variable->binding_needs_init());
globals_->Add(variable->name(), zone());
globals_->Add(variable->binding_needs_init()
? isolate()->factory()->the_hole_value()
: isolate()->factory()->undefined_value(),
zone());
globals_->Add(isolate()->factory()->undefined_value(), zone());
break;
case VariableLocation::PARAMETER:

View File

@ -765,11 +765,9 @@ void FullCodeGenerator::VisitVariableDeclaration(
switch (variable->location()) {
case VariableLocation::GLOBAL:
case VariableLocation::UNALLOCATED:
DCHECK(!variable->binding_needs_init());
globals_->Add(variable->name(), zone());
globals_->Add(variable->binding_needs_init()
? isolate()->factory()->the_hole_value()
: isolate()->factory()->undefined_value(),
zone());
globals_->Add(isolate()->factory()->undefined_value(), zone());
break;
case VariableLocation::PARAMETER:

View File

@ -715,10 +715,9 @@ void FullCodeGenerator::VisitVariableDeclaration(
switch (variable->location()) {
case VariableLocation::GLOBAL:
case VariableLocation::UNALLOCATED:
DCHECK(!variable->binding_needs_init());
globals_->Add(variable->name(), zone());
globals_->Add(variable->binding_needs_init()
? isolate()->factory()->the_hole_value()
: isolate()->factory()->undefined_value(), zone());
globals_->Add(isolate()->factory()->undefined_value(), zone());
break;
case VariableLocation::PARAMETER:

View File

@ -765,11 +765,9 @@ void FullCodeGenerator::VisitVariableDeclaration(
switch (variable->location()) {
case VariableLocation::GLOBAL:
case VariableLocation::UNALLOCATED:
DCHECK(!variable->binding_needs_init());
globals_->Add(variable->name(), zone());
globals_->Add(variable->binding_needs_init()
? isolate()->factory()->the_hole_value()
: isolate()->factory()->undefined_value(),
zone());
globals_->Add(isolate()->factory()->undefined_value(), zone());
break;
case VariableLocation::PARAMETER:

View File

@ -764,11 +764,9 @@ void FullCodeGenerator::VisitVariableDeclaration(
switch (variable->location()) {
case VariableLocation::GLOBAL:
case VariableLocation::UNALLOCATED:
DCHECK(!variable->binding_needs_init());
globals_->Add(variable->name(), zone());
globals_->Add(variable->binding_needs_init()
? isolate()->factory()->the_hole_value()
: isolate()->factory()->undefined_value(),
zone());
globals_->Add(isolate()->factory()->undefined_value(), zone());
break;
case VariableLocation::PARAMETER:

View File

@ -730,11 +730,9 @@ void FullCodeGenerator::VisitVariableDeclaration(
switch (variable->location()) {
case VariableLocation::GLOBAL:
case VariableLocation::UNALLOCATED:
DCHECK(!variable->binding_needs_init());
globals_->Add(variable->name(), zone());
globals_->Add(variable->binding_needs_init()
? isolate()->factory()->the_hole_value()
: isolate()->factory()->undefined_value(),
zone());
globals_->Add(isolate()->factory()->undefined_value(), zone());
break;
case VariableLocation::PARAMETER:

View File

@ -708,11 +708,9 @@ void FullCodeGenerator::VisitVariableDeclaration(
switch (variable->location()) {
case VariableLocation::GLOBAL:
case VariableLocation::UNALLOCATED:
DCHECK(!variable->binding_needs_init());
globals_->Add(variable->name(), zone());
globals_->Add(variable->binding_needs_init()
? isolate()->factory()->the_hole_value()
: isolate()->factory()->undefined_value(),
zone());
globals_->Add(isolate()->factory()->undefined_value(), zone());
break;
case VariableLocation::PARAMETER:

View File

@ -727,11 +727,9 @@ void FullCodeGenerator::VisitVariableDeclaration(
switch (variable->location()) {
case VariableLocation::GLOBAL:
case VariableLocation::UNALLOCATED:
DCHECK(!variable->binding_needs_init());
globals_->Add(variable->name(), zone());
globals_->Add(variable->binding_needs_init()
? isolate()->factory()->the_hole_value()
: isolate()->factory()->undefined_value(),
zone());
globals_->Add(isolate()->factory()->undefined_value(), zone());
break;
case VariableLocation::PARAMETER:

View File

@ -712,10 +712,9 @@ void FullCodeGenerator::VisitVariableDeclaration(
switch (variable->location()) {
case VariableLocation::GLOBAL:
case VariableLocation::UNALLOCATED:
DCHECK(!variable->binding_needs_init());
globals_->Add(variable->name(), zone());
globals_->Add(variable->binding_needs_init()
? isolate()->factory()->the_hole_value()
: isolate()->factory()->undefined_value(), zone());
globals_->Add(isolate()->factory()->undefined_value(), zone());
break;
case VariableLocation::PARAMETER:

View File

@ -747,14 +747,11 @@ void BytecodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) {
bool hole_init = mode == CONST || mode == LET;
switch (variable->location()) {
case VariableLocation::GLOBAL:
case VariableLocation::UNALLOCATED: {
Handle<Oddball> value = variable->binding_needs_init()
? isolate()->factory()->the_hole_value()
: isolate()->factory()->undefined_value();
case VariableLocation::UNALLOCATED:
DCHECK(!variable->binding_needs_init());
globals()->push_back(variable->name());
globals()->push_back(value);
globals()->push_back(isolate()->factory()->undefined_value());
break;
}
case VariableLocation::LOCAL:
if (hole_init) {
Register destination(variable->index());