| 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 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 | 704 |
| 705 | 705 |
| 706 void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, | 706 void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, |
| 707 VariableMode mode, | 707 VariableMode mode, |
| 708 FunctionLiteral* function, | 708 FunctionLiteral* function, |
| 709 int* global_count) { | 709 int* global_count) { |
| 710 // If it was not possible to allocate the variable at compile time, we | 710 // If it was not possible to allocate the variable at compile time, we |
| 711 // need to "declare" it at runtime to make sure it actually exists in the | 711 // need to "declare" it at runtime to make sure it actually exists in the |
| 712 // local context. | 712 // local context. |
| 713 Variable* variable = proxy->var(); | 713 Variable* variable = proxy->var(); |
| 714 bool binding_needs_init = |
| 715 mode == CONST || mode == CONST_HARMONY || mode == LET; |
| 714 switch (variable->location()) { | 716 switch (variable->location()) { |
| 715 case Variable::UNALLOCATED: | 717 case Variable::UNALLOCATED: |
| 716 ++(*global_count); | 718 ++(*global_count); |
| 717 break; | 719 break; |
| 718 | 720 |
| 719 case Variable::PARAMETER: | 721 case Variable::PARAMETER: |
| 720 case Variable::LOCAL: | 722 case Variable::LOCAL: |
| 721 if (function != NULL) { | 723 if (function != NULL) { |
| 722 Comment cmnt(masm_, "[ Declaration"); | 724 Comment cmnt(masm_, "[ Declaration"); |
| 723 VisitForAccumulatorValue(function); | 725 VisitForAccumulatorValue(function); |
| 724 __ mov(StackOperand(variable), result_register()); | 726 __ mov(StackOperand(variable), result_register()); |
| 725 } else if (mode == CONST || mode == LET) { | 727 } else if (binding_needs_init) { |
| 726 Comment cmnt(masm_, "[ Declaration"); | 728 Comment cmnt(masm_, "[ Declaration"); |
| 727 __ mov(StackOperand(variable), | 729 __ mov(StackOperand(variable), |
| 728 Immediate(isolate()->factory()->the_hole_value())); | 730 Immediate(isolate()->factory()->the_hole_value())); |
| 729 } | 731 } |
| 730 break; | 732 break; |
| 731 | 733 |
| 732 case Variable::CONTEXT: | 734 case Variable::CONTEXT: |
| 733 // The variable in the decl always resides in the current function | 735 // The variable in the decl always resides in the current function |
| 734 // context. | 736 // context. |
| 735 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); | 737 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 747 __ mov(ContextOperand(esi, variable->index()), result_register()); | 749 __ mov(ContextOperand(esi, variable->index()), result_register()); |
| 748 // We know that we have written a function, which is not a smi. | 750 // We know that we have written a function, which is not a smi. |
| 749 __ RecordWriteContextSlot(esi, | 751 __ RecordWriteContextSlot(esi, |
| 750 Context::SlotOffset(variable->index()), | 752 Context::SlotOffset(variable->index()), |
| 751 result_register(), | 753 result_register(), |
| 752 ecx, | 754 ecx, |
| 753 kDontSaveFPRegs, | 755 kDontSaveFPRegs, |
| 754 EMIT_REMEMBERED_SET, | 756 EMIT_REMEMBERED_SET, |
| 755 OMIT_SMI_CHECK); | 757 OMIT_SMI_CHECK); |
| 756 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); | 758 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
| 757 } else if (mode == CONST || mode == LET) { | 759 } else if (binding_needs_init) { |
| 758 Comment cmnt(masm_, "[ Declaration"); | 760 Comment cmnt(masm_, "[ Declaration"); |
| 759 __ mov(ContextOperand(esi, variable->index()), | 761 __ mov(ContextOperand(esi, variable->index()), |
| 760 Immediate(isolate()->factory()->the_hole_value())); | 762 Immediate(isolate()->factory()->the_hole_value())); |
| 761 // No write barrier since the hole value is in old space. | 763 // No write barrier since the hole value is in old space. |
| 762 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); | 764 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
| 763 } | 765 } |
| 764 break; | 766 break; |
| 765 | 767 |
| 766 case Variable::LOOKUP: { | 768 case Variable::LOOKUP: { |
| 767 Comment cmnt(masm_, "[ Declaration"); | 769 Comment cmnt(masm_, "[ Declaration"); |
| 768 __ push(esi); | 770 __ push(esi); |
| 769 __ push(Immediate(variable->name())); | 771 __ push(Immediate(variable->name())); |
| 770 // Declaration nodes are always introduced in one of three modes. | 772 // Declaration nodes are always introduced in one of four modes. |
| 771 ASSERT(mode == VAR || mode == CONST || mode == LET); | 773 ASSERT(mode == VAR || |
| 772 PropertyAttributes attr = (mode == CONST) ? READ_ONLY : NONE; | 774 mode == CONST || |
| 775 mode == CONST_HARMONY || |
| 776 mode == LET); |
| 777 PropertyAttributes attr = (mode == CONST || mode == CONST_HARMONY) |
| 778 ? READ_ONLY : NONE; |
| 773 __ push(Immediate(Smi::FromInt(attr))); | 779 __ push(Immediate(Smi::FromInt(attr))); |
| 774 // Push initial value, if any. | 780 // Push initial value, if any. |
| 775 // Note: For variables we must not push an initial value (such as | 781 // Note: For variables we must not push an initial value (such as |
| 776 // 'undefined') because we may have a (legal) redeclaration and we | 782 // 'undefined') because we may have a (legal) redeclaration and we |
| 777 // must not destroy the current value. | 783 // must not destroy the current value. |
| 778 increment_stack_height(3); | 784 increment_stack_height(3); |
| 779 if (function != NULL) { | 785 if (function != NULL) { |
| 780 VisitForStackValue(function); | 786 VisitForStackValue(function); |
| 781 } else if (mode == CONST || mode == LET) { | 787 } else if (binding_needs_init) { |
| 782 __ push(Immediate(isolate()->factory()->the_hole_value())); | 788 __ push(Immediate(isolate()->factory()->the_hole_value())); |
| 783 increment_stack_height(); | 789 increment_stack_height(); |
| 784 } else { | 790 } else { |
| 785 __ push(Immediate(Smi::FromInt(0))); // Indicates no initial value. | 791 __ push(Immediate(Smi::FromInt(0))); // Indicates no initial value. |
| 786 increment_stack_height(); | 792 increment_stack_height(); |
| 787 } | 793 } |
| 788 __ CallRuntime(Runtime::kDeclareContextSlot, 4); | 794 __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
| 789 decrement_stack_height(4); | 795 decrement_stack_height(4); |
| 790 break; | 796 break; |
| 791 } | 797 } |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 // introducing variables. In those cases, we do not want to | 1205 // introducing variables. In those cases, we do not want to |
| 1200 // perform a runtime call for all variables in the scope | 1206 // perform a runtime call for all variables in the scope |
| 1201 // containing the eval. | 1207 // containing the eval. |
| 1202 if (var->mode() == DYNAMIC_GLOBAL) { | 1208 if (var->mode() == DYNAMIC_GLOBAL) { |
| 1203 EmitLoadGlobalCheckExtensions(var, typeof_state, slow); | 1209 EmitLoadGlobalCheckExtensions(var, typeof_state, slow); |
| 1204 __ jmp(done); | 1210 __ jmp(done); |
| 1205 } else if (var->mode() == DYNAMIC_LOCAL) { | 1211 } else if (var->mode() == DYNAMIC_LOCAL) { |
| 1206 Variable* local = var->local_if_not_shadowed(); | 1212 Variable* local = var->local_if_not_shadowed(); |
| 1207 __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); | 1213 __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); |
| 1208 if (local->mode() == CONST || | 1214 if (local->mode() == CONST || |
| 1215 local->mode() == CONST_HARMONY || |
| 1209 local->mode() == LET) { | 1216 local->mode() == LET) { |
| 1210 __ cmp(eax, isolate()->factory()->the_hole_value()); | 1217 __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1211 __ j(not_equal, done); | 1218 __ j(not_equal, done); |
| 1212 if (local->mode() == CONST) { | 1219 if (local->mode() == CONST) { |
| 1213 __ mov(eax, isolate()->factory()->undefined_value()); | 1220 __ mov(eax, isolate()->factory()->undefined_value()); |
| 1214 } else { // LET | 1221 } else { // LET || CONST_HARMONY |
| 1215 __ push(Immediate(var->name())); | 1222 __ push(Immediate(var->name())); |
| 1216 __ CallRuntime(Runtime::kThrowReferenceError, 1); | 1223 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1217 } | 1224 } |
| 1218 } | 1225 } |
| 1219 __ jmp(done); | 1226 __ jmp(done); |
| 1220 } | 1227 } |
| 1221 } | 1228 } |
| 1222 | 1229 |
| 1223 | 1230 |
| 1224 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { | 1231 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1240 context()->Plug(eax); | 1247 context()->Plug(eax); |
| 1241 break; | 1248 break; |
| 1242 } | 1249 } |
| 1243 | 1250 |
| 1244 case Variable::PARAMETER: | 1251 case Variable::PARAMETER: |
| 1245 case Variable::LOCAL: | 1252 case Variable::LOCAL: |
| 1246 case Variable::CONTEXT: { | 1253 case Variable::CONTEXT: { |
| 1247 Comment cmnt(masm_, var->IsContextSlot() | 1254 Comment cmnt(masm_, var->IsContextSlot() |
| 1248 ? "Context variable" | 1255 ? "Context variable" |
| 1249 : "Stack variable"); | 1256 : "Stack variable"); |
| 1250 if (var->mode() != LET && var->mode() != CONST) { | 1257 if (!var->binding_needs_init()) { |
| 1251 context()->Plug(var); | 1258 context()->Plug(var); |
| 1252 } else { | 1259 } else { |
| 1253 // Let and const need a read barrier. | 1260 // Let and const need a read barrier. |
| 1254 Label done; | 1261 Label done; |
| 1255 GetVar(eax, var); | 1262 GetVar(eax, var); |
| 1256 __ cmp(eax, isolate()->factory()->the_hole_value()); | 1263 __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1257 __ j(not_equal, &done, Label::kNear); | 1264 __ j(not_equal, &done, Label::kNear); |
| 1258 if (var->mode() == LET) { | 1265 if (var->mode() == LET || var->mode() == CONST_HARMONY) { |
| 1266 // Throw a reference error when using an uninitialized let/const |
| 1267 // binding in harmony mode. |
| 1259 __ push(Immediate(var->name())); | 1268 __ push(Immediate(var->name())); |
| 1260 __ CallRuntime(Runtime::kThrowReferenceError, 1); | 1269 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1261 } else { // CONST | 1270 } else { |
| 1271 // Uninitalized const bindings outside of harmony mode are unholed. |
| 1272 ASSERT(var->mode() == CONST); |
| 1262 __ mov(eax, isolate()->factory()->undefined_value()); | 1273 __ mov(eax, isolate()->factory()->undefined_value()); |
| 1263 } | 1274 } |
| 1264 __ bind(&done); | 1275 __ bind(&done); |
| 1265 context()->Plug(eax); | 1276 context()->Plug(eax); |
| 1266 } | 1277 } |
| 1267 break; | 1278 break; |
| 1268 } | 1279 } |
| 1269 | 1280 |
| 1270 case Variable::LOOKUP: { | 1281 case Variable::LOOKUP: { |
| 1271 Label done, slow; | 1282 Label done, slow; |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1883 __ CallRuntime(Runtime::kThrowReferenceError, 1); | 1894 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1884 __ bind(&assign); | 1895 __ bind(&assign); |
| 1885 __ mov(location, eax); | 1896 __ mov(location, eax); |
| 1886 if (var->IsContextSlot()) { | 1897 if (var->IsContextSlot()) { |
| 1887 __ mov(edx, eax); | 1898 __ mov(edx, eax); |
| 1888 int offset = Context::SlotOffset(var->index()); | 1899 int offset = Context::SlotOffset(var->index()); |
| 1889 __ RecordWriteContextSlot(ecx, offset, edx, ebx, kDontSaveFPRegs); | 1900 __ RecordWriteContextSlot(ecx, offset, edx, ebx, kDontSaveFPRegs); |
| 1890 } | 1901 } |
| 1891 } | 1902 } |
| 1892 | 1903 |
| 1893 } else if (var->mode() != CONST) { | 1904 } else if (!var->is_const_mode() || op == Token::INIT_CONST_HARMONY) { |
| 1894 // Assignment to var or initializing assignment to let. | 1905 // Assignment to var or initializing assignment to let/const |
| 1906 // in harmony mode. |
| 1895 if (var->IsStackAllocated() || var->IsContextSlot()) { | 1907 if (var->IsStackAllocated() || var->IsContextSlot()) { |
| 1896 MemOperand location = VarOperand(var, ecx); | 1908 MemOperand location = VarOperand(var, ecx); |
| 1897 if (FLAG_debug_code && op == Token::INIT_LET) { | 1909 if (FLAG_debug_code && op == Token::INIT_LET) { |
| 1898 // Check for an uninitialized let binding. | 1910 // Check for an uninitialized let binding. |
| 1899 __ mov(edx, location); | 1911 __ mov(edx, location); |
| 1900 __ cmp(edx, isolate()->factory()->the_hole_value()); | 1912 __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 1901 __ Check(equal, "Let binding re-initialization."); | 1913 __ Check(equal, "Let binding re-initialization."); |
| 1902 } | 1914 } |
| 1903 // Perform the assignment. | 1915 // Perform the assignment. |
| 1904 __ mov(location, eax); | 1916 __ mov(location, eax); |
| (...skipping 2430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4335 *context_length = 0; | 4347 *context_length = 0; |
| 4336 return previous_; | 4348 return previous_; |
| 4337 } | 4349 } |
| 4338 | 4350 |
| 4339 | 4351 |
| 4340 #undef __ | 4352 #undef __ |
| 4341 | 4353 |
| 4342 } } // namespace v8::internal | 4354 } } // namespace v8::internal |
| 4343 | 4355 |
| 4344 #endif // V8_TARGET_ARCH_IA32 | 4356 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |