| 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_X64 | 5 #if V8_TARGET_ARCH_X64 |
| 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 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1178 __ CallStub(&stub); | 1178 __ CallStub(&stub); |
| 1179 RestoreContext(); | 1179 RestoreContext(); |
| 1180 } | 1180 } |
| 1181 PrepareForBailoutForId(expr->CreateLiteralId(), BailoutState::TOS_REGISTER); | 1181 PrepareForBailoutForId(expr->CreateLiteralId(), BailoutState::TOS_REGISTER); |
| 1182 | 1182 |
| 1183 // If result_saved is true the result is on top of the stack. If | 1183 // If result_saved is true the result is on top of the stack. If |
| 1184 // result_saved is false the result is in rax. | 1184 // result_saved is false the result is in rax. |
| 1185 bool result_saved = false; | 1185 bool result_saved = false; |
| 1186 | 1186 |
| 1187 AccessorTable accessor_table(zone()); | 1187 AccessorTable accessor_table(zone()); |
| 1188 int property_index = 0; | 1188 for (int i = 0; i < expr->properties()->length(); i++) { |
| 1189 for (; property_index < expr->properties()->length(); property_index++) { | 1189 ObjectLiteral::Property* property = expr->properties()->at(i); |
| 1190 ObjectLiteral::Property* property = expr->properties()->at(property_index); | 1190 DCHECK(!property->is_computed_name()); |
| 1191 if (property->is_computed_name()) break; | |
| 1192 if (property->IsCompileTimeValue()) continue; | 1191 if (property->IsCompileTimeValue()) continue; |
| 1193 | 1192 |
| 1194 Literal* key = property->key()->AsLiteral(); | 1193 Literal* key = property->key()->AsLiteral(); |
| 1195 Expression* value = property->value(); | 1194 Expression* value = property->value(); |
| 1196 if (!result_saved) { | 1195 if (!result_saved) { |
| 1197 PushOperand(rax); // Save result on the stack | 1196 PushOperand(rax); // Save result on the stack |
| 1198 result_saved = true; | 1197 result_saved = true; |
| 1199 } | 1198 } |
| 1200 switch (property->kind()) { | 1199 switch (property->kind()) { |
| 1201 case ObjectLiteral::Property::CONSTANT: | 1200 case ObjectLiteral::Property::CONSTANT: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 CallRuntimeWithOperands(Runtime::kSetProperty); | 1233 CallRuntimeWithOperands(Runtime::kSetProperty); |
| 1235 } else { | 1234 } else { |
| 1236 DropOperands(3); | 1235 DropOperands(3); |
| 1237 } | 1236 } |
| 1238 break; | 1237 break; |
| 1239 case ObjectLiteral::Property::PROTOTYPE: | 1238 case ObjectLiteral::Property::PROTOTYPE: |
| 1240 PushOperand(Operand(rsp, 0)); // Duplicate receiver. | 1239 PushOperand(Operand(rsp, 0)); // Duplicate receiver. |
| 1241 VisitForStackValue(value); | 1240 VisitForStackValue(value); |
| 1242 DCHECK(property->emit_store()); | 1241 DCHECK(property->emit_store()); |
| 1243 CallRuntimeWithOperands(Runtime::kInternalSetPrototype); | 1242 CallRuntimeWithOperands(Runtime::kInternalSetPrototype); |
| 1244 PrepareForBailoutForId(expr->GetIdForPropertySet(property_index), | 1243 PrepareForBailoutForId(expr->GetIdForPropertySet(i), |
| 1245 BailoutState::NO_REGISTERS); | 1244 BailoutState::NO_REGISTERS); |
| 1246 break; | 1245 break; |
| 1247 case ObjectLiteral::Property::GETTER: | 1246 case ObjectLiteral::Property::GETTER: |
| 1248 if (property->emit_store()) { | 1247 if (property->emit_store()) { |
| 1249 AccessorTable::Iterator it = accessor_table.lookup(key); | 1248 AccessorTable::Iterator it = accessor_table.lookup(key); |
| 1250 it->second->bailout_id = expr->GetIdForPropertySet(property_index); | 1249 it->second->bailout_id = expr->GetIdForPropertySet(i); |
| 1251 it->second->getter = property; | 1250 it->second->getter = property; |
| 1252 } | 1251 } |
| 1253 break; | 1252 break; |
| 1254 case ObjectLiteral::Property::SETTER: | 1253 case ObjectLiteral::Property::SETTER: |
| 1255 if (property->emit_store()) { | 1254 if (property->emit_store()) { |
| 1256 AccessorTable::Iterator it = accessor_table.lookup(key); | 1255 AccessorTable::Iterator it = accessor_table.lookup(key); |
| 1257 it->second->bailout_id = expr->GetIdForPropertySet(property_index); | 1256 it->second->bailout_id = expr->GetIdForPropertySet(i); |
| 1258 it->second->setter = property; | 1257 it->second->setter = property; |
| 1259 } | 1258 } |
| 1260 break; | 1259 break; |
| 1261 } | 1260 } |
| 1262 } | 1261 } |
| 1263 | 1262 |
| 1264 // Emit code to define accessors, using only a single call to the runtime for | 1263 // Emit code to define accessors, using only a single call to the runtime for |
| 1265 // each pair of corresponding getters and setters. | 1264 // each pair of corresponding getters and setters. |
| 1266 for (AccessorTable::Iterator it = accessor_table.begin(); | 1265 for (AccessorTable::Iterator it = accessor_table.begin(); |
| 1267 it != accessor_table.end(); | 1266 it != accessor_table.end(); |
| 1268 ++it) { | 1267 ++it) { |
| 1269 PushOperand(Operand(rsp, 0)); // Duplicate receiver. | 1268 PushOperand(Operand(rsp, 0)); // Duplicate receiver. |
| 1270 VisitForStackValue(it->first); | 1269 VisitForStackValue(it->first); |
| 1271 EmitAccessor(it->second->getter); | 1270 EmitAccessor(it->second->getter); |
| 1272 EmitAccessor(it->second->setter); | 1271 EmitAccessor(it->second->setter); |
| 1273 PushOperand(Smi::FromInt(NONE)); | 1272 PushOperand(Smi::FromInt(NONE)); |
| 1274 CallRuntimeWithOperands(Runtime::kDefineAccessorPropertyUnchecked); | 1273 CallRuntimeWithOperands(Runtime::kDefineAccessorPropertyUnchecked); |
| 1275 PrepareForBailoutForId(it->second->bailout_id, BailoutState::NO_REGISTERS); | 1274 PrepareForBailoutForId(it->second->bailout_id, BailoutState::NO_REGISTERS); |
| 1276 } | 1275 } |
| 1277 | 1276 |
| 1278 // Object literals have two parts. The "static" part on the left contains no | |
| 1279 // computed property names, and so we can compute its map ahead of time; see | |
| 1280 // runtime.cc::CreateObjectLiteralBoilerplate. The second "dynamic" part | |
| 1281 // starts with the first computed property name, and continues with all | |
| 1282 // properties to its right. All the code from above initializes the static | |
| 1283 // component of the object literal, and arranges for the map of the result to | |
| 1284 // reflect the static order in which the keys appear. For the dynamic | |
| 1285 // properties, we compile them into a series of "SetOwnProperty" runtime | |
| 1286 // calls. This will preserve insertion order. | |
| 1287 for (; property_index < expr->properties()->length(); property_index++) { | |
| 1288 ObjectLiteral::Property* property = expr->properties()->at(property_index); | |
| 1289 | |
| 1290 Expression* value = property->value(); | |
| 1291 if (!result_saved) { | |
| 1292 PushOperand(rax); // Save result on the stack | |
| 1293 result_saved = true; | |
| 1294 } | |
| 1295 | |
| 1296 PushOperand(Operand(rsp, 0)); // Duplicate receiver. | |
| 1297 | |
| 1298 if (property->kind() == ObjectLiteral::Property::PROTOTYPE) { | |
| 1299 DCHECK(!property->is_computed_name()); | |
| 1300 VisitForStackValue(value); | |
| 1301 DCHECK(property->emit_store()); | |
| 1302 CallRuntimeWithOperands(Runtime::kInternalSetPrototype); | |
| 1303 PrepareForBailoutForId(expr->GetIdForPropertySet(property_index), | |
| 1304 BailoutState::NO_REGISTERS); | |
| 1305 } else { | |
| 1306 EmitPropertyKey(property, expr->GetIdForPropertyName(property_index)); | |
| 1307 VisitForStackValue(value); | |
| 1308 if (NeedsHomeObject(value)) { | |
| 1309 EmitSetHomeObject(value, 2, property->GetSlot()); | |
| 1310 } | |
| 1311 | |
| 1312 switch (property->kind()) { | |
| 1313 case ObjectLiteral::Property::CONSTANT: | |
| 1314 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | |
| 1315 case ObjectLiteral::Property::COMPUTED: | |
| 1316 case ObjectLiteral::Property::PROTOTYPE: | |
| 1317 UNREACHABLE(); | |
| 1318 break; | |
| 1319 | |
| 1320 case ObjectLiteral::Property::GETTER: | |
| 1321 PushOperand(Smi::FromInt(NONE)); | |
| 1322 CallRuntimeWithOperands(Runtime::kDefineGetterPropertyUnchecked); | |
| 1323 break; | |
| 1324 | |
| 1325 case ObjectLiteral::Property::SETTER: | |
| 1326 PushOperand(Smi::FromInt(NONE)); | |
| 1327 CallRuntimeWithOperands(Runtime::kDefineSetterPropertyUnchecked); | |
| 1328 break; | |
| 1329 } | |
| 1330 } | |
| 1331 } | |
| 1332 | |
| 1333 if (result_saved) { | 1277 if (result_saved) { |
| 1334 context()->PlugTOS(); | 1278 context()->PlugTOS(); |
| 1335 } else { | 1279 } else { |
| 1336 context()->Plug(rax); | 1280 context()->Plug(rax); |
| 1337 } | 1281 } |
| 1338 } | 1282 } |
| 1339 | 1283 |
| 1340 | 1284 |
| 1341 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 1285 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1342 Comment cmnt(masm_, "[ ArrayLiteral"); | 1286 Comment cmnt(masm_, "[ ArrayLiteral"); |
| (...skipping 1693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3036 DCHECK_EQ( | 2980 DCHECK_EQ( |
| 3037 isolate->builtins()->OnStackReplacement()->entry(), | 2981 isolate->builtins()->OnStackReplacement()->entry(), |
| 3038 Assembler::target_address_at(call_target_address, unoptimized_code)); | 2982 Assembler::target_address_at(call_target_address, unoptimized_code)); |
| 3039 return ON_STACK_REPLACEMENT; | 2983 return ON_STACK_REPLACEMENT; |
| 3040 } | 2984 } |
| 3041 | 2985 |
| 3042 } // namespace internal | 2986 } // namespace internal |
| 3043 } // namespace v8 | 2987 } // namespace v8 |
| 3044 | 2988 |
| 3045 #endif // V8_TARGET_ARCH_X64 | 2989 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |