OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1404 __ mov(FieldOperand(eax, i + kPointerSize), ecx); | 1404 __ mov(FieldOperand(eax, i + kPointerSize), ecx); |
1405 } | 1405 } |
1406 if ((size % (2 * kPointerSize)) != 0) { | 1406 if ((size % (2 * kPointerSize)) != 0) { |
1407 __ mov(edx, FieldOperand(ebx, size - kPointerSize)); | 1407 __ mov(edx, FieldOperand(ebx, size - kPointerSize)); |
1408 __ mov(FieldOperand(eax, size - kPointerSize), edx); | 1408 __ mov(FieldOperand(eax, size - kPointerSize), edx); |
1409 } | 1409 } |
1410 context()->Plug(eax); | 1410 context()->Plug(eax); |
1411 } | 1411 } |
1412 | 1412 |
1413 | 1413 |
1414 void FullCodeGenerator::EmitAccessor(Expression* expression) { | |
1415 if (expression == NULL) { | |
1416 __ push(Immediate(isolate()->factory()->null_value())); | |
1417 } else { | |
1418 VisitForStackValue(expression); | |
1419 } | |
1420 } | |
1421 | |
1422 | |
1414 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { | 1423 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
1415 Comment cmnt(masm_, "[ ObjectLiteral"); | 1424 Comment cmnt(masm_, "[ ObjectLiteral"); |
1416 Handle<FixedArray> constant_properties = expr->constant_properties(); | 1425 Handle<FixedArray> constant_properties = expr->constant_properties(); |
1417 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1426 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
1418 __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); | 1427 __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); |
1419 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | 1428 __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
1420 __ push(Immediate(constant_properties)); | 1429 __ push(Immediate(constant_properties)); |
1421 int flags = expr->fast_elements() | 1430 int flags = expr->fast_elements() |
1422 ? ObjectLiteral::kFastElements | 1431 ? ObjectLiteral::kFastElements |
1423 : ObjectLiteral::kNoFlags; | 1432 : ObjectLiteral::kNoFlags; |
(...skipping 14 matching lines...) Expand all Loading... | |
1438 | 1447 |
1439 // If result_saved is true the result is on top of the stack. If | 1448 // If result_saved is true the result is on top of the stack. If |
1440 // result_saved is false the result is in eax. | 1449 // result_saved is false the result is in eax. |
1441 bool result_saved = false; | 1450 bool result_saved = false; |
1442 | 1451 |
1443 // Mark all computed expressions that are bound to a key that | 1452 // Mark all computed expressions that are bound to a key that |
1444 // is shadowed by a later occurrence of the same key. For the | 1453 // is shadowed by a later occurrence of the same key. For the |
1445 // marked expressions, no store code is emitted. | 1454 // marked expressions, no store code is emitted. |
1446 expr->CalculateEmitStore(); | 1455 expr->CalculateEmitStore(); |
1447 | 1456 |
1457 AccessorTable accessor_table(isolate()->zone()); | |
1448 for (int i = 0; i < expr->properties()->length(); i++) { | 1458 for (int i = 0; i < expr->properties()->length(); i++) { |
1449 ObjectLiteral::Property* property = expr->properties()->at(i); | 1459 ObjectLiteral::Property* property = expr->properties()->at(i); |
1450 if (property->IsCompileTimeValue()) continue; | 1460 if (property->IsCompileTimeValue()) continue; |
1451 | 1461 |
1452 Literal* key = property->key(); | 1462 Literal* key = property->key(); |
1453 Expression* value = property->value(); | 1463 Expression* value = property->value(); |
1454 if (!result_saved) { | 1464 if (!result_saved) { |
1455 __ push(eax); // Save result on the stack | 1465 __ push(eax); // Save result on the stack |
1456 result_saved = true; | 1466 result_saved = true; |
1457 } | 1467 } |
1458 switch (property->kind()) { | 1468 switch (property->kind()) { |
1469 case ObjectLiteral::Property::CONSTANT: | |
1470 UNREACHABLE(); | |
1459 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | 1471 case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
1460 ASSERT(!CompileTimeValue::IsCompileTimeValue(value)); | 1472 ASSERT(!CompileTimeValue::IsCompileTimeValue(value)); |
1461 // Fall through. | 1473 // Fall through. |
1462 case ObjectLiteral::Property::COMPUTED: | 1474 case ObjectLiteral::Property::COMPUTED: |
1463 if (key->handle()->IsSymbol()) { | 1475 if (key->handle()->IsSymbol()) { |
1464 if (property->emit_store()) { | 1476 if (property->emit_store()) { |
1465 VisitForAccumulatorValue(value); | 1477 VisitForAccumulatorValue(value); |
1466 __ mov(ecx, Immediate(key->handle())); | 1478 __ mov(ecx, Immediate(key->handle())); |
1467 __ mov(edx, Operand(esp, 0)); | 1479 __ mov(edx, Operand(esp, 0)); |
1468 Handle<Code> ic = is_classic_mode() | 1480 Handle<Code> ic = is_classic_mode() |
(...skipping 11 matching lines...) Expand all Loading... | |
1480 __ push(Operand(esp, 0)); // Duplicate receiver. | 1492 __ push(Operand(esp, 0)); // Duplicate receiver. |
1481 VisitForStackValue(key); | 1493 VisitForStackValue(key); |
1482 VisitForStackValue(value); | 1494 VisitForStackValue(value); |
1483 if (property->emit_store()) { | 1495 if (property->emit_store()) { |
1484 __ push(Immediate(Smi::FromInt(NONE))); // PropertyAttributes | 1496 __ push(Immediate(Smi::FromInt(NONE))); // PropertyAttributes |
1485 __ CallRuntime(Runtime::kSetProperty, 4); | 1497 __ CallRuntime(Runtime::kSetProperty, 4); |
1486 } else { | 1498 } else { |
1487 __ Drop(3); | 1499 __ Drop(3); |
1488 } | 1500 } |
1489 break; | 1501 break; |
1502 case ObjectLiteral::Property::GETTER: | |
1503 accessor_table.lookup(key)->second->getter = value; | |
1504 break; | |
1490 case ObjectLiteral::Property::SETTER: | 1505 case ObjectLiteral::Property::SETTER: |
1491 case ObjectLiteral::Property::GETTER: | 1506 accessor_table.lookup(key)->second->setter = value; |
1492 __ push(Operand(esp, 0)); // Duplicate receiver. | |
1493 VisitForStackValue(key); | |
1494 if (property->kind() == ObjectLiteral::Property::GETTER) { | |
1495 VisitForStackValue(value); | |
1496 __ push(Immediate(isolate()->factory()->null_value())); | |
1497 } else { | |
1498 __ push(Immediate(isolate()->factory()->null_value())); | |
1499 VisitForStackValue(value); | |
1500 } | |
1501 __ push(Immediate(Smi::FromInt(NONE))); | |
1502 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); | |
1503 break; | 1507 break; |
1504 default: UNREACHABLE(); | |
1505 } | 1508 } |
1506 } | 1509 } |
1507 | 1510 |
1511 // Emit code to define accessors, using only a single call to the runtime for | |
Vitaly Repeshko
2012/03/15 07:59:27
Can this share at least some code with CalculateEm
| |
1512 // each pair of corresponding getters and setters. | |
1513 for (AccessorTable::Iterator it = accessor_table.begin(); | |
1514 it != accessor_table.end(); | |
1515 ++it) { | |
1516 __ push(Operand(esp, 0)); // Duplicate receiver. | |
1517 VisitForStackValue(it->first); | |
1518 EmitAccessor(it->second->getter); | |
1519 EmitAccessor(it->second->setter); | |
1520 __ push(Immediate(Smi::FromInt(NONE))); | |
1521 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); | |
1522 } | |
1523 | |
1508 if (expr->has_function()) { | 1524 if (expr->has_function()) { |
1509 ASSERT(result_saved); | 1525 ASSERT(result_saved); |
1510 __ push(Operand(esp, 0)); | 1526 __ push(Operand(esp, 0)); |
1511 __ CallRuntime(Runtime::kToFastProperties, 1); | 1527 __ CallRuntime(Runtime::kToFastProperties, 1); |
1512 } | 1528 } |
1513 | 1529 |
1514 if (result_saved) { | 1530 if (result_saved) { |
1515 context()->PlugTOS(); | 1531 context()->PlugTOS(); |
1516 } else { | 1532 } else { |
1517 context()->Plug(eax); | 1533 context()->Plug(eax); |
(...skipping 2962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4480 *context_length = 0; | 4496 *context_length = 0; |
4481 return previous_; | 4497 return previous_; |
4482 } | 4498 } |
4483 | 4499 |
4484 | 4500 |
4485 #undef __ | 4501 #undef __ |
4486 | 4502 |
4487 } } // namespace v8::internal | 4503 } } // namespace v8::internal |
4488 | 4504 |
4489 #endif // V8_TARGET_ARCH_IA32 | 4505 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |