• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INL_H_
6 #define V8_OBJECTS_PROPERTY_CELL_INL_H_
7 
8 #include "src/objects/property-cell.h"
9 
10 #include "src/heap/heap-write-barrier-inl.h"
11 #include "src/objects/code-inl.h"
12 
13 // Has to be the last include (doesn't have include guards):
14 #include "src/objects/object-macros.h"
15 
16 namespace v8 {
17 namespace internal {
18 
19 #include "torque-generated/src/objects/property-cell-tq-inl.inc"
20 
21 TQ_OBJECT_CONSTRUCTORS_IMPL(PropertyCell)
22 
ACCESSORS(PropertyCell,dependent_code,DependentCode,kDependentCodeOffset)23 ACCESSORS(PropertyCell, dependent_code, DependentCode, kDependentCodeOffset)
24 ACCESSORS(PropertyCell, name, Name, kNameOffset)
25 ACCESSORS(PropertyCell, property_details_raw, Smi, kPropertyDetailsRawOffset)
26 RELEASE_ACQUIRE_ACCESSORS(PropertyCell, property_details_raw, Smi,
27                           kPropertyDetailsRawOffset)
28 ACCESSORS(PropertyCell, value, Object, kValueOffset)
29 RELEASE_ACQUIRE_ACCESSORS(PropertyCell, value, Object, kValueOffset)
30 
31 PropertyDetails PropertyCell::property_details() const {
32   return PropertyDetails(Smi::cast(property_details_raw()));
33 }
34 
property_details(AcquireLoadTag tag)35 PropertyDetails PropertyCell::property_details(AcquireLoadTag tag) const {
36   return PropertyDetails(Smi::cast(property_details_raw(tag)));
37 }
38 
UpdatePropertyDetailsExceptCellType(PropertyDetails details)39 void PropertyCell::UpdatePropertyDetailsExceptCellType(
40     PropertyDetails details) {
41   DCHECK(CheckDataIsCompatible(details, value()));
42   PropertyDetails old_details = property_details();
43   CHECK_EQ(old_details.cell_type(), details.cell_type());
44   set_property_details_raw(details.AsSmi(), kReleaseStore);
45   // Deopt when making a writable property read-only. The reverse direction
46   // is uninteresting because Turbofan does not currently rely on read-only
47   // unless the property is also configurable, in which case it will stay
48   // read-only forever.
49   if (!old_details.IsReadOnly() && details.IsReadOnly()) {
50     // TODO(11527): pass Isolate as an argument.
51     Isolate* isolate = GetIsolateFromWritableObject(*this);
52     dependent_code().DeoptimizeDependentCodeGroup(
53         isolate, DependentCode::kPropertyCellChangedGroup);
54   }
55 }
56 
Transition(PropertyDetails new_details,Handle<Object> new_value)57 void PropertyCell::Transition(PropertyDetails new_details,
58                               Handle<Object> new_value) {
59   DCHECK(CanTransitionTo(new_details, *new_value));
60   // This code must be in sync with its counterpart in
61   // PropertyCellData::Serialize.
62   PropertyDetails transition_marker = new_details;
63   transition_marker.set_cell_type(PropertyCellType::kInTransition);
64   set_property_details_raw(transition_marker.AsSmi(), kReleaseStore);
65   set_value(*new_value, kReleaseStore);
66   set_property_details_raw(new_details.AsSmi(), kReleaseStore);
67 }
68 
69 }  // namespace internal
70 }  // namespace v8
71 
72 #include "src/objects/object-macros-undef.h"
73 
74 #endif  // V8_OBJECTS_PROPERTY_CELL_INL_H_
75