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/full-codegen/full-codegen.h" | 7 #include "src/full-codegen/full-codegen.h" |
8 #include "src/ast/compile-time-value.h" | 8 #include "src/ast/compile-time-value.h" |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 __ CallStub(&stub); | 1149 __ CallStub(&stub); |
1150 RestoreContext(); | 1150 RestoreContext(); |
1151 } | 1151 } |
1152 PrepareForBailoutForId(expr->CreateLiteralId(), BailoutState::TOS_REGISTER); | 1152 PrepareForBailoutForId(expr->CreateLiteralId(), BailoutState::TOS_REGISTER); |
1153 | 1153 |
1154 // If result_saved is true the result is on top of the stack. If | 1154 // If result_saved is true the result is on top of the stack. If |
1155 // result_saved is false the result is in eax. | 1155 // result_saved is false the result is in eax. |
1156 bool result_saved = false; | 1156 bool result_saved = false; |
1157 | 1157 |
1158 AccessorTable accessor_table(zone()); | 1158 AccessorTable accessor_table(zone()); |
1159 int property_index = 0; | 1159 for (int i = 0; i < expr->properties()->length(); i++) { |
1160 for (; property_index < expr->properties()->length(); property_index++) { | 1160 ObjectLiteral::Property* property = expr->properties()->at(i); |
1161 ObjectLiteral::Property* property = expr->properties()->at(property_index); | 1161 DCHECK(!property->is_computed_name()); |
1162 if (property->is_computed_name()) break; | |
1163 if (property->IsCompileTimeValue()) continue; | 1162 if (property->IsCompileTimeValue()) continue; |
1164 | 1163 |
1165 Literal* key = property->key()->AsLiteral(); | 1164 Literal* key = property->key()->AsLiteral(); |
1166 Expression* value = property->value(); | 1165 Expression* value = property->value(); |
1167 if (!result_saved) { | 1166 if (!result_saved) { |
1168 PushOperand(eax); // Save result on the stack | 1167 PushOperand(eax); // Save result on the stack |
1169 result_saved = true; | 1168 result_saved = true; |
1170 } | 1169 } |
1171 switch (property->kind()) { | 1170 switch (property->kind()) { |
1172 case ObjectLiteral::Property::CONSTANT: | 1171 case ObjectLiteral::Property::CONSTANT: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 CallRuntimeWithOperands(Runtime::kSetProperty); | 1203 CallRuntimeWithOperands(Runtime::kSetProperty); |
1205 } else { | 1204 } else { |
1206 DropOperands(3); | 1205 DropOperands(3); |
1207 } | 1206 } |
1208 break; | 1207 break; |
1209 case ObjectLiteral::Property::PROTOTYPE: | 1208 case ObjectLiteral::Property::PROTOTYPE: |
1210 PushOperand(Operand(esp, 0)); // Duplicate receiver. | 1209 PushOperand(Operand(esp, 0)); // Duplicate receiver. |
1211 VisitForStackValue(value); | 1210 VisitForStackValue(value); |
1212 DCHECK(property->emit_store()); | 1211 DCHECK(property->emit_store()); |
1213 CallRuntimeWithOperands(Runtime::kInternalSetPrototype); | 1212 CallRuntimeWithOperands(Runtime::kInternalSetPrototype); |
1214 PrepareForBailoutForId(expr->GetIdForPropertySet(property_index), | 1213 PrepareForBailoutForId(expr->GetIdForPropertySet(i), |
1215 BailoutState::NO_REGISTERS); | 1214 BailoutState::NO_REGISTERS); |
1216 break; | 1215 break; |
1217 case ObjectLiteral::Property::GETTER: | 1216 case ObjectLiteral::Property::GETTER: |
1218 if (property->emit_store()) { | 1217 if (property->emit_store()) { |
1219 AccessorTable::Iterator it = accessor_table.lookup(key); | 1218 AccessorTable::Iterator it = accessor_table.lookup(key); |
1220 it->second->bailout_id = expr->GetIdForPropertySet(property_index); | 1219 it->second->bailout_id = expr->GetIdForPropertySet(i); |
1221 it->second->getter = property; | 1220 it->second->getter = property; |
1222 } | 1221 } |
1223 break; | 1222 break; |
1224 case ObjectLiteral::Property::SETTER: | 1223 case ObjectLiteral::Property::SETTER: |
1225 if (property->emit_store()) { | 1224 if (property->emit_store()) { |
1226 AccessorTable::Iterator it = accessor_table.lookup(key); | 1225 AccessorTable::Iterator it = accessor_table.lookup(key); |
1227 it->second->bailout_id = expr->GetIdForPropertySet(property_index); | 1226 it->second->bailout_id = expr->GetIdForPropertySet(i); |
1228 it->second->setter = property; | 1227 it->second->setter = property; |
1229 } | 1228 } |
1230 break; | 1229 break; |
1231 } | 1230 } |
1232 } | 1231 } |
1233 | 1232 |
1234 // Emit code to define accessors, using only a single call to the runtime for | 1233 // Emit code to define accessors, using only a single call to the runtime for |
1235 // each pair of corresponding getters and setters. | 1234 // each pair of corresponding getters and setters. |
1236 for (AccessorTable::Iterator it = accessor_table.begin(); | 1235 for (AccessorTable::Iterator it = accessor_table.begin(); |
1237 it != accessor_table.end(); | 1236 it != accessor_table.end(); |
1238 ++it) { | 1237 ++it) { |
1239 PushOperand(Operand(esp, 0)); // Duplicate receiver. | 1238 PushOperand(Operand(esp, 0)); // Duplicate receiver. |
1240 VisitForStackValue(it->first); | 1239 VisitForStackValue(it->first); |
1241 | 1240 |
1242 EmitAccessor(it->second->getter); | 1241 EmitAccessor(it->second->getter); |
1243 EmitAccessor(it->second->setter); | 1242 EmitAccessor(it->second->setter); |
1244 | 1243 |
1245 PushOperand(Smi::FromInt(NONE)); | 1244 PushOperand(Smi::FromInt(NONE)); |
1246 CallRuntimeWithOperands(Runtime::kDefineAccessorPropertyUnchecked); | 1245 CallRuntimeWithOperands(Runtime::kDefineAccessorPropertyUnchecked); |
1247 PrepareForBailoutForId(it->second->bailout_id, BailoutState::NO_REGISTERS); | 1246 PrepareForBailoutForId(it->second->bailout_id, BailoutState::NO_REGISTERS); |
1248 } | 1247 } |
1249 | 1248 |
1250 // Object literals have two parts. The "static" part on the left contains no | |
1251 // computed property names, and so we can compute its map ahead of time; see | |
1252 // runtime.cc::CreateObjectLiteralBoilerplate. The second "dynamic" part | |
1253 // starts with the first computed property name, and continues with all | |
1254 // properties to its right. All the code from above initializes the static | |
1255 // component of the object literal, and arranges for the map of the result to | |
1256 // reflect the static order in which the keys appear. For the dynamic | |
1257 // properties, we compile them into a series of "SetOwnProperty" runtime | |
1258 // calls. This will preserve insertion order. | |
1259 for (; property_index < expr->properties()->length(); property_index++) { | |
1260 ObjectLiteral::Property* property = expr->properties()->at(property_index); | |
1261 | |
1262 Expression* value = property->value(); | |
1263 if (!result_saved) { | |
1264 PushOperand(eax); // Save result on the stack | |
1265 result_saved = true; | |
1266 } | |
1267 | |
1268 PushOperand(Operand(esp, 0)); // Duplicate receiver. | |
1269 | |
1270 if (property->kind() == ObjectLiteral::Property::PROTOTYPE) { | |
1271 DCHECK(!property->is_computed_name()); | |
1272 VisitForStackValue(value); | |
1273 DCHECK(property->emit_store()); | |
1274 CallRuntimeWithOperands(Runtime::kInternalSetPrototype); | |
1275 PrepareForBailoutForId(expr->GetIdForPropertySet(property_index), | |
1276 BailoutState::NO_REGISTERS); | |
1277 } else { | |
1278 EmitPropertyKey(property, expr->GetIdForPropertyName(property_index)); | |
1279 VisitForStackValue(value); | |
1280 if (NeedsHomeObject(value)) { | |
1281 EmitSetHomeObject(value, 2, property->GetSlot()); | |
1282 } | |
1283 | |
1284 switch (property->kind()) { | |
1285 case ObjectLiteral::Property::CONSTANT: | |
1286 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | |
1287 case ObjectLiteral::Property::COMPUTED: | |
1288 case ObjectLiteral::Property::PROTOTYPE: | |
1289 UNREACHABLE(); | |
1290 break; | |
1291 | |
1292 case ObjectLiteral::Property::GETTER: | |
1293 PushOperand(Smi::FromInt(NONE)); | |
1294 CallRuntimeWithOperands(Runtime::kDefineGetterPropertyUnchecked); | |
1295 break; | |
1296 | |
1297 case ObjectLiteral::Property::SETTER: | |
1298 PushOperand(Smi::FromInt(NONE)); | |
1299 CallRuntimeWithOperands(Runtime::kDefineSetterPropertyUnchecked); | |
1300 break; | |
1301 } | |
1302 } | |
1303 } | |
1304 | |
1305 if (result_saved) { | 1249 if (result_saved) { |
1306 context()->PlugTOS(); | 1250 context()->PlugTOS(); |
1307 } else { | 1251 } else { |
1308 context()->Plug(eax); | 1252 context()->Plug(eax); |
1309 } | 1253 } |
1310 } | 1254 } |
1311 | 1255 |
1312 | 1256 |
1313 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 1257 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
1314 Comment cmnt(masm_, "[ ArrayLiteral"); | 1258 Comment cmnt(masm_, "[ ArrayLiteral"); |
(...skipping 1736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3051 isolate->builtins()->OnStackReplacement()->entry(), | 2995 isolate->builtins()->OnStackReplacement()->entry(), |
3052 Assembler::target_address_at(call_target_address, unoptimized_code)); | 2996 Assembler::target_address_at(call_target_address, unoptimized_code)); |
3053 return ON_STACK_REPLACEMENT; | 2997 return ON_STACK_REPLACEMENT; |
3054 } | 2998 } |
3055 | 2999 |
3056 | 3000 |
3057 } // namespace internal | 3001 } // namespace internal |
3058 } // namespace v8 | 3002 } // namespace v8 |
3059 | 3003 |
3060 #endif // V8_TARGET_ARCH_IA32 | 3004 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |