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(
// baseline code might contain debug code that inspects the variable.
Node* current = environment()->Lookup(variable);
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) {
// Perform an initialization check for const {this} variables.
// Note that the {this} variable is the only const variable being able
......@@ -3460,20 +3469,18 @@ Node* AstGraphBuilder::BuildVariableAssignment(
if (current->op() != the_hole->op() && variable->is_this()) {
value = BuildHoleCheckElseThrow(current, variable, value, bailout_id);
}
} else if (IsLexicalVariableMode(mode) && op != Token::INIT) {
// Perform an initialization check for lexically declared variables.
Node* current = environment()->Lookup(variable);
} else if (mode == CONST && op != Token::INIT) {
if (variable->binding_needs_init()) {
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);
}
}
if (mode == CONST) {
// Assignment to const is exception in all modes.
return BuildThrowConstAssignError(bailout_id);
}
}
environment()->Bind(variable, value);
return value;
case VariableLocation::CONTEXT: {
......@@ -3487,6 +3494,13 @@ Node* AstGraphBuilder::BuildVariableAssignment(
return BuildThrowConstAssignError(bailout_id);
}
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) {
// Perform an initialization check for const {this} variables.
// Note that the {this} variable is the only const variable being able
......@@ -3497,19 +3511,16 @@ Node* AstGraphBuilder::BuildVariableAssignment(
Node* current = NewNode(op, current_context());
value = BuildHoleCheckElseThrow(current, variable, value, bailout_id);
}
} else if (IsLexicalVariableMode(mode) && op != Token::INIT) {
// Perform an initialization check for lexically declared variables.
} else if (mode == CONST && op != Token::INIT) {
if (variable->binding_needs_init()) {
const Operator* op =
javascript()->LoadContext(depth, variable->index(), false);
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);
}
}
const Operator* op = javascript()->StoreContext(depth, variable->index());
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