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

Side by Side Diff: src/ast.h

Issue 1135493006: Revert of [strong] Object literals create strong objects (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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 | « include/v8.h ('k') | src/bootstrapper.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 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } 1288 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; }
1289 1289
1290 int literal_index() { return literal_index_; } 1290 int literal_index() { return literal_index_; }
1291 1291
1292 int depth() const { 1292 int depth() const {
1293 // only callable after initialization. 1293 // only callable after initialization.
1294 DCHECK(depth_ >= 1); 1294 DCHECK(depth_ >= 1);
1295 return depth_; 1295 return depth_;
1296 } 1296 }
1297 1297
1298 bool is_strong() const { return is_strong_; }
1299
1300 protected: 1298 protected:
1301 MaterializedLiteral(Zone* zone, int literal_index, bool is_strong, int pos) 1299 MaterializedLiteral(Zone* zone, int literal_index, int pos)
1302 : Expression(zone, pos), 1300 : Expression(zone, pos),
1303 literal_index_(literal_index), 1301 literal_index_(literal_index),
1304 is_simple_(false), 1302 is_simple_(false),
1305 is_strong_(is_strong),
1306 depth_(0) {} 1303 depth_(0) {}
1307 1304
1308 // A materialized literal is simple if the values consist of only 1305 // A materialized literal is simple if the values consist of only
1309 // constants and simple object and array literals. 1306 // constants and simple object and array literals.
1310 bool is_simple() const { return is_simple_; } 1307 bool is_simple() const { return is_simple_; }
1311 void set_is_simple(bool is_simple) { is_simple_ = is_simple; } 1308 void set_is_simple(bool is_simple) { is_simple_ = is_simple; }
1312 friend class CompileTimeValue; 1309 friend class CompileTimeValue;
1313 1310
1314 void set_depth(int depth) { 1311 void set_depth(int depth) {
1315 DCHECK(depth >= 1); 1312 DCHECK(depth >= 1);
1316 depth_ = depth; 1313 depth_ = depth;
1317 } 1314 }
1318 1315
1319 // Populate the constant properties/elements fixed array. 1316 // Populate the constant properties/elements fixed array.
1320 void BuildConstants(Isolate* isolate); 1317 void BuildConstants(Isolate* isolate);
1321 friend class ArrayLiteral; 1318 friend class ArrayLiteral;
1322 friend class ObjectLiteral; 1319 friend class ObjectLiteral;
1323 1320
1324 // If the expression is a literal, return the literal value; 1321 // If the expression is a literal, return the literal value;
1325 // if the expression is a materialized literal and is simple return a 1322 // if the expression is a materialized literal and is simple return a
1326 // compile time value as encoded by CompileTimeValue::GetValue(). 1323 // compile time value as encoded by CompileTimeValue::GetValue().
1327 // Otherwise, return undefined literal as the placeholder 1324 // Otherwise, return undefined literal as the placeholder
1328 // in the object literal boilerplate. 1325 // in the object literal boilerplate.
1329 Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate); 1326 Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate);
1330 1327
1331 private: 1328 private:
1332 int literal_index_; 1329 int literal_index_;
1333 bool is_simple_; 1330 bool is_simple_;
1334 bool is_strong_;
1335 int depth_; 1331 int depth_;
1336 }; 1332 };
1337 1333
1338 1334
1339 // Property is used for passing information 1335 // Property is used for passing information
1340 // about an object literal's properties from the parser 1336 // about an object literal's properties from the parser
1341 // to the code generator. 1337 // to the code generator.
1342 class ObjectLiteralProperty final : public ZoneObject { 1338 class ObjectLiteralProperty final : public ZoneObject {
1343 public: 1339 public:
1344 enum Kind { 1340 enum Kind {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 // Assemble bitfield of flags for the CreateObjectLiteral helper. 1415 // Assemble bitfield of flags for the CreateObjectLiteral helper.
1420 int ComputeFlags(bool disable_mementos = false) const { 1416 int ComputeFlags(bool disable_mementos = false) const {
1421 int flags = fast_elements() ? kFastElements : kNoFlags; 1417 int flags = fast_elements() ? kFastElements : kNoFlags;
1422 flags |= has_function() ? kHasFunction : kNoFlags; 1418 flags |= has_function() ? kHasFunction : kNoFlags;
1423 if (depth() == 1 && !has_elements() && !may_store_doubles()) { 1419 if (depth() == 1 && !has_elements() && !may_store_doubles()) {
1424 flags |= kShallowProperties; 1420 flags |= kShallowProperties;
1425 } 1421 }
1426 if (disable_mementos) { 1422 if (disable_mementos) {
1427 flags |= kDisableMementos; 1423 flags |= kDisableMementos;
1428 } 1424 }
1429 if (is_strong()) {
1430 flags |= kIsStrong;
1431 }
1432 return flags; 1425 return flags;
1433 } 1426 }
1434 1427
1435 enum Flags { 1428 enum Flags {
1436 kNoFlags = 0, 1429 kNoFlags = 0,
1437 kFastElements = 1, 1430 kFastElements = 1,
1438 kHasFunction = 1 << 1, 1431 kHasFunction = 1 << 1,
1439 kShallowProperties = 1 << 2, 1432 kShallowProperties = 1 << 2,
1440 kDisableMementos = 1 << 3, 1433 kDisableMementos = 1 << 3
1441 kIsStrong = 1 << 4
1442 }; 1434 };
1443 1435
1444 struct Accessors: public ZoneObject { 1436 struct Accessors: public ZoneObject {
1445 Accessors() : getter(NULL), setter(NULL) {} 1437 Accessors() : getter(NULL), setter(NULL) {}
1446 Expression* getter; 1438 Expression* getter;
1447 Expression* setter; 1439 Expression* setter;
1448 }; 1440 };
1449 1441
1450 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } 1442 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); }
1451 1443
1452 // Return an AST id for a property that is used in simulate instructions. 1444 // Return an AST id for a property that is used in simulate instructions.
1453 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 1)); } 1445 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 1)); }
1454 1446
1455 // Unlike other AST nodes, this number of bailout IDs allocated for an 1447 // Unlike other AST nodes, this number of bailout IDs allocated for an
1456 // ObjectLiteral can vary, so num_ids() is not a static method. 1448 // ObjectLiteral can vary, so num_ids() is not a static method.
1457 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); } 1449 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); }
1458 1450
1459 protected: 1451 protected:
1460 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index, 1452 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index,
1461 int boilerplate_properties, bool has_function, 1453 int boilerplate_properties, bool has_function, int pos)
1462 bool is_strong, int pos) 1454 : MaterializedLiteral(zone, literal_index, pos),
1463 : MaterializedLiteral(zone, literal_index, is_strong, pos),
1464 properties_(properties), 1455 properties_(properties),
1465 boilerplate_properties_(boilerplate_properties), 1456 boilerplate_properties_(boilerplate_properties),
1466 fast_elements_(false), 1457 fast_elements_(false),
1467 has_elements_(false), 1458 has_elements_(false),
1468 may_store_doubles_(false), 1459 may_store_doubles_(false),
1469 has_function_(has_function) {} 1460 has_function_(has_function) {}
1470 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } 1461 static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1471 1462
1472 private: 1463 private:
1473 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1464 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
(...skipping 10 matching lines...) Expand all
1484 // Node for capturing a regexp literal. 1475 // Node for capturing a regexp literal.
1485 class RegExpLiteral final : public MaterializedLiteral { 1476 class RegExpLiteral final : public MaterializedLiteral {
1486 public: 1477 public:
1487 DECLARE_NODE_TYPE(RegExpLiteral) 1478 DECLARE_NODE_TYPE(RegExpLiteral)
1488 1479
1489 Handle<String> pattern() const { return pattern_->string(); } 1480 Handle<String> pattern() const { return pattern_->string(); }
1490 Handle<String> flags() const { return flags_->string(); } 1481 Handle<String> flags() const { return flags_->string(); }
1491 1482
1492 protected: 1483 protected:
1493 RegExpLiteral(Zone* zone, const AstRawString* pattern, 1484 RegExpLiteral(Zone* zone, const AstRawString* pattern,
1494 const AstRawString* flags, int literal_index, bool is_strong, 1485 const AstRawString* flags, int literal_index, int pos)
1495 int pos) 1486 : MaterializedLiteral(zone, literal_index, pos),
1496 : MaterializedLiteral(zone, literal_index, is_strong, pos),
1497 pattern_(pattern), 1487 pattern_(pattern),
1498 flags_(flags) { 1488 flags_(flags) {
1499 set_depth(1); 1489 set_depth(1);
1500 } 1490 }
1501 1491
1502 private: 1492 private:
1503 const AstRawString* pattern_; 1493 const AstRawString* pattern_;
1504 const AstRawString* flags_; 1494 const AstRawString* flags_;
1505 }; 1495 };
1506 1496
(...skipping 24 matching lines...) Expand all
1531 1521
1532 // Populate the constant elements fixed array. 1522 // Populate the constant elements fixed array.
1533 void BuildConstantElements(Isolate* isolate); 1523 void BuildConstantElements(Isolate* isolate);
1534 1524
1535 // Assemble bitfield of flags for the CreateArrayLiteral helper. 1525 // Assemble bitfield of flags for the CreateArrayLiteral helper.
1536 int ComputeFlags(bool disable_mementos = false) const { 1526 int ComputeFlags(bool disable_mementos = false) const {
1537 int flags = depth() == 1 ? kShallowElements : kNoFlags; 1527 int flags = depth() == 1 ? kShallowElements : kNoFlags;
1538 if (disable_mementos) { 1528 if (disable_mementos) {
1539 flags |= kDisableMementos; 1529 flags |= kDisableMementos;
1540 } 1530 }
1541 if (is_strong()) {
1542 flags |= kIsStrong;
1543 }
1544 return flags; 1531 return flags;
1545 } 1532 }
1546 1533
1547 enum Flags { 1534 enum Flags {
1548 kNoFlags = 0, 1535 kNoFlags = 0,
1549 kShallowElements = 1, 1536 kShallowElements = 1,
1550 kDisableMementos = 1 << 1, 1537 kDisableMementos = 1 << 1
1551 kIsStrong = 1 << 2
1552 }; 1538 };
1553 1539
1554 protected: 1540 protected:
1555 ArrayLiteral(Zone* zone, ZoneList<Expression*>* values, int literal_index, 1541 ArrayLiteral(Zone* zone, ZoneList<Expression*>* values, int literal_index,
1556 bool is_strong, int pos) 1542 int pos)
1557 : MaterializedLiteral(zone, literal_index, is_strong, pos), 1543 : MaterializedLiteral(zone, literal_index, pos), values_(values) {}
1558 values_(values) {}
1559 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } 1544 static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1560 1545
1561 private: 1546 private:
1562 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1547 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1563 1548
1564 Handle<FixedArray> constant_elements_; 1549 Handle<FixedArray> constant_elements_;
1565 ZoneList<Expression*>* values_; 1550 ZoneList<Expression*>* values_;
1566 }; 1551 };
1567 1552
1568 1553
(...skipping 1748 matching lines...) Expand 10 before | Expand all | Expand 10 after
3317 3302
3318 Literal* NewTheHoleLiteral(int pos) { 3303 Literal* NewTheHoleLiteral(int pos) {
3319 return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos); 3304 return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos);
3320 } 3305 }
3321 3306
3322 ObjectLiteral* NewObjectLiteral( 3307 ObjectLiteral* NewObjectLiteral(
3323 ZoneList<ObjectLiteral::Property*>* properties, 3308 ZoneList<ObjectLiteral::Property*>* properties,
3324 int literal_index, 3309 int literal_index,
3325 int boilerplate_properties, 3310 int boilerplate_properties,
3326 bool has_function, 3311 bool has_function,
3327 bool is_strong,
3328 int pos) { 3312 int pos) {
3329 return new (zone_) ObjectLiteral(zone_, properties, literal_index, 3313 return new (zone_) ObjectLiteral(zone_, properties, literal_index,
3330 boilerplate_properties, has_function, 3314 boilerplate_properties, has_function, pos);
3331 is_strong, pos);
3332 } 3315 }
3333 3316
3334 ObjectLiteral::Property* NewObjectLiteralProperty( 3317 ObjectLiteral::Property* NewObjectLiteralProperty(
3335 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, 3318 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind,
3336 bool is_static, bool is_computed_name) { 3319 bool is_static, bool is_computed_name) {
3337 return new (zone_) 3320 return new (zone_)
3338 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name); 3321 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name);
3339 } 3322 }
3340 3323
3341 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, 3324 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key,
3342 Expression* value, 3325 Expression* value,
3343 bool is_static, 3326 bool is_static,
3344 bool is_computed_name) { 3327 bool is_computed_name) {
3345 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value, 3328 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value,
3346 is_static, is_computed_name); 3329 is_static, is_computed_name);
3347 } 3330 }
3348 3331
3349 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, 3332 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern,
3350 const AstRawString* flags, 3333 const AstRawString* flags,
3351 int literal_index, 3334 int literal_index,
3352 bool is_strong,
3353 int pos) { 3335 int pos) {
3354 return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index, 3336 return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos);
3355 is_strong, pos);
3356 } 3337 }
3357 3338
3358 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, 3339 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values,
3359 int literal_index, 3340 int literal_index,
3360 bool is_strong,
3361 int pos) { 3341 int pos) {
3362 return new (zone_) ArrayLiteral(zone_, values, literal_index, is_strong, 3342 return new (zone_) ArrayLiteral(zone_, values, literal_index, pos);
3363 pos);
3364 } 3343 }
3365 3344
3366 VariableProxy* NewVariableProxy(Variable* var, 3345 VariableProxy* NewVariableProxy(Variable* var,
3367 int start_position = RelocInfo::kNoPosition, 3346 int start_position = RelocInfo::kNoPosition,
3368 int end_position = RelocInfo::kNoPosition) { 3347 int end_position = RelocInfo::kNoPosition) {
3369 return new (zone_) VariableProxy(zone_, var, start_position, end_position); 3348 return new (zone_) VariableProxy(zone_, var, start_position, end_position);
3370 } 3349 }
3371 3350
3372 VariableProxy* NewVariableProxy(const AstRawString* name, 3351 VariableProxy* NewVariableProxy(const AstRawString* name,
3373 Variable::Kind variable_kind, 3352 Variable::Kind variable_kind,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
3508 3487
3509 private: 3488 private:
3510 Zone* zone_; 3489 Zone* zone_;
3511 AstValueFactory* ast_value_factory_; 3490 AstValueFactory* ast_value_factory_;
3512 }; 3491 };
3513 3492
3514 3493
3515 } } // namespace v8::internal 3494 } } // namespace v8::internal
3516 3495
3517 #endif // V8_AST_H_ 3496 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698