| 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 1576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1587 CHECK(!shared_info.is_null()); // TODO(mstarzinger): Set stack overflow? | 1587 CHECK(!shared_info.is_null()); // TODO(mstarzinger): Set stack overflow? |
| 1588 | 1588 |
| 1589 // Create node to instantiate a new closure. | 1589 // Create node to instantiate a new closure. |
| 1590 PretenureFlag pretenure = expr->pretenure() ? TENURED : NOT_TENURED; | 1590 PretenureFlag pretenure = expr->pretenure() ? TENURED : NOT_TENURED; |
| 1591 const Operator* op = javascript()->CreateClosure(shared_info, pretenure); | 1591 const Operator* op = javascript()->CreateClosure(shared_info, pretenure); |
| 1592 Node* value = NewNode(op); | 1592 Node* value = NewNode(op); |
| 1593 ast_context()->ProduceValue(expr, value); | 1593 ast_context()->ProduceValue(expr, value); |
| 1594 } | 1594 } |
| 1595 | 1595 |
| 1596 | 1596 |
| 1597 void AstGraphBuilder::VisitClassLiteral(ClassLiteral* expr) { | |
| 1598 // Visit declarations and class literal in a block scope. | |
| 1599 if (expr->scope()->ContextLocalCount() > 0) { | |
| 1600 Node* context = BuildLocalBlockContext(expr->scope()); | |
| 1601 ContextScope scope(this, expr->scope(), context); | |
| 1602 VisitDeclarations(expr->scope()->declarations()); | |
| 1603 VisitClassLiteralContents(expr); | |
| 1604 } else { | |
| 1605 VisitDeclarations(expr->scope()->declarations()); | |
| 1606 VisitClassLiteralContents(expr); | |
| 1607 } | |
| 1608 } | |
| 1609 | |
| 1610 | |
| 1611 void AstGraphBuilder::VisitClassLiteralContents(ClassLiteral* expr) { | |
| 1612 VisitForValueOrTheHole(expr->extends()); | |
| 1613 VisitForValue(expr->constructor()); | |
| 1614 | |
| 1615 // Create node to instantiate a new class. | |
| 1616 Node* constructor = environment()->Pop(); | |
| 1617 Node* extends = environment()->Pop(); | |
| 1618 Node* start = jsgraph()->Constant(expr->start_position()); | |
| 1619 Node* end = jsgraph()->Constant(expr->end_position()); | |
| 1620 const Operator* opc = javascript()->CallRuntime(Runtime::kDefineClass); | |
| 1621 Node* literal = NewNode(opc, extends, constructor, start, end); | |
| 1622 PrepareFrameState(literal, expr->CreateLiteralId(), | |
| 1623 OutputFrameStateCombine::Push()); | |
| 1624 environment()->Push(literal); | |
| 1625 | |
| 1626 // Load the "prototype" from the constructor. | |
| 1627 PrepareEagerCheckpoint(expr->CreateLiteralId()); | |
| 1628 Handle<Name> name = isolate()->factory()->prototype_string(); | |
| 1629 VectorSlotPair pair = CreateVectorSlotPair(expr->PrototypeSlot()); | |
| 1630 Node* prototype = BuildNamedLoad(literal, name, pair); | |
| 1631 PrepareFrameState(prototype, expr->PrototypeId(), | |
| 1632 OutputFrameStateCombine::Push()); | |
| 1633 environment()->Push(prototype); | |
| 1634 | |
| 1635 // Create nodes to store method values into the literal. | |
| 1636 for (int i = 0; i < expr->properties()->length(); i++) { | |
| 1637 ObjectLiteral::Property* property = expr->properties()->at(i); | |
| 1638 environment()->Push(environment()->Peek(property->is_static() ? 1 : 0)); | |
| 1639 | |
| 1640 VisitForValue(property->key()); | |
| 1641 Node* name = BuildToName(environment()->Pop(), expr->GetIdForProperty(i)); | |
| 1642 environment()->Push(name); | |
| 1643 | |
| 1644 // The static prototype property is read only. We handle the non computed | |
| 1645 // property name case in the parser. Since this is the only case where we | |
| 1646 // need to check for an own read only property we special case this so we do | |
| 1647 // not need to do this for every property. | |
| 1648 if (property->is_static() && property->is_computed_name()) { | |
| 1649 Node* check = BuildThrowIfStaticPrototype(environment()->Pop(), | |
| 1650 expr->GetIdForProperty(i)); | |
| 1651 environment()->Push(check); | |
| 1652 } | |
| 1653 | |
| 1654 VisitForValue(property->value()); | |
| 1655 Node* value = environment()->Pop(); | |
| 1656 Node* key = environment()->Pop(); | |
| 1657 Node* receiver = environment()->Pop(); | |
| 1658 | |
| 1659 BuildSetHomeObject(value, receiver, property); | |
| 1660 | |
| 1661 switch (property->kind()) { | |
| 1662 case ObjectLiteral::Property::CONSTANT: | |
| 1663 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | |
| 1664 case ObjectLiteral::Property::PROTOTYPE: | |
| 1665 UNREACHABLE(); | |
| 1666 case ObjectLiteral::Property::COMPUTED: { | |
| 1667 Node* attr = jsgraph()->Constant(DONT_ENUM); | |
| 1668 Node* set_function_name = | |
| 1669 jsgraph()->Constant(property->NeedsSetFunctionName()); | |
| 1670 const Operator* op = | |
| 1671 javascript()->CallRuntime(Runtime::kDefineDataPropertyInLiteral); | |
| 1672 Node* call = NewNode(op, receiver, key, value, attr, set_function_name); | |
| 1673 PrepareFrameState(call, BailoutId::None()); | |
| 1674 break; | |
| 1675 } | |
| 1676 case ObjectLiteral::Property::GETTER: { | |
| 1677 Node* attr = jsgraph()->Constant(DONT_ENUM); | |
| 1678 const Operator* op = javascript()->CallRuntime( | |
| 1679 Runtime::kDefineGetterPropertyUnchecked, 4); | |
| 1680 NewNode(op, receiver, key, value, attr); | |
| 1681 break; | |
| 1682 } | |
| 1683 case ObjectLiteral::Property::SETTER: { | |
| 1684 Node* attr = jsgraph()->Constant(DONT_ENUM); | |
| 1685 const Operator* op = javascript()->CallRuntime( | |
| 1686 Runtime::kDefineSetterPropertyUnchecked, 4); | |
| 1687 NewNode(op, receiver, key, value, attr); | |
| 1688 break; | |
| 1689 } | |
| 1690 } | |
| 1691 } | |
| 1692 | |
| 1693 // Set the constructor to have fast properties. | |
| 1694 prototype = environment()->Pop(); | |
| 1695 literal = environment()->Pop(); | |
| 1696 const Operator* op = javascript()->CallRuntime(Runtime::kToFastProperties); | |
| 1697 literal = NewNode(op, literal); | |
| 1698 | |
| 1699 // Assign to class variable. | |
| 1700 if (expr->class_variable_proxy() != nullptr) { | |
| 1701 Variable* var = expr->class_variable_proxy()->var(); | |
| 1702 VectorSlotPair feedback = CreateVectorSlotPair( | |
| 1703 expr->NeedsProxySlot() ? expr->ProxySlot() | |
| 1704 : FeedbackVectorSlot::Invalid()); | |
| 1705 BuildVariableAssignment(var, literal, Token::INIT, feedback, | |
| 1706 BailoutId::None()); | |
| 1707 } | |
| 1708 ast_context()->ProduceValue(expr, literal); | |
| 1709 } | |
| 1710 | |
| 1711 | |
| 1712 void AstGraphBuilder::VisitNativeFunctionLiteral(NativeFunctionLiteral* expr) { | 1597 void AstGraphBuilder::VisitNativeFunctionLiteral(NativeFunctionLiteral* expr) { |
| 1713 UNREACHABLE(); | 1598 UNREACHABLE(); |
| 1714 } | 1599 } |
| 1715 | 1600 |
| 1716 | 1601 |
| 1717 void AstGraphBuilder::VisitDoExpression(DoExpression* expr) { | 1602 void AstGraphBuilder::VisitDoExpression(DoExpression* expr) { |
| 1718 VisitBlock(expr->block()); | 1603 VisitBlock(expr->block()); |
| 1719 VisitVariableProxy(expr->result()); | 1604 VisitVariableProxy(expr->result()); |
| 1720 ast_context()->ReplaceValue(expr); | 1605 ast_context()->ReplaceValue(expr); |
| 1721 } | 1606 } |
| (...skipping 2647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4369 // Phi does not exist yet, introduce one. | 4254 // Phi does not exist yet, introduce one. |
| 4370 value = NewPhi(inputs, value, control); | 4255 value = NewPhi(inputs, value, control); |
| 4371 value->ReplaceInput(inputs - 1, other); | 4256 value->ReplaceInput(inputs - 1, other); |
| 4372 } | 4257 } |
| 4373 return value; | 4258 return value; |
| 4374 } | 4259 } |
| 4375 | 4260 |
| 4376 } // namespace compiler | 4261 } // namespace compiler |
| 4377 } // namespace internal | 4262 } // namespace internal |
| 4378 } // namespace v8 | 4263 } // namespace v8 |
| OLD | NEW |