OLD | NEW |
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 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 bool IsMonomorphic() const { return !receiver_type_.is_null(); } | 1346 bool IsMonomorphic() const { return !receiver_type_.is_null(); } |
1347 Handle<Map> GetReceiverType() const { return receiver_type_; } | 1347 Handle<Map> GetReceiverType() const { return receiver_type_; } |
1348 | 1348 |
1349 bool IsCompileTimeValue() const; | 1349 bool IsCompileTimeValue() const; |
1350 | 1350 |
1351 void set_emit_store(bool emit_store); | 1351 void set_emit_store(bool emit_store); |
1352 bool emit_store() const; | 1352 bool emit_store() const; |
1353 | 1353 |
1354 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; } | 1354 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; } |
1355 | 1355 |
| 1356 bool IsNullPrototype() const { |
| 1357 return IsPrototype() && value()->IsNullLiteral(); |
| 1358 } |
| 1359 bool IsPrototype() const { return kind() == PROTOTYPE; } |
| 1360 |
1356 private: | 1361 private: |
1357 friend class AstNodeFactory; | 1362 friend class AstNodeFactory; |
1358 | 1363 |
1359 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind, | 1364 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind, |
1360 bool is_computed_name); | 1365 bool is_computed_name); |
1361 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key, | 1366 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key, |
1362 Expression* value, bool is_computed_name); | 1367 Expression* value, bool is_computed_name); |
1363 | 1368 |
1364 Kind kind_; | 1369 Kind kind_; |
1365 bool emit_store_; | 1370 bool emit_store_; |
(...skipping 17 matching lines...) Expand all Loading... |
1383 bool may_store_doubles() const { | 1388 bool may_store_doubles() const { |
1384 return MayStoreDoublesField::decode(bit_field_); | 1389 return MayStoreDoublesField::decode(bit_field_); |
1385 } | 1390 } |
1386 bool has_elements() const { return HasElementsField::decode(bit_field_); } | 1391 bool has_elements() const { return HasElementsField::decode(bit_field_); } |
1387 bool has_shallow_properties() const { | 1392 bool has_shallow_properties() const { |
1388 return depth() == 1 && !has_elements() && !may_store_doubles(); | 1393 return depth() == 1 && !has_elements() && !may_store_doubles(); |
1389 } | 1394 } |
1390 bool has_rest_property() const { | 1395 bool has_rest_property() const { |
1391 return HasRestPropertyField::decode(bit_field_); | 1396 return HasRestPropertyField::decode(bit_field_); |
1392 } | 1397 } |
1393 | 1398 bool HasNullPrototype() const { |
| 1399 for (int i = 0; i < properties()->length(); i++) { |
| 1400 const ObjectLiteral::Property* property = properties()->at(i); |
| 1401 if (property->IsNullPrototype()) return true; |
| 1402 } |
| 1403 return false; |
| 1404 } |
1394 // Decide if a property should be in the object boilerplate. | 1405 // Decide if a property should be in the object boilerplate. |
1395 static bool IsBoilerplateProperty(Property* property); | 1406 static bool IsBoilerplateProperty(Property* property); |
1396 | 1407 |
1397 // Populate the depth field and flags. | 1408 // Populate the depth field and flags. |
1398 void InitDepthAndFlags(); | 1409 void InitDepthAndFlags(); |
1399 | 1410 |
1400 // Get the constant properties fixed array, populating it if necessary. | 1411 // Get the constant properties fixed array, populating it if necessary. |
1401 Handle<BoilerplateDescription> GetOrBuildConstantProperties( | 1412 Handle<BoilerplateDescription> GetOrBuildConstantProperties( |
1402 Isolate* isolate) { | 1413 Isolate* isolate) { |
1403 if (constant_properties_.is_null()) { | 1414 if (constant_properties_.is_null()) { |
1404 BuildConstantProperties(isolate); | 1415 BuildConstantProperties(isolate); |
1405 } | 1416 } |
1406 return constant_properties(); | 1417 return constant_properties(); |
1407 } | 1418 } |
1408 | 1419 |
1409 // Populate the constant properties fixed array. | 1420 // Populate the constant properties fixed array. |
1410 void BuildConstantProperties(Isolate* isolate); | 1421 void BuildConstantProperties(Isolate* isolate); |
1411 | 1422 |
1412 // Mark all computed expressions that are bound to a key that | 1423 // Mark all computed expressions that are bound to a key that |
1413 // is shadowed by a later occurrence of the same key. For the | 1424 // is shadowed by a later occurrence of the same key. For the |
1414 // marked expressions, no store code is emitted. | 1425 // marked expressions, no store code is emitted. |
1415 void CalculateEmitStore(Zone* zone); | 1426 void CalculateEmitStore(Zone* zone); |
1416 | 1427 |
1417 // Determines whether the {FastCloneShallowObject} builtin can be used. | 1428 // Determines whether the {FastCloneShallowObject} builtin can be used. |
1418 bool IsFastCloningSupported() const; | 1429 bool IsFastCloningSupported() const; |
1419 | 1430 |
1420 // Assemble bitfield of flags for the CreateObjectLiteral helper. | 1431 // Assemble bitfield of flags for the CreateObjectLiteral helper. |
1421 int ComputeFlags(bool disable_mementos = false) const { | 1432 int ComputeFlags(bool disable_mementos = false) const { |
1422 int flags = fast_elements() ? kFastElements : kNoFlags; | 1433 int flags = fast_elements() ? kFastElements : kNoFlags; |
1423 if (has_shallow_properties()) { | 1434 if (HasNullPrototype()) flags |= kHasNullPrototype; |
1424 flags |= kShallowProperties; | 1435 if (has_shallow_properties()) flags |= kShallowProperties; |
1425 } | 1436 if (disable_mementos) flags |= kDisableMementos; |
1426 if (disable_mementos) { | |
1427 flags |= kDisableMementos; | |
1428 } | |
1429 return flags; | 1437 return flags; |
1430 } | 1438 } |
1431 | 1439 |
1432 enum Flags { | 1440 enum Flags { |
1433 kNoFlags = 0, | 1441 kNoFlags = 0, |
1434 kFastElements = 1, | 1442 kFastElements = 1, |
1435 kShallowProperties = 1 << 1, | 1443 kShallowProperties = 1 << 1, |
1436 kDisableMementos = 1 << 2, | 1444 kDisableMementos = 1 << 2, |
1437 kHasRestProperty = 1 << 3, | 1445 kHasRestProperty = 1 << 3, |
| 1446 kHasNullPrototype = 1 << 4, |
1438 }; | 1447 }; |
1439 | 1448 |
1440 struct Accessors: public ZoneObject { | 1449 struct Accessors: public ZoneObject { |
1441 Accessors() : getter(NULL), setter(NULL), bailout_id(BailoutId::None()) {} | 1450 Accessors() : getter(NULL), setter(NULL), bailout_id(BailoutId::None()) {} |
1442 ObjectLiteralProperty* getter; | 1451 ObjectLiteralProperty* getter; |
1443 ObjectLiteralProperty* setter; | 1452 ObjectLiteralProperty* setter; |
1444 BailoutId bailout_id; | 1453 BailoutId bailout_id; |
1445 }; | 1454 }; |
1446 | 1455 |
1447 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } | 1456 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } |
(...skipping 2189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3637 : NULL; \ | 3646 : NULL; \ |
3638 } | 3647 } |
3639 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3648 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
3640 #undef DECLARE_NODE_FUNCTIONS | 3649 #undef DECLARE_NODE_FUNCTIONS |
3641 | 3650 |
3642 | 3651 |
3643 } // namespace internal | 3652 } // namespace internal |
3644 } // namespace v8 | 3653 } // namespace v8 |
3645 | 3654 |
3646 #endif // V8_AST_AST_H_ | 3655 #endif // V8_AST_AST_H_ |
OLD | NEW |