Commit b028e64b authored by adamk's avatar adamk Committed by Commit bot

[turbofan] Re-separate logic for LET and CONST in BuildVariableAssignment

The structure of this code changed in https://codereview.chromium.org/2201193004,
but the structural changes were not essential to that CL's purpose (which was
to use Variable::binding_needs_init() consistently to decide whether to
hole-check). Now the code should appear as it did before that change, but with
the addition of binding_needs_init() checks.

R=bmeurer@chromium.org, mstarzinger@chromium.org

Review-Url: https://codereview.chromium.org/2237933002
Cr-Commit-Position: refs/heads/master@{#38638}
parent b052909c
...@@ -3452,6 +3452,15 @@ Node* AstGraphBuilder::BuildVariableAssignment( ...@@ -3452,6 +3452,15 @@ Node* AstGraphBuilder::BuildVariableAssignment(
// baseline code might contain debug code that inspects the variable. // baseline code might contain debug code that inspects the variable.
Node* current = environment()->Lookup(variable); Node* current = environment()->Lookup(variable);
CHECK_NOT_NULL(current); CHECK_NOT_NULL(current);
} else if (mode == LET && op != Token::INIT &&
variable->binding_needs_init()) {
// Perform an initialization check for let declared variables.
Node* current = environment()->Lookup(variable);
if (current->op() == the_hole->op()) {
return BuildThrowReferenceError(variable, bailout_id);
} else if (current->opcode() == IrOpcode::kPhi) {
BuildHoleCheckThenThrow(current, variable, value, bailout_id);
}
} else if (mode == CONST && op == Token::INIT) { } else if (mode == CONST && op == Token::INIT) {
// Perform an initialization check for const {this} variables. // Perform an initialization check for const {this} variables.
// Note that the {this} variable is the only const variable being able // Note that the {this} variable is the only const variable being able
...@@ -3460,19 +3469,17 @@ Node* AstGraphBuilder::BuildVariableAssignment( ...@@ -3460,19 +3469,17 @@ Node* AstGraphBuilder::BuildVariableAssignment(
if (current->op() != the_hole->op() && variable->is_this()) { if (current->op() != the_hole->op() && variable->is_this()) {
value = BuildHoleCheckElseThrow(current, variable, value, bailout_id); value = BuildHoleCheckElseThrow(current, variable, value, bailout_id);
} }
} else if (IsLexicalVariableMode(mode) && op != Token::INIT) { } else if (mode == CONST && op != Token::INIT) {
// Perform an initialization check for lexically declared variables.
Node* current = environment()->Lookup(variable);
if (variable->binding_needs_init()) { if (variable->binding_needs_init()) {
Node* current = environment()->Lookup(variable);
if (current->op() == the_hole->op()) { if (current->op() == the_hole->op()) {
return BuildThrowReferenceError(variable, bailout_id); return BuildThrowReferenceError(variable, bailout_id);
} else if (current->opcode() == IrOpcode::kPhi) { } else if (current->opcode() == IrOpcode::kPhi) {
BuildHoleCheckThenThrow(current, variable, value, bailout_id); BuildHoleCheckThenThrow(current, variable, value, bailout_id);
} }
} }
if (mode == CONST) { // Assignment to const is exception in all modes.
return BuildThrowConstAssignError(bailout_id); return BuildThrowConstAssignError(bailout_id);
}
} }
environment()->Bind(variable, value); environment()->Bind(variable, value);
return value; return value;
...@@ -3487,6 +3494,13 @@ Node* AstGraphBuilder::BuildVariableAssignment( ...@@ -3487,6 +3494,13 @@ Node* AstGraphBuilder::BuildVariableAssignment(
return BuildThrowConstAssignError(bailout_id); return BuildThrowConstAssignError(bailout_id);
} }
return value; return value;
} else if (mode == LET && op != Token::INIT &&
variable->binding_needs_init()) {
// Perform an initialization check for let declared variables.
const Operator* op =
javascript()->LoadContext(depth, variable->index(), false);
Node* current = NewNode(op, current_context());
value = BuildHoleCheckThenThrow(current, variable, value, bailout_id);
} else if (mode == CONST && op == Token::INIT) { } else if (mode == CONST && op == Token::INIT) {
// Perform an initialization check for const {this} variables. // Perform an initialization check for const {this} variables.
// Note that the {this} variable is the only const variable being able // Note that the {this} variable is the only const variable being able
...@@ -3497,18 +3511,15 @@ Node* AstGraphBuilder::BuildVariableAssignment( ...@@ -3497,18 +3511,15 @@ Node* AstGraphBuilder::BuildVariableAssignment(
Node* current = NewNode(op, current_context()); Node* current = NewNode(op, current_context());
value = BuildHoleCheckElseThrow(current, variable, value, bailout_id); value = BuildHoleCheckElseThrow(current, variable, value, bailout_id);
} }
} else if (IsLexicalVariableMode(mode) && op != Token::INIT) { } else if (mode == CONST && op != Token::INIT) {
// Perform an initialization check for lexically declared variables.
if (variable->binding_needs_init()) { if (variable->binding_needs_init()) {
const Operator* op = const Operator* op =
javascript()->LoadContext(depth, variable->index(), false); javascript()->LoadContext(depth, variable->index(), false);
Node* current = NewNode(op, current_context()); Node* current = NewNode(op, current_context());
value = BuildHoleCheckThenThrow(current, variable, value, bailout_id); BuildHoleCheckThenThrow(current, variable, value, bailout_id);
}
if (mode == CONST) {
// Assignment to const is exception in all modes.
return BuildThrowConstAssignError(bailout_id);
} }
// Assignment to const is exception in all modes.
return BuildThrowConstAssignError(bailout_id);
} }
const Operator* op = javascript()->StoreContext(depth, variable->index()); const Operator* op = javascript()->StoreContext(depth, variable->index());
return NewNode(op, current_context(), value); return NewNode(op, current_context(), value);
......
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