OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
6 | 6 |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/interpreter/bytecode-register-allocator.h" | 10 #include "src/interpreter/bytecode-register-allocator.h" |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 } | 752 } |
753 break; | 753 break; |
754 case VariableLocation::CONTEXT: | 754 case VariableLocation::CONTEXT: |
755 if (hole_init) { | 755 if (hole_init) { |
756 builder()->LoadTheHole().StoreContextSlot(execution_context()->reg(), | 756 builder()->LoadTheHole().StoreContextSlot(execution_context()->reg(), |
757 variable->index()); | 757 variable->index()); |
758 } | 758 } |
759 break; | 759 break; |
760 case VariableLocation::LOOKUP: { | 760 case VariableLocation::LOOKUP: { |
761 DCHECK(IsDeclaredVariableMode(mode)); | 761 DCHECK(IsDeclaredVariableMode(mode)); |
| 762 DCHECK(!hole_init); |
762 | 763 |
763 register_allocator()->PrepareForConsecutiveAllocations(3); | 764 register_allocator()->PrepareForConsecutiveAllocations(3); |
764 Register name = register_allocator()->NextConsecutiveRegister(); | 765 Register name = register_allocator()->NextConsecutiveRegister(); |
765 Register init_value = register_allocator()->NextConsecutiveRegister(); | 766 Register init_value = register_allocator()->NextConsecutiveRegister(); |
766 Register attributes = register_allocator()->NextConsecutiveRegister(); | 767 Register attributes = register_allocator()->NextConsecutiveRegister(); |
767 | 768 |
768 builder()->LoadLiteral(variable->name()).StoreAccumulatorInRegister(name); | 769 builder()->LoadLiteral(variable->name()).StoreAccumulatorInRegister(name); |
769 if (hole_init) { | 770 builder() |
770 builder()->LoadTheHole().StoreAccumulatorInRegister(init_value); | 771 ->LoadLiteral(Smi::FromInt(0)) |
771 } else { | 772 .StoreAccumulatorInRegister(init_value); |
772 // For variables, we must not use an initial value (such as 'undefined') | |
773 // because we may have a (legal) redeclaration and we must not destroy | |
774 // the current value. | |
775 builder() | |
776 ->LoadLiteral(Smi::FromInt(0)) | |
777 .StoreAccumulatorInRegister(init_value); | |
778 } | |
779 builder() | 773 builder() |
780 ->LoadLiteral(Smi::FromInt(variable->DeclarationPropertyAttributes())) | 774 ->LoadLiteral(Smi::FromInt(variable->DeclarationPropertyAttributes())) |
781 .StoreAccumulatorInRegister(attributes) | 775 .StoreAccumulatorInRegister(attributes) |
782 .CallRuntime(Runtime::kDeclareLookupSlot, name, 3); | 776 .CallRuntime(Runtime::kDeclareLookupSlot, name, 3); |
783 break; | 777 break; |
784 } | 778 } |
785 } | 779 } |
786 } | 780 } |
787 | 781 |
788 void BytecodeGenerator::VisitFunctionDeclaration(FunctionDeclaration* decl) { | 782 void BytecodeGenerator::VisitFunctionDeclaration(FunctionDeclaration* decl) { |
(...skipping 2407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3196 return execution_context()->scope()->language_mode(); | 3190 return execution_context()->scope()->language_mode(); |
3197 } | 3191 } |
3198 | 3192 |
3199 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 3193 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
3200 return TypeFeedbackVector::GetIndex(slot); | 3194 return TypeFeedbackVector::GetIndex(slot); |
3201 } | 3195 } |
3202 | 3196 |
3203 } // namespace interpreter | 3197 } // namespace interpreter |
3204 } // namespace internal | 3198 } // namespace internal |
3205 } // namespace v8 | 3199 } // namespace v8 |
OLD | NEW |