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

Side by Side Diff: src/ast/ast.h

Issue 2445333002: Ensure slow properties for simple {__proto__:null} literals. (Closed)
Patch Set: fixing typo Created 3 years, 9 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/ast/ast.cc » ('j') | src/ast/ast.cc » ('J')
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_AST_H_ 5 #ifndef V8_AST_AST_H_
6 #define V8_AST_AST_H_ 6 #define V8_AST_AST_H_
7 7
8 #include "src/ast/ast-types.h" 8 #include "src/ast/ast-types.h"
9 #include "src/ast/ast-value-factory.h" 9 #include "src/ast/ast-value-factory.h"
10 #include "src/ast/modules.h" 10 #include "src/ast/modules.h"
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 : Expression(pos, type), depth_(0) { 1257 : Expression(pos, type), depth_(0) {
1258 bit_field_ |= IsSimpleField::encode(false); 1258 bit_field_ |= IsSimpleField::encode(false);
1259 } 1259 }
1260 1260
1261 // A materialized literal is simple if the values consist of only 1261 // A materialized literal is simple if the values consist of only
1262 // constants and simple object and array literals. 1262 // constants and simple object and array literals.
1263 bool is_simple() const { return IsSimpleField::decode(bit_field_); } 1263 bool is_simple() const { return IsSimpleField::decode(bit_field_); }
1264 void set_is_simple(bool is_simple) { 1264 void set_is_simple(bool is_simple) {
1265 bit_field_ = IsSimpleField::update(bit_field_, is_simple); 1265 bit_field_ = IsSimpleField::update(bit_field_, is_simple);
1266 } 1266 }
1267
1267 friend class CompileTimeValue; 1268 friend class CompileTimeValue;
1268 1269
1269 void set_depth(int depth) { 1270 void set_depth(int depth) {
1270 DCHECK_LE(1, depth); 1271 DCHECK_LE(1, depth);
1271 depth_ = depth; 1272 depth_ = depth;
1272 } 1273 }
1273 1274
1274 // Populate the depth field and any flags the literal has. 1275 // Populate the depth field and any flags the literal has.
1275 void InitDepthAndFlags(); 1276 void InitDepthAndFlags();
1276 1277
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 bool IsMonomorphic() const { return !receiver_type_.is_null(); } 1347 bool IsMonomorphic() const { return !receiver_type_.is_null(); }
1347 Handle<Map> GetReceiverType() const { return receiver_type_; } 1348 Handle<Map> GetReceiverType() const { return receiver_type_; }
1348 1349
1349 bool IsCompileTimeValue() const; 1350 bool IsCompileTimeValue() const;
1350 1351
1351 void set_emit_store(bool emit_store); 1352 void set_emit_store(bool emit_store);
1352 bool emit_store() const; 1353 bool emit_store() const;
1353 1354
1354 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; } 1355 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; }
1355 1356
1357 bool IsNullPrototype() const {
1358 return IsPrototype() && value()->IsNullLiteral();
1359 }
1360 bool IsPrototype() const { return kind() == PROTOTYPE; }
1361
1356 private: 1362 private:
1357 friend class AstNodeFactory; 1363 friend class AstNodeFactory;
1358 1364
1359 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind, 1365 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind,
1360 bool is_computed_name); 1366 bool is_computed_name);
1361 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key, 1367 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key,
1362 Expression* value, bool is_computed_name); 1368 Expression* value, bool is_computed_name);
1363 1369
1364 Kind kind_; 1370 Kind kind_;
1365 bool emit_store_; 1371 bool emit_store_;
(...skipping 17 matching lines...) Expand all
1383 bool may_store_doubles() const { 1389 bool may_store_doubles() const {
1384 return MayStoreDoublesField::decode(bit_field_); 1390 return MayStoreDoublesField::decode(bit_field_);
1385 } 1391 }
1386 bool has_elements() const { return HasElementsField::decode(bit_field_); } 1392 bool has_elements() const { return HasElementsField::decode(bit_field_); }
1387 bool has_shallow_properties() const { 1393 bool has_shallow_properties() const {
1388 return depth() == 1 && !has_elements() && !may_store_doubles(); 1394 return depth() == 1 && !has_elements() && !may_store_doubles();
1389 } 1395 }
1390 bool has_rest_property() const { 1396 bool has_rest_property() const {
1391 return HasRestPropertyField::decode(bit_field_); 1397 return HasRestPropertyField::decode(bit_field_);
1392 } 1398 }
1393 1399 bool has_null_prototype() const {
1400 return HasNullPrototypeField::decode(bit_field_);
1401 }
1394 // Decide if a property should be in the object boilerplate. 1402 // Decide if a property should be in the object boilerplate.
1395 static bool IsBoilerplateProperty(Property* property); 1403 static bool IsBoilerplateProperty(Property* property);
1396 1404
1397 // Populate the depth field and flags. 1405 // Populate the depth field and flags.
1398 void InitDepthAndFlags(); 1406 void InitDepthAndFlags();
1399 1407
1400 // Get the constant properties fixed array, populating it if necessary. 1408 // Get the constant properties fixed array, populating it if necessary.
1401 Handle<BoilerplateDescription> GetOrBuildConstantProperties( 1409 Handle<BoilerplateDescription> GetOrBuildConstantProperties(
1402 Isolate* isolate) { 1410 Isolate* isolate) {
1403 if (constant_properties_.is_null()) { 1411 if (constant_properties_.is_null()) {
1404 BuildConstantProperties(isolate); 1412 BuildConstantProperties(isolate);
1405 } 1413 }
1406 return constant_properties(); 1414 return constant_properties();
1407 } 1415 }
1408 1416
1409 // Populate the constant properties fixed array. 1417 // Populate the constant properties fixed array.
1410 void BuildConstantProperties(Isolate* isolate); 1418 void BuildConstantProperties(Isolate* isolate);
1411 1419
1412 // Mark all computed expressions that are bound to a key that 1420 // Mark all computed expressions that are bound to a key that
1413 // is shadowed by a later occurrence of the same key. For the 1421 // is shadowed by a later occurrence of the same key. For the
1414 // marked expressions, no store code is emitted. 1422 // marked expressions, no store code is emitted.
1415 void CalculateEmitStore(Zone* zone); 1423 void CalculateEmitStore(Zone* zone);
1416 1424
1417 // Determines whether the {FastCloneShallowObject} builtin can be used. 1425 // Determines whether the {FastCloneShallowObject} builtin can be used.
1418 bool IsFastCloningSupported() const; 1426 bool IsFastCloningSupported() const;
1419 1427
1420 // Assemble bitfield of flags for the CreateObjectLiteral helper. 1428 // Assemble bitfield of flags for the CreateObjectLiteral helper.
1421 int ComputeFlags(bool disable_mementos = false) const { 1429 int ComputeFlags(bool disable_mementos = false) const {
1422 int flags = fast_elements() ? kFastElements : kNoFlags; 1430 int flags = fast_elements() ? kFastElements : kNoFlags;
1423 if (has_shallow_properties()) { 1431 if (has_shallow_properties()) flags |= kShallowProperties;
1424 flags |= kShallowProperties; 1432 if (disable_mementos) flags |= kDisableMementos;
1425 } 1433 if (has_null_prototype()) flags |= kHasNullPrototype;
1426 if (disable_mementos) {
1427 flags |= kDisableMementos;
1428 }
1429 return flags; 1434 return flags;
1430 } 1435 }
1431 1436
1432 enum Flags { 1437 enum Flags {
1433 kNoFlags = 0, 1438 kNoFlags = 0,
1434 kFastElements = 1, 1439 kFastElements = 1,
1435 kShallowProperties = 1 << 1, 1440 kShallowProperties = 1 << 1,
1436 kDisableMementos = 1 << 2, 1441 kDisableMementos = 1 << 2,
1437 kHasRestProperty = 1 << 3, 1442 kHasNullPrototype = 1 << 3,
1438 }; 1443 };
1439 1444
1440 struct Accessors: public ZoneObject { 1445 struct Accessors: public ZoneObject {
1441 Accessors() : getter(NULL), setter(NULL), bailout_id(BailoutId::None()) {} 1446 Accessors() : getter(NULL), setter(NULL), bailout_id(BailoutId::None()) {}
1442 ObjectLiteralProperty* getter; 1447 ObjectLiteralProperty* getter;
1443 ObjectLiteralProperty* setter; 1448 ObjectLiteralProperty* setter;
1444 BailoutId bailout_id; 1449 BailoutId bailout_id;
1445 }; 1450 };
1446 1451
1447 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } 1452 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); }
(...skipping 15 matching lines...) Expand all
1463 1468
1464 ObjectLiteral(ZoneList<Property*>* properties, 1469 ObjectLiteral(ZoneList<Property*>* properties,
1465 uint32_t boilerplate_properties, int pos, 1470 uint32_t boilerplate_properties, int pos,
1466 bool has_rest_property) 1471 bool has_rest_property)
1467 : MaterializedLiteral(pos, kObjectLiteral), 1472 : MaterializedLiteral(pos, kObjectLiteral),
1468 boilerplate_properties_(boilerplate_properties), 1473 boilerplate_properties_(boilerplate_properties),
1469 properties_(properties) { 1474 properties_(properties) {
1470 bit_field_ |= FastElementsField::encode(false) | 1475 bit_field_ |= FastElementsField::encode(false) |
1471 HasElementsField::encode(false) | 1476 HasElementsField::encode(false) |
1472 MayStoreDoublesField::encode(false) | 1477 MayStoreDoublesField::encode(false) |
1473 HasRestPropertyField::encode(has_rest_property); 1478 HasRestPropertyField::encode(has_rest_property) |
1479 HasNullPrototypeField::encode(false);
1474 } 1480 }
1475 1481
1476 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } 1482 static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1477 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1483 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1478 1484
1485 void set_fast_elements(bool fast_elements) {
1486 bit_field_ = FastElementsField::update(bit_field_, fast_elements);
1487 }
1488 void set_has_elements(bool has_elements) {
1489 bit_field_ = HasElementsField::update(bit_field_, has_elements);
1490 }
1491 void set_has_null_protoype(bool has_null_prototype) {
1492 bit_field_ = HasNullPrototypeField::update(bit_field_, has_null_prototype);
1493 }
1494
1479 uint32_t boilerplate_properties_; 1495 uint32_t boilerplate_properties_;
1480 Handle<BoilerplateDescription> constant_properties_; 1496 Handle<BoilerplateDescription> constant_properties_;
1481 ZoneList<Property*>* properties_; 1497 ZoneList<Property*>* properties_;
1482 1498
1483 class FastElementsField 1499 class FastElementsField
1484 : public BitField<bool, MaterializedLiteral::kNextBitFieldIndex, 1> {}; 1500 : public BitField<bool, MaterializedLiteral::kNextBitFieldIndex, 1> {};
1485 class HasElementsField : public BitField<bool, FastElementsField::kNext, 1> { 1501 class HasElementsField : public BitField<bool, FastElementsField::kNext, 1> {
1486 }; 1502 };
1487 class MayStoreDoublesField 1503 class MayStoreDoublesField
1488 : public BitField<bool, HasElementsField::kNext, 1> {}; 1504 : public BitField<bool, HasElementsField::kNext, 1> {};
1489 class HasRestPropertyField 1505 class HasRestPropertyField
1490 : public BitField<bool, MayStoreDoublesField::kNext, 1> {}; 1506 : public BitField<bool, MayStoreDoublesField::kNext, 1> {};
1507 class HasNullPrototypeField
1508 : public BitField<bool, HasRestPropertyField::kNext, 1> {};
1491 }; 1509 };
1492 1510
1493 1511
1494 // A map from property names to getter/setter pairs allocated in the zone. 1512 // A map from property names to getter/setter pairs allocated in the zone.
1495 class AccessorTable 1513 class AccessorTable
1496 : public base::TemplateHashMap<Literal, ObjectLiteral::Accessors, 1514 : public base::TemplateHashMap<Literal, ObjectLiteral::Accessors,
1497 bool (*)(void*, void*), 1515 bool (*)(void*, void*),
1498 ZoneAllocationPolicy> { 1516 ZoneAllocationPolicy> {
1499 public: 1517 public:
1500 explicit AccessorTable(Zone* zone) 1518 explicit AccessorTable(Zone* zone)
(...skipping 2146 matching lines...) Expand 10 before | Expand all | Expand 10 after
3647 : NULL; \ 3665 : NULL; \
3648 } 3666 }
3649 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 3667 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3650 #undef DECLARE_NODE_FUNCTIONS 3668 #undef DECLARE_NODE_FUNCTIONS
3651 3669
3652 3670
3653 } // namespace internal 3671 } // namespace internal
3654 } // namespace v8 3672 } // namespace v8
3655 3673
3656 #endif // V8_AST_AST_H_ 3674 #endif // V8_AST_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast/ast.cc » ('j') | src/ast/ast.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698