Chromium Code Reviews| 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 3270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3281 variable->mode() == LET); | 3281 variable->mode() == LET); |
| 3282 return Bailout("reference to uninitialized variable"); | 3282 return Bailout("reference to uninitialized variable"); |
| 3283 } | 3283 } |
| 3284 return ast_context()->ReturnValue(value); | 3284 return ast_context()->ReturnValue(value); |
| 3285 } | 3285 } |
| 3286 | 3286 |
| 3287 case Variable::CONTEXT: { | 3287 case Variable::CONTEXT: { |
| 3288 if (variable->mode() == LET || variable->mode() == CONST_HARMONY) { | 3288 if (variable->mode() == LET || variable->mode() == CONST_HARMONY) { |
| 3289 return Bailout("reference to harmony declared context slot"); | 3289 return Bailout("reference to harmony declared context slot"); |
| 3290 } | 3290 } |
| 3291 if (variable->mode() == CONST) { | |
| 3292 return Bailout("reference to const context slot"); | |
|
fschneider
2011/12/09 09:37:54
In order to get rid of this bailout we also additi
| |
| 3293 } | |
| 3294 HValue* context = BuildContextChainWalk(variable); | 3291 HValue* context = BuildContextChainWalk(variable); |
| 3295 HLoadContextSlot* instr = | 3292 HLoadContextSlot* instr = |
| 3296 new(zone()) HLoadContextSlot(context, variable->index()); | 3293 new(zone()) HLoadContextSlot(context, variable->index()); |
| 3297 return ast_context()->ReturnInstruction(instr, expr->id()); | 3294 return ast_context()->ReturnInstruction(instr, expr->id()); |
| 3298 } | 3295 } |
| 3299 | 3296 |
| 3300 case Variable::LOOKUP: | 3297 case Variable::LOOKUP: |
| 3301 return Bailout("reference to a variable which requires dynamic lookup"); | 3298 return Bailout("reference to a variable which requires dynamic lookup"); |
| 3302 } | 3299 } |
| 3303 } | 3300 } |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3949 | 3946 |
| 3950 if (expr->is_compound()) { | 3947 if (expr->is_compound()) { |
| 3951 HandleCompoundAssignment(expr); | 3948 HandleCompoundAssignment(expr); |
| 3952 return; | 3949 return; |
| 3953 } | 3950 } |
| 3954 | 3951 |
| 3955 if (prop != NULL) { | 3952 if (prop != NULL) { |
| 3956 HandlePropertyAssignment(expr); | 3953 HandlePropertyAssignment(expr); |
| 3957 } else if (proxy != NULL) { | 3954 } else if (proxy != NULL) { |
| 3958 Variable* var = proxy->var(); | 3955 Variable* var = proxy->var(); |
| 3956 | |
| 3959 if (var->mode() == CONST) { | 3957 if (var->mode() == CONST) { |
| 3960 if (expr->op() != Token::INIT_CONST) { | 3958 if (expr->op() != Token::INIT_CONST) { |
| 3961 return Bailout("non-initializer assignment to const"); | 3959 CHECK_ALIVE(VisitForValue(expr->value())); |
| 3960 return ast_context()->ReturnValue(Pop()); | |
| 3962 } | 3961 } |
| 3963 if (!var->IsStackAllocated()) { | 3962 |
| 3964 return Bailout("assignment to const context slot"); | 3963 if (var->IsStackAllocated()) { |
| 3965 } | 3964 // We insert a use of the old value to detect unsupported uses of const |
| 3966 // We insert a use of the old value to detect unsupported uses of const | 3965 // variables (e.g. initialization inside a loop). |
| 3967 // variables (e.g. initialization inside a loop). | 3966 HValue* old_value = environment()->Lookup(var); |
| 3968 HValue* old_value = environment()->Lookup(var); | 3967 AddInstruction(new HUseConst(old_value)); |
| 3969 AddInstruction(new HUseConst(old_value)); | |
| 3970 } else if (var->mode() == LET) { | |
| 3971 if (!var->IsStackAllocated()) { | |
| 3972 return Bailout("assignment to let context slot"); | |
| 3973 } | 3968 } |
| 3974 } else if (var->mode() == CONST_HARMONY) { | 3969 } else if (var->mode() == CONST_HARMONY) { |
| 3975 if (expr->op() != Token::INIT_CONST_HARMONY) { | 3970 if (expr->op() != Token::INIT_CONST_HARMONY) { |
| 3976 return Bailout("non-initializer assignment to const"); | 3971 return Bailout("non-initializer assignment to const"); |
| 3977 } | 3972 } |
| 3978 if (!var->IsStackAllocated()) { | 3973 if (!var->IsStackAllocated()) { |
| 3979 return Bailout("assignment to const context slot"); | 3974 return Bailout("assignment to const context slot"); |
| 3980 } | 3975 } |
| 3976 } else if (var->mode() == LET) { | |
| 3977 if (!var->IsStackAllocated()) { | |
| 3978 return Bailout("assignment to let context slot"); | |
| 3979 } | |
| 3981 } | 3980 } |
| 3982 | 3981 |
| 3983 if (proxy->IsArguments()) return Bailout("assignment to arguments"); | 3982 if (proxy->IsArguments()) return Bailout("assignment to arguments"); |
| 3984 | 3983 |
| 3985 // Handle the assignment. | 3984 // Handle the assignment. |
| 3986 switch (var->location()) { | 3985 switch (var->location()) { |
| 3987 case Variable::UNALLOCATED: | 3986 case Variable::UNALLOCATED: |
| 3988 CHECK_ALIVE(VisitForValue(expr->value())); | 3987 CHECK_ALIVE(VisitForValue(expr->value())); |
| 3989 HandleGlobalVariableAssignment(var, | 3988 HandleGlobalVariableAssignment(var, |
| 3990 Top(), | 3989 Top(), |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 4005 // We do not allow the arguments object to occur in a context where it | 4004 // We do not allow the arguments object to occur in a context where it |
| 4006 // may escape, but assignments to stack-allocated locals are | 4005 // may escape, but assignments to stack-allocated locals are |
| 4007 // permitted. | 4006 // permitted. |
| 4008 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED)); | 4007 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED)); |
| 4009 HValue* value = Pop(); | 4008 HValue* value = Pop(); |
| 4010 Bind(var, value); | 4009 Bind(var, value); |
| 4011 return ast_context()->ReturnValue(value); | 4010 return ast_context()->ReturnValue(value); |
| 4012 } | 4011 } |
| 4013 | 4012 |
| 4014 case Variable::CONTEXT: { | 4013 case Variable::CONTEXT: { |
| 4015 ASSERT(var->mode() != CONST); | |
| 4016 // Bail out if we try to mutate a parameter value in a function using | 4014 // 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 | 4015 // the arguments object. We do not (yet) correctly handle the |
| 4018 // arguments property of the function. | 4016 // arguments property of the function. |
| 4019 if (info()->scope()->arguments() != NULL) { | 4017 if (info()->scope()->arguments() != NULL) { |
| 4020 // Parameters will rewrite to context slots. We have no direct way | 4018 // Parameters will rewrite to context slots. We have no direct way |
| 4021 // to detect that the variable is a parameter. | 4019 // to detect that the variable is a parameter. |
| 4022 int count = info()->scope()->num_parameters(); | 4020 int count = info()->scope()->num_parameters(); |
| 4023 for (int i = 0; i < count; ++i) { | 4021 for (int i = 0; i < count; ++i) { |
| 4024 if (var == info()->scope()->parameter(i)) { | 4022 if (var == info()->scope()->parameter(i)) { |
| 4025 return Bailout("assignment to parameter in arguments object"); | 4023 return Bailout("assignment to parameter in arguments object"); |
| 4026 } | 4024 } |
| 4027 } | 4025 } |
| 4028 } | 4026 } |
| 4029 | 4027 |
| 4030 CHECK_ALIVE(VisitForValue(expr->value())); | 4028 CHECK_ALIVE(VisitForValue(expr->value())); |
| 4031 HValue* context = BuildContextChainWalk(var); | 4029 HValue* context = BuildContextChainWalk(var); |
| 4032 HStoreContextSlot* instr = | 4030 HStoreContextSlot* instr = |
| 4033 new(zone()) HStoreContextSlot(context, var->index(), Top()); | 4031 new(zone()) HStoreContextSlot(context, var->index(), Top()); |
| 4032 | |
| 4033 // Ensure that const variable's value will be set only once | |
| 4034 if (var->is_const_mode()) { | |
|
fschneider
2011/12/09 09:37:54
Here I would write
if (var->mode() == CONST)
to
| |
| 4035 instr->ForceIsHoleCheck(); | |
| 4036 } | |
| 4037 | |
| 4034 AddInstruction(instr); | 4038 AddInstruction(instr); |
| 4035 if (instr->HasObservableSideEffects()) { | 4039 if (instr->HasObservableSideEffects()) { |
| 4036 AddSimulate(expr->AssignmentId()); | 4040 AddSimulate(expr->AssignmentId()); |
| 4037 } | 4041 } |
| 4038 return ast_context()->ReturnValue(Pop()); | 4042 return ast_context()->ReturnValue(Pop()); |
| 4039 } | 4043 } |
| 4040 | 4044 |
| 4041 case Variable::LOOKUP: | 4045 case Variable::LOOKUP: |
| 4042 return Bailout("assignment to LOOKUP variable"); | 4046 return Bailout("assignment to LOOKUP variable"); |
| 4043 } | 4047 } |
| (...skipping 3204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7248 } | 7252 } |
| 7249 } | 7253 } |
| 7250 | 7254 |
| 7251 #ifdef DEBUG | 7255 #ifdef DEBUG |
| 7252 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 7256 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
| 7253 if (allocator_ != NULL) allocator_->Verify(); | 7257 if (allocator_ != NULL) allocator_->Verify(); |
| 7254 #endif | 7258 #endif |
| 7255 } | 7259 } |
| 7256 | 7260 |
| 7257 } } // namespace v8::internal | 7261 } } // namespace v8::internal |
| OLD | NEW |