Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: src/ia32/full-codegen-ia32.cc

Issue 795573005: ES6 computed property names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: moar cleanup Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #if V8_TARGET_ARCH_IA32 7 #if V8_TARGET_ARCH_IA32
8 8
9 #include "src/code-factory.h" 9 #include "src/code-factory.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 // If result_saved is true the result is on top of the stack. If 1610 // If result_saved is true the result is on top of the stack. If
1611 // result_saved is false the result is in eax. 1611 // result_saved is false the result is in eax.
1612 bool result_saved = false; 1612 bool result_saved = false;
1613 1613
1614 // Mark all computed expressions that are bound to a key that 1614 // Mark all computed expressions that are bound to a key that
1615 // is shadowed by a later occurrence of the same key. For the 1615 // is shadowed by a later occurrence of the same key. For the
1616 // marked expressions, no store code is emitted. 1616 // marked expressions, no store code is emitted.
1617 expr->CalculateEmitStore(zone()); 1617 expr->CalculateEmitStore(zone());
1618 1618
1619 AccessorTable accessor_table(zone()); 1619 AccessorTable accessor_table(zone());
1620 for (int i = 0; i < expr->properties()->length(); i++) { 1620 int property_index = 0;
1621 ObjectLiteral::Property* property = expr->properties()->at(i); 1621 for (; property_index < expr->properties()->length(); property_index++) {
1622 ObjectLiteral::Property* property = expr->properties()->at(property_index);
1623 if (property->is_computed_name()) break;
1622 if (property->IsCompileTimeValue()) continue; 1624 if (property->IsCompileTimeValue()) continue;
1623 1625
1624 Literal* key = property->key(); 1626 Literal* key = property->key()->AsLiteral();
1625 Expression* value = property->value(); 1627 Expression* value = property->value();
1626 if (!result_saved) { 1628 if (!result_saved) {
1627 __ push(eax); // Save result on the stack 1629 __ push(eax); // Save result on the stack
1628 result_saved = true; 1630 result_saved = true;
1629 } 1631 }
1630 switch (property->kind()) { 1632 switch (property->kind()) {
1631 case ObjectLiteral::Property::CONSTANT: 1633 case ObjectLiteral::Property::CONSTANT:
1632 UNREACHABLE(); 1634 UNREACHABLE();
1633 case ObjectLiteral::Property::MATERIALIZED_LITERAL: 1635 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1634 DCHECK(!CompileTimeValue::IsCompileTimeValue(value)); 1636 DCHECK(!CompileTimeValue::IsCompileTimeValue(value));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 __ push(Operand(esp, 0)); // Duplicate receiver. 1696 __ push(Operand(esp, 0)); // Duplicate receiver.
1695 VisitForStackValue(it->first); 1697 VisitForStackValue(it->first);
1696 EmitAccessor(it->second->getter); 1698 EmitAccessor(it->second->getter);
1697 EmitSetHomeObjectIfNeeded(it->second->getter, 2); 1699 EmitSetHomeObjectIfNeeded(it->second->getter, 2);
1698 EmitAccessor(it->second->setter); 1700 EmitAccessor(it->second->setter);
1699 EmitSetHomeObjectIfNeeded(it->second->setter, 3); 1701 EmitSetHomeObjectIfNeeded(it->second->setter, 3);
1700 __ push(Immediate(Smi::FromInt(NONE))); 1702 __ push(Immediate(Smi::FromInt(NONE)));
1701 __ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 5); 1703 __ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 5);
1702 } 1704 }
1703 1705
1706 // Object literals have two parts. The "static" part on the left contains no
1707 // computed property names, and so we can compute its map ahead of time; see
1708 // runtime.cc::CreateObjectLiteralBoilerplate. The second "dynamic" part
1709 // starts with the first computed property name, and continues with all
1710 // properties to its right. All the code from above initializes the static
1711 // component of the object literal, and arranges for the map of the result to
1712 // reflect the static order in which the keys appear. For the dynamic
1713 // properties, we compile them into a series of "SetOwnProperty" runtime
1714 // calls. This will preserve insertion order.
1715 for (; property_index < expr->properties()->length(); property_index++) {
1716 ObjectLiteral::Property* property = expr->properties()->at(property_index);
1717
1718 Expression* value = property->value();
1719 Expression* key = property->key();
1720 if (!result_saved) {
1721 __ push(eax); // Save result on the stack
1722 result_saved = true;
1723 }
1724
1725 switch (property->kind()) {
Dmitry Lomov (no reviews) 2014/12/12 15:11:58 Suggestion about this switch - all cases except PR
arv (Not doing code reviews) 2014/12/12 16:49:34 Done.
1726 case ObjectLiteral::Property::CONSTANT:
1727 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1728 case ObjectLiteral::Property::COMPUTED:
1729 __ push(Operand(esp, 0)); // Duplicate receiver.
1730 VisitForStackValue(key);
1731 if (property->is_computed_name()) {
1732 __ InvokeBuiltin(Builtins::TO_NAME, CALL_FUNCTION);
1733 __ Push(result_register());
1734 }
1735 VisitForStackValue(value);
1736 if (property->emit_store()) {
1737 __ push(Immediate(Smi::FromInt(NONE)));
1738 __ CallRuntime(Runtime::kDefineDataPropertyUnchecked, 4);
1739 } else {
1740 __ Drop(3);
1741 }
1742 break;
1743 case ObjectLiteral::Property::PROTOTYPE:
1744 DCHECK(!property->is_computed_name());
1745 __ push(Operand(esp, 0)); // Duplicate receiver.
1746 VisitForStackValue(value);
1747 if (property->emit_store()) {
1748 __ CallRuntime(Runtime::kInternalSetPrototype, 2);
1749 } else {
1750 __ Drop(2);
1751 }
1752 break;
1753
1754 case ObjectLiteral::Property::GETTER:
1755 __ push(Operand(esp, 0)); // Duplicate receiver.
1756 VisitForStackValue(key);
1757 VisitForStackValue(value);
1758 __ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 3);
1759 break;
1760
1761 case ObjectLiteral::Property::SETTER:
1762 __ push(Operand(esp, 0)); // Duplicate receiver.
1763 VisitForStackValue(key);
1764 VisitForStackValue(value);
1765 __ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 3);
1766 break;
1767 }
1768 }
1769
1704 if (expr->has_function()) { 1770 if (expr->has_function()) {
1705 DCHECK(result_saved); 1771 DCHECK(result_saved);
1706 __ push(Operand(esp, 0)); 1772 __ push(Operand(esp, 0));
1707 __ CallRuntime(Runtime::kToFastProperties, 1); 1773 __ CallRuntime(Runtime::kToFastProperties, 1);
1708 } 1774 }
1709 1775
1710 if (result_saved) { 1776 if (result_saved) {
1711 context()->PlugTOS(); 1777 context()->PlugTOS();
1712 } else { 1778 } else {
1713 context()->Plug(eax); 1779 context()->Plug(eax);
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
2387 __ push(eax); 2453 __ push(eax);
2388 2454
2389 // No access check is needed here since the constructor is created by the 2455 // No access check is needed here since the constructor is created by the
2390 // class literal. 2456 // class literal.
2391 Register scratch = ebx; 2457 Register scratch = ebx;
2392 __ mov(scratch, FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset)); 2458 __ mov(scratch, FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset));
2393 __ Push(scratch); 2459 __ Push(scratch);
2394 2460
2395 for (int i = 0; i < lit->properties()->length(); i++) { 2461 for (int i = 0; i < lit->properties()->length(); i++) {
2396 ObjectLiteral::Property* property = lit->properties()->at(i); 2462 ObjectLiteral::Property* property = lit->properties()->at(i);
2397 Literal* key = property->key()->AsLiteral();
2398 Expression* value = property->value(); 2463 Expression* value = property->value();
2464 Expression* key = property->key();
2399 DCHECK(key != NULL); 2465 DCHECK(key != NULL);
2400 2466
2401 if (property->is_static()) { 2467 if (property->is_static()) {
2402 __ push(Operand(esp, kPointerSize)); // constructor 2468 __ push(Operand(esp, kPointerSize)); // constructor
2403 } else { 2469 } else {
2404 __ push(Operand(esp, 0)); // prototype 2470 __ push(Operand(esp, 0)); // prototype
2405 } 2471 }
2406 VisitForStackValue(key); 2472 VisitForStackValue(key);
2407 VisitForStackValue(value); 2473 VisitForStackValue(value);
2408 EmitSetHomeObjectIfNeeded(value, 2); 2474 EmitSetHomeObjectIfNeeded(value, 2);
2409 2475
2410 switch (property->kind()) { 2476 switch (property->kind()) {
2411 case ObjectLiteral::Property::CONSTANT: 2477 case ObjectLiteral::Property::CONSTANT:
2412 case ObjectLiteral::Property::MATERIALIZED_LITERAL: 2478 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
2413 case ObjectLiteral::Property::COMPUTED: 2479 case ObjectLiteral::Property::COMPUTED:
2414 case ObjectLiteral::Property::PROTOTYPE: 2480 case ObjectLiteral::Property::PROTOTYPE:
2415 __ CallRuntime(Runtime::kDefineClassMethod, 3); 2481 __ CallRuntime(Runtime::kDefineClassMethod, 3);
2416 break; 2482 break;
2417 2483
2418 case ObjectLiteral::Property::GETTER: 2484 case ObjectLiteral::Property::GETTER:
2419 __ CallRuntime(Runtime::kDefineClassGetter, 3); 2485 __ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 3);
2420 break; 2486 break;
2421 2487
2422 case ObjectLiteral::Property::SETTER: 2488 case ObjectLiteral::Property::SETTER:
2423 __ CallRuntime(Runtime::kDefineClassSetter, 3); 2489 __ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 3);
2424 break; 2490 break;
2425 2491
2426 default: 2492 default:
2427 UNREACHABLE(); 2493 UNREACHABLE();
2428 } 2494 }
2429 } 2495 }
2430 2496
2431 // prototype 2497 // prototype
2432 __ CallRuntime(Runtime::kToFastProperties, 1); 2498 __ CallRuntime(Runtime::kToFastProperties, 1);
2433 2499
(...skipping 2742 matching lines...) Expand 10 before | Expand all | Expand 10 after
5176 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), 5242 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(),
5177 Assembler::target_address_at(call_target_address, 5243 Assembler::target_address_at(call_target_address,
5178 unoptimized_code)); 5244 unoptimized_code));
5179 return OSR_AFTER_STACK_CHECK; 5245 return OSR_AFTER_STACK_CHECK;
5180 } 5246 }
5181 5247
5182 5248
5183 } } // namespace v8::internal 5249 } } // namespace v8::internal
5184 5250
5185 #endif // V8_TARGET_ARCH_IA32 5251 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/hydrogen.cc ('k') | src/mips/full-codegen-mips.cc » ('j') | src/preparser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698