1 // Copyright 2018 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_OBJECTS_PROPERTY_CELL_H_ 6 #define V8_OBJECTS_PROPERTY_CELL_H_ 7 8 #include "src/objects/heap-object.h" 9 10 // Has to be the last include (doesn't have include guards): 11 #include "src/objects/object-macros.h" 12 13 namespace v8 { 14 namespace internal { 15 16 #include "torque-generated/src/objects/property-cell-tq.inc" 17 18 class PropertyCell 19 : public TorqueGeneratedPropertyCell<PropertyCell, HeapObject> { 20 public: 21 // [name]: the name of the global property. 22 DECL_GETTER(name, Name) 23 24 // [property_details]: details of the global property. 25 DECL_GETTER(property_details_raw, Smi) 26 DECL_ACQUIRE_GETTER(property_details_raw, Smi) 27 inline PropertyDetails property_details() const; 28 inline PropertyDetails property_details(AcquireLoadTag tag) const; 29 inline void UpdatePropertyDetailsExceptCellType(PropertyDetails details); 30 31 // [value]: value of the global property. 32 DECL_GETTER(value, Object) 33 DECL_ACQUIRE_GETTER(value, Object) 34 35 // [dependent_code]: code that depends on the type of the global property. 36 DECL_ACCESSORS(dependent_code, DependentCode) 37 38 // Changes the value and/or property details. 39 // For global properties: 40 inline void Transition(PropertyDetails new_details, Handle<Object> new_value); 41 // For protectors: 42 void InvalidateProtector(); 43 44 static PropertyCellType InitialType(Isolate* isolate, Object value); 45 46 // Computes the new type of the cell's contents for the given value, but 47 // without actually modifying the details. 48 static PropertyCellType UpdatedType(Isolate* isolate, PropertyCell cell, 49 Object value, PropertyDetails details); 50 51 // Prepares property cell at given entry for receiving given value and sets 52 // that value. As a result the old cell could be invalidated and/or dependent 53 // code could be deoptimized. Returns the (possibly new) property cell. 54 static Handle<PropertyCell> PrepareForAndSetValue( 55 Isolate* isolate, Handle<GlobalDictionary> dictionary, 56 InternalIndex entry, Handle<Object> value, PropertyDetails details); 57 58 void ClearAndInvalidate(ReadOnlyRoots roots); 59 static Handle<PropertyCell> InvalidateAndReplaceEntry( 60 Isolate* isolate, Handle<GlobalDictionary> dictionary, 61 InternalIndex entry, PropertyDetails new_details, 62 Handle<Object> new_value); 63 64 // Whether or not the {details} and {value} fit together. This is an 65 // approximation with false positives. 66 static bool CheckDataIsCompatible(PropertyDetails details, Object value); 67 68 DECL_PRINTER(PropertyCell) 69 DECL_VERIFIER(PropertyCell) 70 71 using BodyDescriptor = FixedBodyDescriptor<kNameOffset, kSize, kSize>; 72 73 TQ_OBJECT_CONSTRUCTORS(PropertyCell) 74 75 private: 76 friend class Factory; 77 78 DECL_SETTER(name, Name) 79 DECL_SETTER(value, Object) 80 DECL_RELEASE_SETTER(value, Object) 81 DECL_SETTER(property_details_raw, Smi) 82 DECL_RELEASE_SETTER(property_details_raw, Smi) 83 84 #ifdef DEBUG 85 // Whether the property cell can transition to the given state. This is an 86 // approximation with false positives. 87 bool CanTransitionTo(PropertyDetails new_details, Object new_value) const; 88 #endif // DEBUG 89 }; 90 91 } // namespace internal 92 } // namespace v8 93 94 #include "src/objects/object-macros-undef.h" 95 96 #endif // V8_OBJECTS_PROPERTY_CELL_H_ 97