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 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 | 677 |
678 | 678 |
679 void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, | 679 void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, |
680 VariableMode mode, | 680 VariableMode mode, |
681 FunctionLiteral* function, | 681 FunctionLiteral* function, |
682 int* global_count) { | 682 int* global_count) { |
683 // If it was not possible to allocate the variable at compile time, we | 683 // If it was not possible to allocate the variable at compile time, we |
684 // need to "declare" it at runtime to make sure it actually exists in the | 684 // need to "declare" it at runtime to make sure it actually exists in the |
685 // local context. | 685 // local context. |
686 Variable* variable = proxy->var(); | 686 Variable* variable = proxy->var(); |
| 687 bool binding_needs_init = |
| 688 mode == CONST || mode == CONST_HARMONY || mode == LET; |
687 switch (variable->location()) { | 689 switch (variable->location()) { |
688 case Variable::UNALLOCATED: | 690 case Variable::UNALLOCATED: |
689 ++(*global_count); | 691 ++(*global_count); |
690 break; | 692 break; |
691 | 693 |
692 case Variable::PARAMETER: | 694 case Variable::PARAMETER: |
693 case Variable::LOCAL: | 695 case Variable::LOCAL: |
694 if (function != NULL) { | 696 if (function != NULL) { |
695 Comment cmnt(masm_, "[ Declaration"); | 697 Comment cmnt(masm_, "[ Declaration"); |
696 VisitForAccumulatorValue(function); | 698 VisitForAccumulatorValue(function); |
697 __ movq(StackOperand(variable), result_register()); | 699 __ movq(StackOperand(variable), result_register()); |
698 } else if (mode == CONST || mode == LET) { | 700 } else if (binding_needs_init) { |
699 Comment cmnt(masm_, "[ Declaration"); | 701 Comment cmnt(masm_, "[ Declaration"); |
700 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); | 702 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); |
701 __ movq(StackOperand(variable), kScratchRegister); | 703 __ movq(StackOperand(variable), kScratchRegister); |
702 } | 704 } |
703 break; | 705 break; |
704 | 706 |
705 case Variable::CONTEXT: | 707 case Variable::CONTEXT: |
706 // The variable in the decl always resides in the current function | 708 // The variable in the decl always resides in the current function |
707 // context. | 709 // context. |
708 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); | 710 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
(...skipping 12 matching lines...) Expand all Loading... |
721 int offset = Context::SlotOffset(variable->index()); | 723 int offset = Context::SlotOffset(variable->index()); |
722 // We know that we have written a function, which is not a smi. | 724 // We know that we have written a function, which is not a smi. |
723 __ RecordWriteContextSlot(rsi, | 725 __ RecordWriteContextSlot(rsi, |
724 offset, | 726 offset, |
725 result_register(), | 727 result_register(), |
726 rcx, | 728 rcx, |
727 kDontSaveFPRegs, | 729 kDontSaveFPRegs, |
728 EMIT_REMEMBERED_SET, | 730 EMIT_REMEMBERED_SET, |
729 OMIT_SMI_CHECK); | 731 OMIT_SMI_CHECK); |
730 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); | 732 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
731 } else if (mode == CONST || mode == LET) { | 733 } else if (binding_needs_init) { |
732 Comment cmnt(masm_, "[ Declaration"); | 734 Comment cmnt(masm_, "[ Declaration"); |
733 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); | 735 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); |
734 __ movq(ContextOperand(rsi, variable->index()), kScratchRegister); | 736 __ movq(ContextOperand(rsi, variable->index()), kScratchRegister); |
735 // No write barrier since the hole value is in old space. | 737 // No write barrier since the hole value is in old space. |
736 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); | 738 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
737 } | 739 } |
738 break; | 740 break; |
739 | 741 |
740 case Variable::LOOKUP: { | 742 case Variable::LOOKUP: { |
741 Comment cmnt(masm_, "[ Declaration"); | 743 Comment cmnt(masm_, "[ Declaration"); |
742 __ push(rsi); | 744 __ push(rsi); |
743 __ Push(variable->name()); | 745 __ Push(variable->name()); |
744 // Declaration nodes are always introduced in one of three modes. | 746 // Declaration nodes are always introduced in one of four modes. |
745 ASSERT(mode == VAR || mode == CONST || mode == LET); | 747 ASSERT(mode == VAR || |
746 PropertyAttributes attr = (mode == CONST) ? READ_ONLY : NONE; | 748 mode == CONST || |
| 749 mode == CONST_HARMONY || |
| 750 mode == LET); |
| 751 PropertyAttributes attr = |
| 752 (mode == CONST || mode == CONST_HARMONY) ? READ_ONLY : NONE; |
747 __ Push(Smi::FromInt(attr)); | 753 __ Push(Smi::FromInt(attr)); |
748 // Push initial value, if any. | 754 // Push initial value, if any. |
749 // Note: For variables we must not push an initial value (such as | 755 // Note: For variables we must not push an initial value (such as |
750 // 'undefined') because we may have a (legal) redeclaration and we | 756 // 'undefined') because we may have a (legal) redeclaration and we |
751 // must not destroy the current value. | 757 // must not destroy the current value. |
752 if (function != NULL) { | 758 if (function != NULL) { |
753 VisitForStackValue(function); | 759 VisitForStackValue(function); |
754 } else if (mode == CONST || mode == LET) { | 760 } else if (binding_needs_init) { |
755 __ PushRoot(Heap::kTheHoleValueRootIndex); | 761 __ PushRoot(Heap::kTheHoleValueRootIndex); |
756 } else { | 762 } else { |
757 __ Push(Smi::FromInt(0)); // Indicates no initial value. | 763 __ Push(Smi::FromInt(0)); // Indicates no initial value. |
758 } | 764 } |
759 __ CallRuntime(Runtime::kDeclareContextSlot, 4); | 765 __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
760 break; | 766 break; |
761 } | 767 } |
762 } | 768 } |
763 } | 769 } |
764 | 770 |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 // eval-introduced variables. Eval is used a lot without | 1181 // eval-introduced variables. Eval is used a lot without |
1176 // introducing variables. In those cases, we do not want to | 1182 // introducing variables. In those cases, we do not want to |
1177 // perform a runtime call for all variables in the scope | 1183 // perform a runtime call for all variables in the scope |
1178 // containing the eval. | 1184 // containing the eval. |
1179 if (var->mode() == DYNAMIC_GLOBAL) { | 1185 if (var->mode() == DYNAMIC_GLOBAL) { |
1180 EmitLoadGlobalCheckExtensions(var, typeof_state, slow); | 1186 EmitLoadGlobalCheckExtensions(var, typeof_state, slow); |
1181 __ jmp(done); | 1187 __ jmp(done); |
1182 } else if (var->mode() == DYNAMIC_LOCAL) { | 1188 } else if (var->mode() == DYNAMIC_LOCAL) { |
1183 Variable* local = var->local_if_not_shadowed(); | 1189 Variable* local = var->local_if_not_shadowed(); |
1184 __ movq(rax, ContextSlotOperandCheckExtensions(local, slow)); | 1190 __ movq(rax, ContextSlotOperandCheckExtensions(local, slow)); |
1185 if (local->mode() == CONST || local->mode() == LET) { | 1191 if (local->mode() == CONST || |
| 1192 local->mode() == CONST_HARMONY || |
| 1193 local->mode() == LET) { |
1186 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); | 1194 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); |
1187 __ j(not_equal, done); | 1195 __ j(not_equal, done); |
1188 if (local->mode() == CONST) { | 1196 if (local->mode() == CONST) { |
1189 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); | 1197 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
1190 } else { // LET | 1198 } else { // LET || CONST_HARMONY |
1191 __ Push(var->name()); | 1199 __ Push(var->name()); |
1192 __ CallRuntime(Runtime::kThrowReferenceError, 1); | 1200 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
1193 } | 1201 } |
1194 } | 1202 } |
1195 __ jmp(done); | 1203 __ jmp(done); |
1196 } | 1204 } |
1197 } | 1205 } |
1198 | 1206 |
1199 | 1207 |
1200 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { | 1208 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { |
(...skipping 13 matching lines...) Expand all Loading... |
1214 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); | 1222 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
1215 __ call(ic, RelocInfo::CODE_TARGET_CONTEXT); | 1223 __ call(ic, RelocInfo::CODE_TARGET_CONTEXT); |
1216 context()->Plug(rax); | 1224 context()->Plug(rax); |
1217 break; | 1225 break; |
1218 } | 1226 } |
1219 | 1227 |
1220 case Variable::PARAMETER: | 1228 case Variable::PARAMETER: |
1221 case Variable::LOCAL: | 1229 case Variable::LOCAL: |
1222 case Variable::CONTEXT: { | 1230 case Variable::CONTEXT: { |
1223 Comment cmnt(masm_, var->IsContextSlot() ? "Context slot" : "Stack slot"); | 1231 Comment cmnt(masm_, var->IsContextSlot() ? "Context slot" : "Stack slot"); |
1224 if (var->mode() != LET && var->mode() != CONST) { | 1232 if (!var->binding_needs_init()) { |
1225 context()->Plug(var); | 1233 context()->Plug(var); |
1226 } else { | 1234 } else { |
1227 // Let and const need a read barrier. | 1235 // Let and const need a read barrier. |
1228 Label done; | 1236 Label done; |
1229 GetVar(rax, var); | 1237 GetVar(rax, var); |
1230 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); | 1238 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); |
1231 __ j(not_equal, &done, Label::kNear); | 1239 __ j(not_equal, &done, Label::kNear); |
1232 if (var->mode() == LET) { | 1240 if (var->mode() == LET || var->mode() == CONST_HARMONY) { |
| 1241 // Throw a reference error when using an uninitialized let/const |
| 1242 // binding in harmony mode. |
1233 __ Push(var->name()); | 1243 __ Push(var->name()); |
1234 __ CallRuntime(Runtime::kThrowReferenceError, 1); | 1244 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
1235 } else { // CONST | 1245 } else { |
| 1246 // Uninitalized const bindings outside of harmony mode are unholed. |
| 1247 ASSERT(var->mode() == CONST); |
1236 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); | 1248 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
1237 } | 1249 } |
1238 __ bind(&done); | 1250 __ bind(&done); |
1239 context()->Plug(rax); | 1251 context()->Plug(rax); |
1240 } | 1252 } |
1241 break; | 1253 break; |
1242 } | 1254 } |
1243 | 1255 |
1244 case Variable::LOOKUP: { | 1256 case Variable::LOOKUP: { |
1245 Label done, slow; | 1257 Label done, slow; |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1798 __ CallRuntime(Runtime::kThrowReferenceError, 1); | 1810 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
1799 __ bind(&assign); | 1811 __ bind(&assign); |
1800 __ movq(location, rax); | 1812 __ movq(location, rax); |
1801 if (var->IsContextSlot()) { | 1813 if (var->IsContextSlot()) { |
1802 __ movq(rdx, rax); | 1814 __ movq(rdx, rax); |
1803 __ RecordWriteContextSlot( | 1815 __ RecordWriteContextSlot( |
1804 rcx, Context::SlotOffset(var->index()), rdx, rbx, kDontSaveFPRegs); | 1816 rcx, Context::SlotOffset(var->index()), rdx, rbx, kDontSaveFPRegs); |
1805 } | 1817 } |
1806 } | 1818 } |
1807 | 1819 |
1808 } else if (var->mode() != CONST) { | 1820 } else if (!var->is_const_mode() || op == Token::INIT_CONST_HARMONY) { |
1809 // Assignment to var or initializing assignment to let. | 1821 // Assignment to var or initializing assignment to let/const |
| 1822 // in harmony mode. |
1810 if (var->IsStackAllocated() || var->IsContextSlot()) { | 1823 if (var->IsStackAllocated() || var->IsContextSlot()) { |
1811 MemOperand location = VarOperand(var, rcx); | 1824 MemOperand location = VarOperand(var, rcx); |
1812 if (FLAG_debug_code && op == Token::INIT_LET) { | 1825 if (FLAG_debug_code && op == Token::INIT_LET) { |
1813 // Check for an uninitialized let binding. | 1826 // Check for an uninitialized let binding. |
1814 __ movq(rdx, location); | 1827 __ movq(rdx, location); |
1815 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); | 1828 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); |
1816 __ Check(equal, "Let binding re-initialization."); | 1829 __ Check(equal, "Let binding re-initialization."); |
1817 } | 1830 } |
1818 // Perform the assignment. | 1831 // Perform the assignment. |
1819 __ movq(location, rax); | 1832 __ movq(location, rax); |
(...skipping 2367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4187 *context_length = 0; | 4200 *context_length = 0; |
4188 return previous_; | 4201 return previous_; |
4189 } | 4202 } |
4190 | 4203 |
4191 | 4204 |
4192 #undef __ | 4205 #undef __ |
4193 | 4206 |
4194 } } // namespace v8::internal | 4207 } } // namespace v8::internal |
4195 | 4208 |
4196 #endif // V8_TARGET_ARCH_X64 | 4209 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |