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

Side by Side Diff: src/ast.h

Issue 1037273002: Ensure object literal element boilerplates aren't modified. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added comment and REBASE. Created 5 years, 8 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 | « src/arm64/full-codegen-arm64.cc ('k') | src/ast.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 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 #ifndef V8_AST_H_ 5 #ifndef V8_AST_H_
6 #define V8_AST_H_ 6 #define V8_AST_H_
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/assembler.h" 10 #include "src/assembler.h"
(...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 // for minimizing the work when constructing it at runtime. 1475 // for minimizing the work when constructing it at runtime.
1476 class ObjectLiteral FINAL : public MaterializedLiteral { 1476 class ObjectLiteral FINAL : public MaterializedLiteral {
1477 public: 1477 public:
1478 typedef ObjectLiteralProperty Property; 1478 typedef ObjectLiteralProperty Property;
1479 1479
1480 DECLARE_NODE_TYPE(ObjectLiteral) 1480 DECLARE_NODE_TYPE(ObjectLiteral)
1481 1481
1482 Handle<FixedArray> constant_properties() const { 1482 Handle<FixedArray> constant_properties() const {
1483 return constant_properties_; 1483 return constant_properties_;
1484 } 1484 }
1485 int properties_count() const { return constant_properties_->length() / 2; }
1485 ZoneList<Property*>* properties() const { return properties_; } 1486 ZoneList<Property*>* properties() const { return properties_; }
1486 bool fast_elements() const { return fast_elements_; } 1487 bool fast_elements() const { return fast_elements_; }
1487 bool may_store_doubles() const { return may_store_doubles_; } 1488 bool may_store_doubles() const { return may_store_doubles_; }
1488 bool has_function() const { return has_function_; } 1489 bool has_function() const { return has_function_; }
1490 bool has_elements() const { return has_elements_; }
1489 1491
1490 // Decide if a property should be in the object boilerplate. 1492 // Decide if a property should be in the object boilerplate.
1491 static bool IsBoilerplateProperty(Property* property); 1493 static bool IsBoilerplateProperty(Property* property);
1492 1494
1493 // Populate the constant properties fixed array. 1495 // Populate the constant properties fixed array.
1494 void BuildConstantProperties(Isolate* isolate); 1496 void BuildConstantProperties(Isolate* isolate);
1495 1497
1496 // Mark all computed expressions that are bound to a key that 1498 // Mark all computed expressions that are bound to a key that
1497 // is shadowed by a later occurrence of the same key. For the 1499 // is shadowed by a later occurrence of the same key. For the
1498 // marked expressions, no store code is emitted. 1500 // marked expressions, no store code is emitted.
1499 void CalculateEmitStore(Zone* zone); 1501 void CalculateEmitStore(Zone* zone);
1500 1502
1501 // Assemble bitfield of flags for the CreateObjectLiteral helper. 1503 // Assemble bitfield of flags for the CreateObjectLiteral helper.
1502 int ComputeFlags() const { 1504 int ComputeFlags(bool disable_mementos = false) const {
1503 int flags = fast_elements() ? kFastElements : kNoFlags; 1505 int flags = fast_elements() ? kFastElements : kNoFlags;
1504 flags |= has_function() ? kHasFunction : kNoFlags; 1506 flags |= has_function() ? kHasFunction : kNoFlags;
1507 if (disable_mementos) {
1508 flags |= kDisableMementos;
1509 }
1505 return flags; 1510 return flags;
1506 } 1511 }
1507 1512
1508 enum Flags { 1513 enum Flags {
1509 kNoFlags = 0, 1514 kNoFlags = 0,
1510 kFastElements = 1, 1515 kFastElements = 1,
1511 kHasFunction = 1 << 1 1516 kHasFunction = 1 << 1,
1517 kDisableMementos = 1 << 2
1512 }; 1518 };
1513 1519
1514 struct Accessors: public ZoneObject { 1520 struct Accessors: public ZoneObject {
1515 Accessors() : getter(NULL), setter(NULL) {} 1521 Accessors() : getter(NULL), setter(NULL) {}
1516 Expression* getter; 1522 Expression* getter;
1517 Expression* setter; 1523 Expression* setter;
1518 }; 1524 };
1519 1525
1520 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } 1526 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); }
1521 1527
1522 // Return an AST id for a property that is used in simulate instructions. 1528 // Return an AST id for a property that is used in simulate instructions.
1523 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 1)); } 1529 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 1)); }
1524 1530
1525 // Unlike other AST nodes, this number of bailout IDs allocated for an 1531 // Unlike other AST nodes, this number of bailout IDs allocated for an
1526 // ObjectLiteral can vary, so num_ids() is not a static method. 1532 // ObjectLiteral can vary, so num_ids() is not a static method.
1527 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); } 1533 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); }
1528 1534
1529 protected: 1535 protected:
1530 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index, 1536 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index,
1531 int boilerplate_properties, bool has_function, int pos) 1537 int boilerplate_properties, bool has_function, int pos)
1532 : MaterializedLiteral(zone, literal_index, pos), 1538 : MaterializedLiteral(zone, literal_index, pos),
1533 properties_(properties), 1539 properties_(properties),
1534 boilerplate_properties_(boilerplate_properties), 1540 boilerplate_properties_(boilerplate_properties),
1535 fast_elements_(false), 1541 fast_elements_(false),
1542 has_elements_(false),
1536 may_store_doubles_(false), 1543 may_store_doubles_(false),
1537 has_function_(has_function) {} 1544 has_function_(has_function) {}
1538 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } 1545 static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1539 1546
1540 private: 1547 private:
1541 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1548 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1542 Handle<FixedArray> constant_properties_; 1549 Handle<FixedArray> constant_properties_;
1543 ZoneList<Property*>* properties_; 1550 ZoneList<Property*>* properties_;
1544 int boilerplate_properties_; 1551 int boilerplate_properties_;
1545 bool fast_elements_; 1552 bool fast_elements_;
1553 bool has_elements_;
1546 bool may_store_doubles_; 1554 bool may_store_doubles_;
1547 bool has_function_; 1555 bool has_function_;
1548 }; 1556 };
1549 1557
1550 1558
1551 // Node for capturing a regexp literal. 1559 // Node for capturing a regexp literal.
1552 class RegExpLiteral FINAL : public MaterializedLiteral { 1560 class RegExpLiteral FINAL : public MaterializedLiteral {
1553 public: 1561 public:
1554 DECLARE_NODE_TYPE(RegExpLiteral) 1562 DECLARE_NODE_TYPE(RegExpLiteral)
1555 1563
(...skipping 15 matching lines...) Expand all
1571 }; 1579 };
1572 1580
1573 1581
1574 // An array literal has a literals object that is used 1582 // An array literal has a literals object that is used
1575 // for minimizing the work when constructing it at runtime. 1583 // for minimizing the work when constructing it at runtime.
1576 class ArrayLiteral FINAL : public MaterializedLiteral { 1584 class ArrayLiteral FINAL : public MaterializedLiteral {
1577 public: 1585 public:
1578 DECLARE_NODE_TYPE(ArrayLiteral) 1586 DECLARE_NODE_TYPE(ArrayLiteral)
1579 1587
1580 Handle<FixedArray> constant_elements() const { return constant_elements_; } 1588 Handle<FixedArray> constant_elements() const { return constant_elements_; }
1589 ElementsKind constant_elements_kind() const {
1590 DCHECK_EQ(2, constant_elements_->length());
1591 return static_cast<ElementsKind>(
1592 Smi::cast(constant_elements_->get(0))->value());
1593 }
1594
1581 ZoneList<Expression*>* values() const { return values_; } 1595 ZoneList<Expression*>* values() const { return values_; }
1582 1596
1583 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } 1597 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); }
1584 1598
1585 // Return an AST id for an element that is used in simulate instructions. 1599 // Return an AST id for an element that is used in simulate instructions.
1586 BailoutId GetIdForElement(int i) { return BailoutId(local_id(i + 1)); } 1600 BailoutId GetIdForElement(int i) { return BailoutId(local_id(i + 1)); }
1587 1601
1588 // Unlike other AST nodes, this number of bailout IDs allocated for an 1602 // Unlike other AST nodes, this number of bailout IDs allocated for an
1589 // ArrayLiteral can vary, so num_ids() is not a static method. 1603 // ArrayLiteral can vary, so num_ids() is not a static method.
1590 int num_ids() const { return parent_num_ids() + 1 + values()->length(); } 1604 int num_ids() const { return parent_num_ids() + 1 + values()->length(); }
1591 1605
1592 // Populate the constant elements fixed array. 1606 // Populate the constant elements fixed array.
1593 void BuildConstantElements(Isolate* isolate); 1607 void BuildConstantElements(Isolate* isolate);
1594 1608
1595 // Assemble bitfield of flags for the CreateArrayLiteral helper. 1609 // Assemble bitfield of flags for the CreateArrayLiteral helper.
1596 int ComputeFlags() const { 1610 int ComputeFlags(bool disable_mementos = false) const {
1597 int flags = depth() == 1 ? kShallowElements : kNoFlags; 1611 int flags = depth() == 1 ? kShallowElements : kNoFlags;
1598 flags |= ArrayLiteral::kDisableMementos; 1612 if (disable_mementos) {
1613 flags |= kDisableMementos;
1614 }
1599 return flags; 1615 return flags;
1600 } 1616 }
1601 1617
1602 enum Flags { 1618 enum Flags {
1603 kNoFlags = 0, 1619 kNoFlags = 0,
1604 kShallowElements = 1, 1620 kShallowElements = 1,
1605 kDisableMementos = 1 << 1 1621 kDisableMementos = 1 << 1
1606 }; 1622 };
1607 1623
1608 protected: 1624 protected:
(...skipping 1927 matching lines...) Expand 10 before | Expand all | Expand 10 after
3536 3552
3537 private: 3553 private:
3538 Zone* zone_; 3554 Zone* zone_;
3539 AstValueFactory* ast_value_factory_; 3555 AstValueFactory* ast_value_factory_;
3540 }; 3556 };
3541 3557
3542 3558
3543 } } // namespace v8::internal 3559 } } // namespace v8::internal
3544 3560
3545 #endif // V8_AST_H_ 3561 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « src/arm64/full-codegen-arm64.cc ('k') | src/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698