Chromium Code Reviews| Index: src/hydrogen.cc |
| diff --git a/src/hydrogen.cc b/src/hydrogen.cc |
| index 519b4b84ba47b52bcc1a70257d1ed2ae140fddd4..94f260ee88e6272b186f8be6b34716b8e011b27e 100644 |
| --- a/src/hydrogen.cc |
| +++ b/src/hydrogen.cc |
| @@ -3956,27 +3956,25 @@ void HGraphBuilder::VisitAssignment(Assignment* expr) { |
| HandlePropertyAssignment(expr); |
| } else if (proxy != NULL) { |
| Variable* var = proxy->var(); |
| - if (var->mode() == CONST) { |
| - if (expr->op() != Token::INIT_CONST) { |
| - return Bailout("non-initializer assignment to const"); |
| - } |
| - if (!var->IsStackAllocated()) { |
| - return Bailout("assignment to const context slot"); |
| - } |
| - // We insert a use of the old value to detect unsupported uses of const |
| - // variables (e.g. initialization inside a loop). |
| - HValue* old_value = environment()->Lookup(var); |
| - AddInstruction(new HUseConst(old_value)); |
| - } else if (var->mode() == LET) { |
| + if (var->mode() == LET) { |
| if (!var->IsStackAllocated()) { |
| return Bailout("assignment to let context slot"); |
| } |
| - } else if (var->mode() == CONST_HARMONY) { |
| - if (expr->op() != Token::INIT_CONST_HARMONY) { |
| - return Bailout("non-initializer assignment to const"); |
| + } |
| + |
| + if (var->is_const_mode()) { |
|
fschneider
2011/12/08 13:01:30
CONST_HARMONY has different semantics from CONST.
|
| + // Changing value of const variable only possible at initialization |
| + if (expr->op() != Token::INIT_CONST && |
| + expr->op() != Token::INIT_CONST_HARMONY) { |
| + CHECK_ALIVE(VisitForValue(expr->value())); |
| + return ast_context()->ReturnValue(Pop()); |
| } |
| - if (!var->IsStackAllocated()) { |
| - return Bailout("assignment to const context slot"); |
| + |
| + if (var->IsStackAllocated()) { |
| + // We insert a use of the old value to detect unsupported uses of const |
| + // variables (e.g. initialization inside a loop). |
| + HValue* old_value = environment()->Lookup(var); |
| + AddInstruction(new HUseConst(old_value)); |
| } |
| } |
| @@ -4012,7 +4010,6 @@ void HGraphBuilder::VisitAssignment(Assignment* expr) { |
| } |
| case Variable::CONTEXT: { |
| - ASSERT(var->mode() != CONST); |
| // Bail out if we try to mutate a parameter value in a function using |
| // the arguments object. We do not (yet) correctly handle the |
| // arguments property of the function. |
| @@ -4031,6 +4028,12 @@ void HGraphBuilder::VisitAssignment(Assignment* expr) { |
| HValue* context = BuildContextChainWalk(var); |
| HStoreContextSlot* instr = |
| new(zone()) HStoreContextSlot(context, var->index(), Top()); |
| + |
| + // Ensure that const variable's value will be set only once |
| + if (var->is_const_mode()) { |
| + instr->ForceIsHoleCheck(); |
| + } |
| + |
| AddInstruction(instr); |
| if (instr->HasObservableSideEffects()) { |
| AddSimulate(expr->AssignmentId()); |