property-cell-inl.h 2.79 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_OBJECTS_PROPERTY_CELL_INL_H_
#define V8_OBJECTS_PROPERTY_CELL_INL_H_

#include "src/objects/property-cell.h"

10 11
#include "src/heap/heap-write-barrier-inl.h"
#include "src/objects/code-inl.h"
12 13 14 15 16 17 18

// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"

namespace v8 {
namespace internal {

19
#include "torque-generated/src/objects/property-cell-tq-inl.inc"
20

21
TQ_OBJECT_CONSTRUCTORS_IMPL(PropertyCell)
22

23 24
ACCESSORS(PropertyCell, dependent_code, DependentCode, kDependentCodeOffset)
ACCESSORS(PropertyCell, name, Name, kNameOffset)
25
ACCESSORS(PropertyCell, property_details_raw, Smi, kPropertyDetailsRawOffset)
26 27 28 29
RELEASE_ACQUIRE_ACCESSORS(PropertyCell, property_details_raw, Smi,
                          kPropertyDetailsRawOffset)
ACCESSORS(PropertyCell, value, Object, kValueOffset)
RELEASE_ACQUIRE_ACCESSORS(PropertyCell, value, Object, kValueOffset)
30 31 32 33 34

PropertyDetails PropertyCell::property_details() const {
  return PropertyDetails(Smi::cast(property_details_raw()));
}

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
PropertyDetails PropertyCell::property_details(AcquireLoadTag tag) const {
  return PropertyDetails(Smi::cast(property_details_raw(tag)));
}

void PropertyCell::UpdatePropertyDetailsExceptCellType(
    PropertyDetails details) {
  DCHECK(CheckDataIsCompatible(details, value()));
  PropertyDetails old_details = property_details();
  CHECK_EQ(old_details.cell_type(), details.cell_type());
  set_property_details_raw(details.AsSmi(), kReleaseStore);
  // Deopt when making a writable property read-only. The reverse direction
  // is uninteresting because Turbofan does not currently rely on read-only
  // unless the property is also configurable, in which case it will stay
  // read-only forever.
  if (!old_details.IsReadOnly() && details.IsReadOnly()) {
50 51
    // TODO(11527): pass Isolate as an argument.
    Isolate* isolate = GetIsolateFromWritableObject(*this);
52
    dependent_code().DeoptimizeDependentCodeGroup(
53
        isolate, DependentCode::kPropertyCellChangedGroup);
54 55 56 57 58 59 60 61
  }
}

void PropertyCell::Transition(PropertyDetails new_details,
                              Handle<Object> new_value) {
  DCHECK(CanTransitionTo(new_details, *new_value));
  // This code must be in sync with its counterpart in
  // PropertyCellData::Serialize.
62 63 64
  PropertyDetails transition_marker = new_details;
  transition_marker.set_cell_type(PropertyCellType::kInTransition);
  set_property_details_raw(transition_marker.AsSmi(), kReleaseStore);
65 66
  set_value(*new_value, kReleaseStore);
  set_property_details_raw(new_details.AsSmi(), kReleaseStore);
67 68 69 70 71 72 73 74
}

}  // namespace internal
}  // namespace v8

#include "src/objects/object-macros-undef.h"

#endif  // V8_OBJECTS_PROPERTY_CELL_INL_H_