OLD | NEW |
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/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
9 #include "src/compiler/ast-loop-assignment-analyzer.h" | 9 #include "src/compiler/ast-loop-assignment-analyzer.h" |
10 #include "src/compiler/control-builders.h" | 10 #include "src/compiler/control-builders.h" |
(...skipping 1621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 CHECK(!shared_info.is_null()); // TODO(mstarzinger): Set stack overflow? | 1632 CHECK(!shared_info.is_null()); // TODO(mstarzinger): Set stack overflow? |
1633 | 1633 |
1634 // Create node to instantiate a new closure. | 1634 // Create node to instantiate a new closure. |
1635 PretenureFlag pretenure = expr->pretenure() ? TENURED : NOT_TENURED; | 1635 PretenureFlag pretenure = expr->pretenure() ? TENURED : NOT_TENURED; |
1636 const Operator* op = javascript()->CreateClosure(shared_info, pretenure); | 1636 const Operator* op = javascript()->CreateClosure(shared_info, pretenure); |
1637 Node* value = NewNode(op); | 1637 Node* value = NewNode(op); |
1638 ast_context()->ProduceValue(expr, value); | 1638 ast_context()->ProduceValue(expr, value); |
1639 } | 1639 } |
1640 | 1640 |
1641 | 1641 |
1642 void AstGraphBuilder::VisitClassLiteral(ClassLiteral* expr) { | |
1643 // Visit declarations and class literal in a block scope. | |
1644 if (expr->scope()->ContextLocalCount() > 0) { | |
1645 Node* context = BuildLocalBlockContext(expr->scope()); | |
1646 ContextScope scope(this, expr->scope(), context); | |
1647 VisitDeclarations(expr->scope()->declarations()); | |
1648 VisitClassLiteralContents(expr); | |
1649 } else { | |
1650 VisitDeclarations(expr->scope()->declarations()); | |
1651 VisitClassLiteralContents(expr); | |
1652 } | |
1653 } | |
1654 | |
1655 | |
1656 void AstGraphBuilder::VisitClassLiteralContents(ClassLiteral* expr) { | |
1657 VisitForValueOrTheHole(expr->extends()); | |
1658 VisitForValue(expr->constructor()); | |
1659 | |
1660 // Create node to instantiate a new class. | |
1661 Node* constructor = environment()->Pop(); | |
1662 Node* extends = environment()->Pop(); | |
1663 Node* start = jsgraph()->Constant(expr->start_position()); | |
1664 Node* end = jsgraph()->Constant(expr->end_position()); | |
1665 const Operator* opc = javascript()->CallRuntime(Runtime::kDefineClass); | |
1666 Node* literal = NewNode(opc, extends, constructor, start, end); | |
1667 PrepareFrameState(literal, expr->CreateLiteralId(), | |
1668 OutputFrameStateCombine::Push()); | |
1669 environment()->Push(literal); | |
1670 | |
1671 // Load the "prototype" from the constructor. | |
1672 PrepareEagerCheckpoint(expr->CreateLiteralId()); | |
1673 Handle<Name> name = isolate()->factory()->prototype_string(); | |
1674 VectorSlotPair pair = CreateVectorSlotPair(expr->PrototypeSlot()); | |
1675 Node* prototype = BuildNamedLoad(literal, name, pair); | |
1676 PrepareFrameState(prototype, expr->PrototypeId(), | |
1677 OutputFrameStateCombine::Push()); | |
1678 environment()->Push(prototype); | |
1679 | |
1680 // Create nodes to store method values into the literal. | |
1681 for (int i = 0; i < expr->properties()->length(); i++) { | |
1682 ObjectLiteral::Property* property = expr->properties()->at(i); | |
1683 environment()->Push(environment()->Peek(property->is_static() ? 1 : 0)); | |
1684 | |
1685 VisitForValue(property->key()); | |
1686 Node* name = BuildToName(environment()->Pop(), expr->GetIdForProperty(i)); | |
1687 environment()->Push(name); | |
1688 | |
1689 // The static prototype property is read only. We handle the non computed | |
1690 // property name case in the parser. Since this is the only case where we | |
1691 // need to check for an own read only property we special case this so we do | |
1692 // not need to do this for every property. | |
1693 if (property->is_static() && property->is_computed_name()) { | |
1694 Node* check = BuildThrowIfStaticPrototype(environment()->Pop(), | |
1695 expr->GetIdForProperty(i)); | |
1696 environment()->Push(check); | |
1697 } | |
1698 | |
1699 VisitForValue(property->value()); | |
1700 Node* value = environment()->Pop(); | |
1701 Node* key = environment()->Pop(); | |
1702 Node* receiver = environment()->Pop(); | |
1703 | |
1704 BuildSetHomeObject(value, receiver, property); | |
1705 | |
1706 switch (property->kind()) { | |
1707 case ObjectLiteral::Property::CONSTANT: | |
1708 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | |
1709 case ObjectLiteral::Property::PROTOTYPE: | |
1710 UNREACHABLE(); | |
1711 case ObjectLiteral::Property::COMPUTED: { | |
1712 Node* attr = jsgraph()->Constant(DONT_ENUM); | |
1713 Node* set_function_name = | |
1714 jsgraph()->Constant(property->NeedsSetFunctionName()); | |
1715 const Operator* op = | |
1716 javascript()->CallRuntime(Runtime::kDefineDataPropertyInLiteral); | |
1717 Node* call = NewNode(op, receiver, key, value, attr, set_function_name); | |
1718 PrepareFrameState(call, BailoutId::None()); | |
1719 break; | |
1720 } | |
1721 case ObjectLiteral::Property::GETTER: { | |
1722 Node* attr = jsgraph()->Constant(DONT_ENUM); | |
1723 const Operator* op = javascript()->CallRuntime( | |
1724 Runtime::kDefineGetterPropertyUnchecked, 4); | |
1725 NewNode(op, receiver, key, value, attr); | |
1726 break; | |
1727 } | |
1728 case ObjectLiteral::Property::SETTER: { | |
1729 Node* attr = jsgraph()->Constant(DONT_ENUM); | |
1730 const Operator* op = javascript()->CallRuntime( | |
1731 Runtime::kDefineSetterPropertyUnchecked, 4); | |
1732 NewNode(op, receiver, key, value, attr); | |
1733 break; | |
1734 } | |
1735 } | |
1736 } | |
1737 | |
1738 // Set the constructor to have fast properties. | |
1739 prototype = environment()->Pop(); | |
1740 literal = environment()->Pop(); | |
1741 const Operator* op = javascript()->CallRuntime(Runtime::kToFastProperties); | |
1742 literal = NewNode(op, literal); | |
1743 | |
1744 // Assign to class variable. | |
1745 if (expr->class_variable_proxy() != nullptr) { | |
1746 Variable* var = expr->class_variable_proxy()->var(); | |
1747 VectorSlotPair feedback = CreateVectorSlotPair( | |
1748 expr->NeedsProxySlot() ? expr->ProxySlot() | |
1749 : FeedbackVectorSlot::Invalid()); | |
1750 BuildVariableAssignment(var, literal, Token::INIT, feedback, | |
1751 BailoutId::None()); | |
1752 } | |
1753 ast_context()->ProduceValue(expr, literal); | |
1754 } | |
1755 | |
1756 | |
1757 void AstGraphBuilder::VisitNativeFunctionLiteral(NativeFunctionLiteral* expr) { | 1642 void AstGraphBuilder::VisitNativeFunctionLiteral(NativeFunctionLiteral* expr) { |
1758 UNREACHABLE(); | 1643 UNREACHABLE(); |
1759 } | 1644 } |
1760 | 1645 |
1761 | 1646 |
1762 void AstGraphBuilder::VisitDoExpression(DoExpression* expr) { | 1647 void AstGraphBuilder::VisitDoExpression(DoExpression* expr) { |
1763 VisitBlock(expr->block()); | 1648 VisitBlock(expr->block()); |
1764 VisitVariableProxy(expr->result()); | 1649 VisitVariableProxy(expr->result()); |
1765 ast_context()->ReplaceValue(expr); | 1650 ast_context()->ReplaceValue(expr); |
1766 } | 1651 } |
(...skipping 2649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4416 // Phi does not exist yet, introduce one. | 4301 // Phi does not exist yet, introduce one. |
4417 value = NewPhi(inputs, value, control); | 4302 value = NewPhi(inputs, value, control); |
4418 value->ReplaceInput(inputs - 1, other); | 4303 value->ReplaceInput(inputs - 1, other); |
4419 } | 4304 } |
4420 return value; | 4305 return value; |
4421 } | 4306 } |
4422 | 4307 |
4423 } // namespace compiler | 4308 } // namespace compiler |
4424 } // namespace internal | 4309 } // namespace internal |
4425 } // namespace v8 | 4310 } // namespace v8 |
OLD | NEW |