OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 3938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3949 | 3949 |
3950 if (expr->is_compound()) { | 3950 if (expr->is_compound()) { |
3951 HandleCompoundAssignment(expr); | 3951 HandleCompoundAssignment(expr); |
3952 return; | 3952 return; |
3953 } | 3953 } |
3954 | 3954 |
3955 if (prop != NULL) { | 3955 if (prop != NULL) { |
3956 HandlePropertyAssignment(expr); | 3956 HandlePropertyAssignment(expr); |
3957 } else if (proxy != NULL) { | 3957 } else if (proxy != NULL) { |
3958 Variable* var = proxy->var(); | 3958 Variable* var = proxy->var(); |
3959 if (var->mode() == CONST) { | 3959 if (var->mode() == LET) { |
3960 if (expr->op() != Token::INIT_CONST) { | |
3961 return Bailout("non-initializer assignment to const"); | |
3962 } | |
3963 if (!var->IsStackAllocated()) { | |
3964 return Bailout("assignment to const context slot"); | |
3965 } | |
3966 // We insert a use of the old value to detect unsupported uses of const | |
3967 // variables (e.g. initialization inside a loop). | |
3968 HValue* old_value = environment()->Lookup(var); | |
3969 AddInstruction(new HUseConst(old_value)); | |
3970 } else if (var->mode() == LET) { | |
3971 if (!var->IsStackAllocated()) { | 3960 if (!var->IsStackAllocated()) { |
3972 return Bailout("assignment to let context slot"); | 3961 return Bailout("assignment to let context slot"); |
3973 } | 3962 } |
3974 } else if (var->mode() == CONST_HARMONY) { | 3963 } |
3975 if (expr->op() != Token::INIT_CONST_HARMONY) { | 3964 |
3976 return Bailout("non-initializer assignment to const"); | 3965 if (var->is_const_mode()) { |
fschneider
2011/12/08 13:01:30
CONST_HARMONY has different semantics from CONST.
| |
3966 // Changing value of const variable only possible at initialization | |
3967 if (expr->op() != Token::INIT_CONST && | |
3968 expr->op() != Token::INIT_CONST_HARMONY) { | |
3969 CHECK_ALIVE(VisitForValue(expr->value())); | |
3970 return ast_context()->ReturnValue(Pop()); | |
3977 } | 3971 } |
3978 if (!var->IsStackAllocated()) { | 3972 |
3979 return Bailout("assignment to const context slot"); | 3973 if (var->IsStackAllocated()) { |
3974 // We insert a use of the old value to detect unsupported uses of const | |
3975 // variables (e.g. initialization inside a loop). | |
3976 HValue* old_value = environment()->Lookup(var); | |
3977 AddInstruction(new HUseConst(old_value)); | |
3980 } | 3978 } |
3981 } | 3979 } |
3982 | 3980 |
3983 if (proxy->IsArguments()) return Bailout("assignment to arguments"); | 3981 if (proxy->IsArguments()) return Bailout("assignment to arguments"); |
3984 | 3982 |
3985 // Handle the assignment. | 3983 // Handle the assignment. |
3986 switch (var->location()) { | 3984 switch (var->location()) { |
3987 case Variable::UNALLOCATED: | 3985 case Variable::UNALLOCATED: |
3988 CHECK_ALIVE(VisitForValue(expr->value())); | 3986 CHECK_ALIVE(VisitForValue(expr->value())); |
3989 HandleGlobalVariableAssignment(var, | 3987 HandleGlobalVariableAssignment(var, |
(...skipping 15 matching lines...) Expand all Loading... | |
4005 // We do not allow the arguments object to occur in a context where it | 4003 // We do not allow the arguments object to occur in a context where it |
4006 // may escape, but assignments to stack-allocated locals are | 4004 // may escape, but assignments to stack-allocated locals are |
4007 // permitted. | 4005 // permitted. |
4008 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED)); | 4006 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED)); |
4009 HValue* value = Pop(); | 4007 HValue* value = Pop(); |
4010 Bind(var, value); | 4008 Bind(var, value); |
4011 return ast_context()->ReturnValue(value); | 4009 return ast_context()->ReturnValue(value); |
4012 } | 4010 } |
4013 | 4011 |
4014 case Variable::CONTEXT: { | 4012 case Variable::CONTEXT: { |
4015 ASSERT(var->mode() != CONST); | |
4016 // Bail out if we try to mutate a parameter value in a function using | 4013 // Bail out if we try to mutate a parameter value in a function using |
4017 // the arguments object. We do not (yet) correctly handle the | 4014 // the arguments object. We do not (yet) correctly handle the |
4018 // arguments property of the function. | 4015 // arguments property of the function. |
4019 if (info()->scope()->arguments() != NULL) { | 4016 if (info()->scope()->arguments() != NULL) { |
4020 // Parameters will rewrite to context slots. We have no direct way | 4017 // Parameters will rewrite to context slots. We have no direct way |
4021 // to detect that the variable is a parameter. | 4018 // to detect that the variable is a parameter. |
4022 int count = info()->scope()->num_parameters(); | 4019 int count = info()->scope()->num_parameters(); |
4023 for (int i = 0; i < count; ++i) { | 4020 for (int i = 0; i < count; ++i) { |
4024 if (var == info()->scope()->parameter(i)) { | 4021 if (var == info()->scope()->parameter(i)) { |
4025 return Bailout("assignment to parameter in arguments object"); | 4022 return Bailout("assignment to parameter in arguments object"); |
4026 } | 4023 } |
4027 } | 4024 } |
4028 } | 4025 } |
4029 | 4026 |
4030 CHECK_ALIVE(VisitForValue(expr->value())); | 4027 CHECK_ALIVE(VisitForValue(expr->value())); |
4031 HValue* context = BuildContextChainWalk(var); | 4028 HValue* context = BuildContextChainWalk(var); |
4032 HStoreContextSlot* instr = | 4029 HStoreContextSlot* instr = |
4033 new(zone()) HStoreContextSlot(context, var->index(), Top()); | 4030 new(zone()) HStoreContextSlot(context, var->index(), Top()); |
4031 | |
4032 // Ensure that const variable's value will be set only once | |
4033 if (var->is_const_mode()) { | |
4034 instr->ForceIsHoleCheck(); | |
4035 } | |
4036 | |
4034 AddInstruction(instr); | 4037 AddInstruction(instr); |
4035 if (instr->HasObservableSideEffects()) { | 4038 if (instr->HasObservableSideEffects()) { |
4036 AddSimulate(expr->AssignmentId()); | 4039 AddSimulate(expr->AssignmentId()); |
4037 } | 4040 } |
4038 return ast_context()->ReturnValue(Pop()); | 4041 return ast_context()->ReturnValue(Pop()); |
4039 } | 4042 } |
4040 | 4043 |
4041 case Variable::LOOKUP: | 4044 case Variable::LOOKUP: |
4042 return Bailout("assignment to LOOKUP variable"); | 4045 return Bailout("assignment to LOOKUP variable"); |
4043 } | 4046 } |
(...skipping 3204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7248 } | 7251 } |
7249 } | 7252 } |
7250 | 7253 |
7251 #ifdef DEBUG | 7254 #ifdef DEBUG |
7252 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 7255 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
7253 if (allocator_ != NULL) allocator_->Verify(); | 7256 if (allocator_ != NULL) allocator_->Verify(); |
7254 #endif | 7257 #endif |
7255 } | 7258 } |
7256 | 7259 |
7257 } } // namespace v8::internal | 7260 } } // namespace v8::internal |
OLD | NEW |