| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #if V8_TARGET_ARCH_IA32 | 5 #if V8_TARGET_ARCH_IA32 |
| 6 | 6 |
| 7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
| 8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
| 9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 | 701 |
| 702 | 702 |
| 703 void FullCodeGenerator::VisitVariableDeclaration( | 703 void FullCodeGenerator::VisitVariableDeclaration( |
| 704 VariableDeclaration* declaration) { | 704 VariableDeclaration* declaration) { |
| 705 // If it was not possible to allocate the variable at compile time, we | 705 // If it was not possible to allocate the variable at compile time, we |
| 706 // need to "declare" it at runtime to make sure it actually exists in the | 706 // need to "declare" it at runtime to make sure it actually exists in the |
| 707 // local context. | 707 // local context. |
| 708 VariableProxy* proxy = declaration->proxy(); | 708 VariableProxy* proxy = declaration->proxy(); |
| 709 VariableMode mode = declaration->mode(); | 709 VariableMode mode = declaration->mode(); |
| 710 Variable* variable = proxy->var(); | 710 Variable* variable = proxy->var(); |
| 711 bool hole_init = mode == LET || mode == CONST || mode == CONST_LEGACY; | 711 bool hole_init = mode == LET || mode == CONST; |
| 712 switch (variable->location()) { | 712 switch (variable->location()) { |
| 713 case VariableLocation::GLOBAL: | 713 case VariableLocation::GLOBAL: |
| 714 case VariableLocation::UNALLOCATED: | 714 case VariableLocation::UNALLOCATED: |
| 715 globals_->Add(variable->name(), zone()); | 715 globals_->Add(variable->name(), zone()); |
| 716 globals_->Add(variable->binding_needs_init() | 716 globals_->Add(variable->binding_needs_init() |
| 717 ? isolate()->factory()->the_hole_value() | 717 ? isolate()->factory()->the_hole_value() |
| 718 : isolate()->factory()->undefined_value(), zone()); | 718 : isolate()->factory()->undefined_value(), zone()); |
| 719 break; | 719 break; |
| 720 | 720 |
| 721 case VariableLocation::PARAMETER: | 721 case VariableLocation::PARAMETER: |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 // introducing variables. In those cases, we do not want to | 1200 // introducing variables. In those cases, we do not want to |
| 1201 // perform a runtime call for all variables in the scope | 1201 // perform a runtime call for all variables in the scope |
| 1202 // containing the eval. | 1202 // containing the eval. |
| 1203 Variable* var = proxy->var(); | 1203 Variable* var = proxy->var(); |
| 1204 if (var->mode() == DYNAMIC_GLOBAL) { | 1204 if (var->mode() == DYNAMIC_GLOBAL) { |
| 1205 EmitLoadGlobalCheckExtensions(proxy, typeof_mode, slow); | 1205 EmitLoadGlobalCheckExtensions(proxy, typeof_mode, slow); |
| 1206 __ jmp(done); | 1206 __ jmp(done); |
| 1207 } else if (var->mode() == DYNAMIC_LOCAL) { | 1207 } else if (var->mode() == DYNAMIC_LOCAL) { |
| 1208 Variable* local = var->local_if_not_shadowed(); | 1208 Variable* local = var->local_if_not_shadowed(); |
| 1209 __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); | 1209 __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); |
| 1210 if (local->mode() == LET || local->mode() == CONST || | 1210 if (local->mode() == LET || local->mode() == CONST) { |
| 1211 local->mode() == CONST_LEGACY) { | |
| 1212 __ cmp(eax, isolate()->factory()->the_hole_value()); | 1211 __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1213 __ j(not_equal, done); | 1212 __ j(not_equal, done); |
| 1214 if (local->mode() == CONST_LEGACY) { | 1213 __ push(Immediate(var->name())); |
| 1215 __ mov(eax, isolate()->factory()->undefined_value()); | 1214 __ CallRuntime(Runtime::kThrowReferenceError); |
| 1216 } else { // LET || CONST | |
| 1217 __ push(Immediate(var->name())); | |
| 1218 __ CallRuntime(Runtime::kThrowReferenceError); | |
| 1219 } | |
| 1220 } | 1215 } |
| 1221 __ jmp(done); | 1216 __ jmp(done); |
| 1222 } | 1217 } |
| 1223 } | 1218 } |
| 1224 | 1219 |
| 1225 | 1220 |
| 1226 void FullCodeGenerator::EmitGlobalVariableLoad(VariableProxy* proxy, | 1221 void FullCodeGenerator::EmitGlobalVariableLoad(VariableProxy* proxy, |
| 1227 TypeofMode typeof_mode) { | 1222 TypeofMode typeof_mode) { |
| 1228 Variable* var = proxy->var(); | 1223 Variable* var = proxy->var(); |
| 1229 DCHECK(var->IsUnallocatedOrGlobalSlot() || | 1224 DCHECK(var->IsUnallocatedOrGlobalSlot() || |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 // Let and const need a read barrier. | 1262 // Let and const need a read barrier. |
| 1268 Label done; | 1263 Label done; |
| 1269 GetVar(eax, var); | 1264 GetVar(eax, var); |
| 1270 __ cmp(eax, isolate()->factory()->the_hole_value()); | 1265 __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1271 __ j(not_equal, &done, Label::kNear); | 1266 __ j(not_equal, &done, Label::kNear); |
| 1272 if (var->mode() == LET || var->mode() == CONST) { | 1267 if (var->mode() == LET || var->mode() == CONST) { |
| 1273 // Throw a reference error when using an uninitialized let/const | 1268 // Throw a reference error when using an uninitialized let/const |
| 1274 // binding in harmony mode. | 1269 // binding in harmony mode. |
| 1275 __ push(Immediate(var->name())); | 1270 __ push(Immediate(var->name())); |
| 1276 __ CallRuntime(Runtime::kThrowReferenceError); | 1271 __ CallRuntime(Runtime::kThrowReferenceError); |
| 1277 } else { | |
| 1278 // Uninitialized legacy const bindings are unholed. | |
| 1279 DCHECK(var->mode() == CONST_LEGACY); | |
| 1280 __ mov(eax, isolate()->factory()->undefined_value()); | |
| 1281 } | 1272 } |
| 1282 __ bind(&done); | 1273 __ bind(&done); |
| 1283 context()->Plug(eax); | 1274 context()->Plug(eax); |
| 1284 break; | 1275 break; |
| 1285 } | 1276 } |
| 1286 context()->Plug(var); | 1277 context()->Plug(var); |
| 1287 break; | 1278 break; |
| 1288 } | 1279 } |
| 1289 | 1280 |
| 1290 case VariableLocation::LOOKUP: { | 1281 case VariableLocation::LOOKUP: { |
| (...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2136 Label uninitialized_this; | 2127 Label uninitialized_this; |
| 2137 MemOperand location = VarOperand(var, ecx); | 2128 MemOperand location = VarOperand(var, ecx); |
| 2138 __ mov(edx, location); | 2129 __ mov(edx, location); |
| 2139 __ cmp(edx, isolate()->factory()->the_hole_value()); | 2130 __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2140 __ j(equal, &uninitialized_this); | 2131 __ j(equal, &uninitialized_this); |
| 2141 __ push(Immediate(var->name())); | 2132 __ push(Immediate(var->name())); |
| 2142 __ CallRuntime(Runtime::kThrowReferenceError); | 2133 __ CallRuntime(Runtime::kThrowReferenceError); |
| 2143 __ bind(&uninitialized_this); | 2134 __ bind(&uninitialized_this); |
| 2144 EmitStoreToStackLocalOrContextSlot(var, location); | 2135 EmitStoreToStackLocalOrContextSlot(var, location); |
| 2145 | 2136 |
| 2146 } else if (!var->is_const_mode() || | 2137 } else if (!var->is_const_mode() || op == Token::INIT) { |
| 2147 (var->mode() == CONST && op == Token::INIT)) { | |
| 2148 if (var->IsLookupSlot()) { | 2138 if (var->IsLookupSlot()) { |
| 2149 // Assignment to var. | 2139 // Assignment to var. |
| 2150 __ Push(Immediate(var->name())); | 2140 __ Push(Immediate(var->name())); |
| 2151 __ Push(eax); | 2141 __ Push(eax); |
| 2152 __ CallRuntime(is_strict(language_mode()) | 2142 __ CallRuntime(is_strict(language_mode()) |
| 2153 ? Runtime::kStoreLookupSlot_Strict | 2143 ? Runtime::kStoreLookupSlot_Strict |
| 2154 : Runtime::kStoreLookupSlot_Sloppy); | 2144 : Runtime::kStoreLookupSlot_Sloppy); |
| 2155 } else { | 2145 } else { |
| 2156 // Assignment to var or initializing assignment to let/const in harmony | 2146 // Assignment to var or initializing assignment to let/const in harmony |
| 2157 // mode. | 2147 // mode. |
| 2158 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | 2148 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 2159 MemOperand location = VarOperand(var, ecx); | 2149 MemOperand location = VarOperand(var, ecx); |
| 2160 if (FLAG_debug_code && var->mode() == LET && op == Token::INIT) { | 2150 if (FLAG_debug_code && var->mode() == LET && op == Token::INIT) { |
| 2161 // Check for an uninitialized let binding. | 2151 // Check for an uninitialized let binding. |
| 2162 __ mov(edx, location); | 2152 __ mov(edx, location); |
| 2163 __ cmp(edx, isolate()->factory()->the_hole_value()); | 2153 __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2164 __ Check(equal, kLetBindingReInitialization); | 2154 __ Check(equal, kLetBindingReInitialization); |
| 2165 } | 2155 } |
| 2166 EmitStoreToStackLocalOrContextSlot(var, location); | 2156 EmitStoreToStackLocalOrContextSlot(var, location); |
| 2167 } | 2157 } |
| 2168 | 2158 |
| 2169 } else if (var->mode() == CONST_LEGACY && op == Token::INIT) { | |
| 2170 // Const initializers need a write barrier. | |
| 2171 DCHECK(!var->IsParameter()); // No const parameters. | |
| 2172 if (var->IsLookupSlot()) { | |
| 2173 __ push(eax); | |
| 2174 __ push(esi); | |
| 2175 __ push(Immediate(var->name())); | |
| 2176 __ CallRuntime(Runtime::kInitializeLegacyConstLookupSlot); | |
| 2177 } else { | |
| 2178 DCHECK(var->IsStackLocal() || var->IsContextSlot()); | |
| 2179 Label skip; | |
| 2180 MemOperand location = VarOperand(var, ecx); | |
| 2181 __ mov(edx, location); | |
| 2182 __ cmp(edx, isolate()->factory()->the_hole_value()); | |
| 2183 __ j(not_equal, &skip, Label::kNear); | |
| 2184 EmitStoreToStackLocalOrContextSlot(var, location); | |
| 2185 __ bind(&skip); | |
| 2186 } | |
| 2187 | |
| 2188 } else { | 2159 } else { |
| 2189 DCHECK(var->mode() == CONST_LEGACY && op != Token::INIT); | 2160 DCHECK(var->mode() == CONST_LEGACY && op != Token::INIT); |
| 2190 if (is_strict(language_mode())) { | 2161 if (is_strict(language_mode())) { |
| 2191 __ CallRuntime(Runtime::kThrowConstAssignError); | 2162 __ CallRuntime(Runtime::kThrowConstAssignError); |
| 2192 } | 2163 } |
| 2193 // Silently ignore store in sloppy mode. | 2164 // Silently ignore store in sloppy mode. |
| 2194 } | 2165 } |
| 2195 } | 2166 } |
| 2196 | 2167 |
| 2197 | 2168 |
| (...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3899 isolate->builtins()->OnStackReplacement()->entry(), | 3870 isolate->builtins()->OnStackReplacement()->entry(), |
| 3900 Assembler::target_address_at(call_target_address, unoptimized_code)); | 3871 Assembler::target_address_at(call_target_address, unoptimized_code)); |
| 3901 return ON_STACK_REPLACEMENT; | 3872 return ON_STACK_REPLACEMENT; |
| 3902 } | 3873 } |
| 3903 | 3874 |
| 3904 | 3875 |
| 3905 } // namespace internal | 3876 } // namespace internal |
| 3906 } // namespace v8 | 3877 } // namespace v8 |
| 3907 | 3878 |
| 3908 #endif // V8_TARGET_ARCH_IA32 | 3879 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |