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

Side by Side Diff: src/compiler/ast-graph-builder.cc

Issue 2330473002: Class fields, part 3 (backends)
Patch Set: bytecode test Created 4 years, 3 months 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
« no previous file with comments | « no previous file | src/full-codegen/arm/full-codegen-arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/compiler/ast-graph-builder.h" 5 #include "src/compiler/ast-graph-builder.h"
6 6
7 #include "src/ast/compile-time-value.h" 7 #include "src/ast/compile-time-value.h"
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/compilation-info.h" 9 #include "src/compilation-info.h"
10 #include "src/compiler.h" 10 #include "src/compiler.h"
(...skipping 1573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 Node* constructor = environment()->Pop(); 1584 Node* constructor = environment()->Pop();
1585 Node* extends = environment()->Pop(); 1585 Node* extends = environment()->Pop();
1586 Node* start = jsgraph()->Constant(expr->start_position()); 1586 Node* start = jsgraph()->Constant(expr->start_position());
1587 Node* end = jsgraph()->Constant(expr->end_position()); 1587 Node* end = jsgraph()->Constant(expr->end_position());
1588 const Operator* opc = javascript()->CallRuntime(Runtime::kDefineClass); 1588 const Operator* opc = javascript()->CallRuntime(Runtime::kDefineClass);
1589 Node* literal = NewNode(opc, extends, constructor, start, end); 1589 Node* literal = NewNode(opc, extends, constructor, start, end);
1590 PrepareFrameState(literal, expr->CreateLiteralId(), 1590 PrepareFrameState(literal, expr->CreateLiteralId(),
1591 OutputFrameStateCombine::Push()); 1591 OutputFrameStateCombine::Push());
1592 environment()->Push(literal); 1592 environment()->Push(literal);
1593 1593
1594 // The below proxy exists to allow static field initializers to have the
1595 // correct home object and receiver. It's only necessary if the initializers
1596 // are called as a part of class definition instead of immediately after it,
1597 // in which case they could simply refer to the class just constructed. The
1598 // latter is actually what's currently specified, and this will need to be
1599 // changed if that behavior is settled upon. See also
1600 // https://github.com/tc39/proposal-class-public-fields/issues/50
1601 VariableProxy* static_initializer_proxy = expr->static_initializer_proxy();
1602 if (static_initializer_proxy != nullptr) {
1603 Variable* variable = static_initializer_proxy->var();
1604 BuildVariableAssignment(variable, literal, Token::INIT,
1605 CreateVectorSlotPair(FeedbackVectorSlot::Invalid()),
1606 BailoutId::None());
1607 }
1608
1594 // Load the "prototype" from the constructor. 1609 // Load the "prototype" from the constructor.
1595 PrepareEagerCheckpoint(expr->CreateLiteralId()); 1610 PrepareEagerCheckpoint(expr->CreateLiteralId());
1596 Handle<Name> name = isolate()->factory()->prototype_string(); 1611 Handle<Name> name = isolate()->factory()->prototype_string();
1597 VectorSlotPair pair = CreateVectorSlotPair(expr->PrototypeSlot()); 1612 VectorSlotPair pair = CreateVectorSlotPair(expr->PrototypeSlot());
1598 Node* prototype = BuildNamedLoad(literal, name, pair); 1613 Node* prototype = BuildNamedLoad(literal, name, pair);
1599 PrepareFrameState(prototype, expr->PrototypeId(), 1614 PrepareFrameState(prototype, expr->PrototypeId(),
1600 OutputFrameStateCombine::Push()); 1615 OutputFrameStateCombine::Push());
1601 environment()->Push(prototype); 1616 environment()->Push(prototype);
1602 1617
1603 // Create nodes to store method values into the literal. 1618 // Create nodes to store method values into the literal.
1604 for (int i = 0; i < expr->properties()->length(); i++) { 1619 for (int i = 0; i < expr->properties()->length(); i++) {
1605 ClassLiteral::Property* property = expr->properties()->at(i); 1620 ClassLiteral::Property* property = expr->properties()->at(i);
1621
1622 if (property->kind() == ClassLiteral::Property::FIELD &&
1623 !property->is_static()) {
1624 // Non-static properties produced by the parser have as their 'key' an
1625 // expression producing their name and as their 'value' a variable which
1626 // is refered to by the synthetic initializer function in order to
1627 // determine the name during class instantiation. This is necessary
1628 // because computed names must only be evaluated once, at class definition
1629 // time.
1630 // That is, code which looks like `class C { [f()] = 1; }` is desugared
1631 // into something like
1632 // class C { constructor(){ this.[.class-field-0-name] = 1; } };
1633 // let .class-field-0-name = f();
1634 // except that the assignment to .class-field-name-0 occurs interleaved
1635 // with the rest of the class body; it is performed by the block in which
1636 // this comment appears.
1637 Variable* variable = property->value()->AsVariableProxy()->var();
1638 VisitForValue(property->key());
1639 Node* key = environment()->Pop();
1640 BuildVariableAssignment(
1641 variable, key, Token::INIT,
1642 CreateVectorSlotPair(FeedbackVectorSlot::Invalid()),
1643 BailoutId::None());
1644 continue;
1645 }
1646
1606 environment()->Push(environment()->Peek(property->is_static() ? 1 : 0)); 1647 environment()->Push(environment()->Peek(property->is_static() ? 1 : 0));
1607 1648
1608 VisitForValue(property->key()); 1649 VisitForValue(property->key());
1609 Node* name = BuildToName(environment()->Pop(), expr->GetIdForProperty(i)); 1650 Node* name = BuildToName(environment()->Pop(), expr->GetIdForProperty(i));
1610 environment()->Push(name); 1651 environment()->Push(name);
1611 1652
1612 // The static prototype property is read only. We handle the non computed 1653 // The static prototype property is read only. We handle the non computed
1613 // property name case in the parser. Since this is the only case where we 1654 // property name case in the parser. Since this is the only case where we
1614 // need to check for an own read only property we special case this so we do 1655 // need to check for an own read only property we special case this so we do
1615 // not need to do this for every property. 1656 // not need to do this for every property.
(...skipping 29 matching lines...) Expand all
1645 break; 1686 break;
1646 } 1687 }
1647 case ClassLiteral::Property::SETTER: { 1688 case ClassLiteral::Property::SETTER: {
1648 Node* attr = jsgraph()->Constant(DONT_ENUM); 1689 Node* attr = jsgraph()->Constant(DONT_ENUM);
1649 const Operator* op = javascript()->CallRuntime( 1690 const Operator* op = javascript()->CallRuntime(
1650 Runtime::kDefineSetterPropertyUnchecked, 4); 1691 Runtime::kDefineSetterPropertyUnchecked, 4);
1651 NewNode(op, receiver, key, value, attr); 1692 NewNode(op, receiver, key, value, attr);
1652 break; 1693 break;
1653 } 1694 }
1654 case ClassLiteral::Property::FIELD: { 1695 case ClassLiteral::Property::FIELD: {
1655 UNREACHABLE(); 1696 DCHECK(property->is_static());
1697 Node* attr = jsgraph()->Constant(DONT_ENUM);
1698 Node* set_function_name =
1699 jsgraph()->Constant(property->NeedsSetFunctionName());
1700 const Operator* op =
1701 javascript()->CallRuntime(Runtime::kDefineDataPropertyInLiteral);
1702 Node* call = NewNode(op, receiver, key, value, attr, set_function_name);
1703 PrepareFrameState(call, BailoutId::None());
1656 break; 1704 break;
1657 } 1705 }
1658 } 1706 }
1659 } 1707 }
1660 1708
1661 // Set the constructor to have fast properties. 1709 // Set the constructor to have fast properties.
1662 prototype = environment()->Pop(); 1710 prototype = environment()->Pop();
1663 literal = environment()->Pop(); 1711 literal = environment()->Pop();
1664 const Operator* op = javascript()->CallRuntime(Runtime::kToFastProperties); 1712 const Operator* op = javascript()->CallRuntime(Runtime::kToFastProperties);
1665 literal = NewNode(op, literal); 1713 literal = NewNode(op, literal);
(...skipping 2667 matching lines...) Expand 10 before | Expand all | Expand 10 after
4333 // Phi does not exist yet, introduce one. 4381 // Phi does not exist yet, introduce one.
4334 value = NewPhi(inputs, value, control); 4382 value = NewPhi(inputs, value, control);
4335 value->ReplaceInput(inputs - 1, other); 4383 value->ReplaceInput(inputs - 1, other);
4336 } 4384 }
4337 return value; 4385 return value;
4338 } 4386 }
4339 4387
4340 } // namespace compiler 4388 } // namespace compiler
4341 } // namespace internal 4389 } // namespace internal
4342 } // namespace v8 4390 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/full-codegen/arm/full-codegen-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698