Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Unified Diff: src/full-codegen/x64/full-codegen-x64.cc

Issue 2201193004: Use Variable::binding_needs_init() to determine hole initialization (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove one more comment Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/full-codegen/mips64/full-codegen-mips64.cc ('k') | src/interpreter/bytecode-generator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/full-codegen/x64/full-codegen-x64.cc
diff --git a/src/full-codegen/x64/full-codegen-x64.cc b/src/full-codegen/x64/full-codegen-x64.cc
index 67c8ecb908ccd3d4b50c67e9b4581889f4489b00..fed7c65bec849adb25106d68a6c9416e09f45cfd 100644
--- a/src/full-codegen/x64/full-codegen-x64.cc
+++ b/src/full-codegen/x64/full-codegen-x64.cc
@@ -719,13 +719,8 @@ void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) {
void FullCodeGenerator::VisitVariableDeclaration(
VariableDeclaration* declaration) {
- // If it was not possible to allocate the variable at compile time, we
- // need to "declare" it at runtime to make sure it actually exists in the
- // local context.
VariableProxy* proxy = declaration->proxy();
- VariableMode mode = declaration->mode();
Variable* variable = proxy->var();
- bool hole_init = mode == LET || mode == CONST;
switch (variable->location()) {
case VariableLocation::GLOBAL:
case VariableLocation::UNALLOCATED: {
@@ -738,7 +733,7 @@ void FullCodeGenerator::VisitVariableDeclaration(
}
case VariableLocation::PARAMETER:
case VariableLocation::LOCAL:
- if (hole_init) {
+ if (variable->binding_needs_init()) {
Comment cmnt(masm_, "[ VariableDeclaration");
__ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex);
__ movp(StackOperand(variable), kScratchRegister);
@@ -746,7 +741,7 @@ void FullCodeGenerator::VisitVariableDeclaration(
break;
case VariableLocation::CONTEXT:
- if (hole_init) {
+ if (variable->binding_needs_init()) {
Comment cmnt(masm_, "[ VariableDeclaration");
EmitDebugCheckDeclarationContext(variable);
__ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex);
@@ -758,8 +753,8 @@ void FullCodeGenerator::VisitVariableDeclaration(
case VariableLocation::LOOKUP: {
Comment cmnt(masm_, "[ VariableDeclaration");
- DCHECK_EQ(VAR, mode);
- DCHECK(!hole_init);
+ DCHECK_EQ(VAR, variable->mode());
+ DCHECK(!variable->binding_needs_init());
__ Push(variable->name());
__ CallRuntime(Runtime::kDeclareEvalVar);
PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS);
@@ -1223,13 +1218,14 @@ void FullCodeGenerator::EmitDynamicLookupFastCase(VariableProxy* proxy,
} else if (var->mode() == DYNAMIC_LOCAL) {
Variable* local = var->local_if_not_shadowed();
__ movp(rax, ContextSlotOperandCheckExtensions(local, slow));
- if (local->mode() == LET || local->mode() == CONST) {
+ if (local->binding_needs_init()) {
__ CompareRoot(rax, Heap::kTheHoleValueRootIndex);
__ j(not_equal, done);
__ Push(var->name());
__ CallRuntime(Runtime::kThrowReferenceError);
+ } else {
+ __ jmp(done);
}
- __ jmp(done);
}
}
@@ -1272,17 +1268,15 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy,
Comment cmnt(masm_, var->IsContextSlot() ? "[ Context slot"
: "[ Stack slot");
if (NeedsHoleCheckForLoad(proxy)) {
- // Let and const need a read barrier.
+ // Throw a reference error when using an uninitialized let/const
+ // binding in harmony mode.
+ DCHECK(IsLexicalVariableMode(var->mode()));
Label done;
GetVar(rax, var);
__ CompareRoot(rax, Heap::kTheHoleValueRootIndex);
__ j(not_equal, &done, Label::kNear);
- if (var->mode() == LET || var->mode() == CONST) {
- // Throw a reference error when using an uninitialized let/const
- // binding in harmony mode.
- __ Push(var->name());
- __ CallRuntime(Runtime::kThrowReferenceError);
- }
+ __ Push(var->name());
+ __ CallRuntime(Runtime::kThrowReferenceError);
__ bind(&done);
context()->Plug(rax);
break;
@@ -2064,33 +2058,25 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op,
EmitLoadStoreICSlot(slot);
CallStoreIC();
- } else if (var->mode() == LET && op != Token::INIT) {
- // Non-initializing assignment to let variable needs a write barrier.
+ } else if (IsLexicalVariableMode(var->mode()) && op != Token::INIT) {
DCHECK(!var->IsLookupSlot());
DCHECK(var->IsStackAllocated() || var->IsContextSlot());
- Label assign;
MemOperand location = VarOperand(var, rcx);
- __ movp(rdx, location);
- __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex);
- __ j(not_equal, &assign, Label::kNear);
- __ Push(var->name());
- __ CallRuntime(Runtime::kThrowReferenceError);
- __ bind(&assign);
- EmitStoreToStackLocalOrContextSlot(var, location);
-
- } else if (var->mode() == CONST && op != Token::INIT) {
- // Assignment to const variable needs a write barrier.
- DCHECK(!var->IsLookupSlot());
- DCHECK(var->IsStackAllocated() || var->IsContextSlot());
- Label const_error;
- MemOperand location = VarOperand(var, rcx);
- __ movp(rdx, location);
- __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex);
- __ j(not_equal, &const_error, Label::kNear);
- __ Push(var->name());
- __ CallRuntime(Runtime::kThrowReferenceError);
- __ bind(&const_error);
- __ CallRuntime(Runtime::kThrowConstAssignError);
+ // Perform an initialization check for lexically declared variables.
+ if (var->binding_needs_init()) {
+ Label assign;
+ __ movp(rdx, location);
+ __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex);
+ __ j(not_equal, &assign, Label::kNear);
+ __ Push(var->name());
+ __ CallRuntime(Runtime::kThrowReferenceError);
+ __ bind(&assign);
+ }
+ if (var->mode() == CONST) {
+ __ CallRuntime(Runtime::kThrowConstAssignError);
+ } else {
+ EmitStoreToStackLocalOrContextSlot(var, location);
+ }
} else if (var->is_this() && var->mode() == CONST && op == Token::INIT) {
// Initializing assignment to const {this} needs a write barrier.
« no previous file with comments | « src/full-codegen/mips64/full-codegen-mips64.cc ('k') | src/interpreter/bytecode-generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698