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

Unified Diff: src/objects-inl.h

Issue 349623002: Make object accessors more const-correct. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« src/objects.h ('K') | « src/objects.h ('k') | src/spaces.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 20dc9b7e47ddae9219744d22f4b461e641fa4b51..e5727c887174086ae23135047d0a5bc8c5d8183e 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -67,30 +67,30 @@ PropertyDetails PropertyDetails::AsDeleted() const {
}
-#define INT_ACCESSORS(holder, name, offset) \
- int holder::name() { return READ_INT_FIELD(this, offset); } \
+#define INT_ACCESSORS(holder, name, offset) \
+ int holder::name() const { return READ_INT_FIELD(this, offset); } \
void holder::set_##name(int value) { WRITE_INT_FIELD(this, offset, value); }
-#define ACCESSORS(holder, name, type, offset) \
- type* holder::name() { return type::cast(READ_FIELD(this, offset)); } \
- void holder::set_##name(type* value, WriteBarrierMode mode) { \
- WRITE_FIELD(this, offset, value); \
- CONDITIONAL_WRITE_BARRIER(GetHeap(), this, offset, value, mode); \
+#define ACCESSORS(holder, name, type, offset) \
+ type* holder::name() const { return type::cast(READ_FIELD(this, offset)); } \
+ void holder::set_##name(type* value, WriteBarrierMode mode) { \
+ WRITE_FIELD(this, offset, value); \
+ CONDITIONAL_WRITE_BARRIER(GetHeap(), this, offset, value, mode); \
}
// Getter that returns a tagged Smi and setter that writes a tagged Smi.
-#define ACCESSORS_TO_SMI(holder, name, offset) \
- Smi* holder::name() { return Smi::cast(READ_FIELD(this, offset)); } \
- void holder::set_##name(Smi* value, WriteBarrierMode mode) { \
- WRITE_FIELD(this, offset, value); \
+#define ACCESSORS_TO_SMI(holder, name, offset) \
+ Smi* holder::name() const { return Smi::cast(READ_FIELD(this, offset)); } \
+ void holder::set_##name(Smi* value, WriteBarrierMode mode) { \
+ WRITE_FIELD(this, offset, value); \
}
// Getter that returns a Smi as an int and writes an int as a Smi.
#define SMI_ACCESSORS(holder, name, offset) \
- int holder::name() { \
+ int holder::name() const { \
Object* value = READ_FIELD(this, offset); \
return Smi::cast(value)->value(); \
} \
@@ -99,7 +99,7 @@ PropertyDetails PropertyDetails::AsDeleted() const {
}
#define SYNCHRONIZED_SMI_ACCESSORS(holder, name, offset) \
- int holder::synchronized_##name() { \
+ int holder::synchronized_##name() const { \
Object* value = ACQUIRE_READ_FIELD(this, offset); \
return Smi::cast(value)->value(); \
} \
@@ -108,7 +108,7 @@ PropertyDetails PropertyDetails::AsDeleted() const {
}
#define NOBARRIER_SMI_ACCESSORS(holder, name, offset) \
- int holder::nobarrier_##name() { \
+ int holder::nobarrier_##name() const { \
Object* value = NOBARRIER_READ_FIELD(this, offset); \
return Smi::cast(value)->value(); \
} \
@@ -117,13 +117,13 @@ PropertyDetails PropertyDetails::AsDeleted() const {
}
#define BOOL_GETTER(holder, field, name, offset) \
- bool holder::name() { \
+ bool holder::name() const { \
return BooleanBit::get(field(), offset); \
} \
#define BOOL_ACCESSORS(holder, field, name, offset) \
- bool holder::name() { \
+ bool holder::name() const { \
return BooleanBit::get(field(), offset); \
} \
void holder::set_##name(bool value) { \
@@ -1121,16 +1121,19 @@ bool JSProxy::HasElementWithHandler(Handle<JSProxy> proxy, uint32_t index) {
#define FIELD_ADDR(p, offset) \
(reinterpret_cast<byte*>(p) + offset - kHeapObjectTag)
+#define FIELD_ADDR_CONST(p, offset) \
+ (reinterpret_cast<const byte*>(p) + offset - kHeapObjectTag)
+
#define READ_FIELD(p, offset) \
- (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)))
+ (*reinterpret_cast<Object* const*>(FIELD_ADDR_CONST(p, offset)))
#define ACQUIRE_READ_FIELD(p, offset) \
reinterpret_cast<Object*>(base::Acquire_Load( \
- reinterpret_cast<base::AtomicWord*>(FIELD_ADDR(p, offset))))
+ reinterpret_cast<const base::AtomicWord*>(FIELD_ADDR_CONST(p, offset))))
#define NOBARRIER_READ_FIELD(p, offset) \
reinterpret_cast<Object*>(base::NoBarrier_Load( \
- reinterpret_cast<base::AtomicWord*>(FIELD_ADDR(p, offset))))
+ reinterpret_cast<const base::AtomicWord*>(FIELD_ADDR_CONST(p, offset))))
#define WRITE_FIELD(p, offset, value) \
(*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value)
@@ -1163,17 +1166,17 @@ bool JSProxy::HasElementWithHandler(Handle<JSProxy> proxy, uint32_t index) {
#ifndef V8_TARGET_ARCH_MIPS
#define READ_DOUBLE_FIELD(p, offset) \
- (*reinterpret_cast<double*>(FIELD_ADDR(p, offset)))
+ (*reinterpret_cast<const double*>(FIELD_ADDR_CONST(p, offset)))
#else // V8_TARGET_ARCH_MIPS
// Prevent gcc from using load-double (mips ldc1) on (possibly)
// non-64-bit aligned HeapNumber::value.
- static inline double read_double_field(void* p, int offset) {
+ static inline double read_double_field(const void* p, int offset) {
union conversion {
double d;
uint32_t u[2];
} c;
- c.u[0] = (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset)));
- c.u[1] = (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset + 4)));
+ c.u[0] = (*reinterpret_cast<uint32_t*>(FIELD_ADDR_CONST(p, offset)));
+ c.u[1] = (*reinterpret_cast<uint32_t*>(FIELD_ADDR_CONST(p, offset + 4)));
return c.d;
}
#define READ_DOUBLE_FIELD(p, offset) read_double_field(p, offset)
@@ -1201,43 +1204,43 @@ bool JSProxy::HasElementWithHandler(Handle<JSProxy> proxy, uint32_t index) {
#define READ_INT_FIELD(p, offset) \
- (*reinterpret_cast<int*>(FIELD_ADDR(p, offset)))
+ (*reinterpret_cast<const int*>(FIELD_ADDR_CONST(p, offset)))
#define WRITE_INT_FIELD(p, offset, value) \
(*reinterpret_cast<int*>(FIELD_ADDR(p, offset)) = value)
#define READ_INTPTR_FIELD(p, offset) \
- (*reinterpret_cast<intptr_t*>(FIELD_ADDR(p, offset)))
+ (*reinterpret_cast<const intptr_t*>(FIELD_ADDR_CONST(p, offset)))
#define WRITE_INTPTR_FIELD(p, offset, value) \
(*reinterpret_cast<intptr_t*>(FIELD_ADDR(p, offset)) = value)
#define READ_UINT32_FIELD(p, offset) \
- (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset)))
+ (*reinterpret_cast<const uint32_t*>(FIELD_ADDR_CONST(p, offset)))
#define WRITE_UINT32_FIELD(p, offset, value) \
(*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset)) = value)
#define READ_INT32_FIELD(p, offset) \
- (*reinterpret_cast<int32_t*>(FIELD_ADDR(p, offset)))
+ (*reinterpret_cast<const int32_t*>(FIELD_ADDR_CONST(p, offset)))
#define WRITE_INT32_FIELD(p, offset, value) \
(*reinterpret_cast<int32_t*>(FIELD_ADDR(p, offset)) = value)
#define READ_INT64_FIELD(p, offset) \
- (*reinterpret_cast<int64_t*>(FIELD_ADDR(p, offset)))
+ (*reinterpret_cast<const int64_t*>(FIELD_ADDR_CONST(p, offset)))
#define WRITE_INT64_FIELD(p, offset, value) \
(*reinterpret_cast<int64_t*>(FIELD_ADDR(p, offset)) = value)
#define READ_SHORT_FIELD(p, offset) \
- (*reinterpret_cast<uint16_t*>(FIELD_ADDR(p, offset)))
+ (*reinterpret_cast<const uint16_t*>(FIELD_ADDR_CONST(p, offset)))
#define WRITE_SHORT_FIELD(p, offset, value) \
(*reinterpret_cast<uint16_t*>(FIELD_ADDR(p, offset)) = value)
#define READ_BYTE_FIELD(p, offset) \
- (*reinterpret_cast<byte*>(FIELD_ADDR(p, offset)))
+ (*reinterpret_cast<const byte*>(FIELD_ADDR_CONST(p, offset)))
#define NOBARRIER_READ_BYTE_FIELD(p, offset) \
static_cast<byte>(base::NoBarrier_Load( \
@@ -1252,11 +1255,11 @@ bool JSProxy::HasElementWithHandler(Handle<JSProxy> proxy, uint32_t index) {
static_cast<base::Atomic8>(value));
Object** HeapObject::RawField(HeapObject* obj, int byte_offset) {
- return &READ_FIELD(obj, byte_offset);
+ return reinterpret_cast<Object**>(FIELD_ADDR(obj, byte_offset));
}
-int Smi::value() {
+int Smi::value() const {
return Internals::SmiValue(this);
}
@@ -1281,7 +1284,7 @@ bool Smi::IsValid(intptr_t value) {
}
-MapWord MapWord::FromMap(Map* map) {
+MapWord MapWord::FromMap(const Map* map) {
return MapWord(reinterpret_cast<uintptr_t>(map));
}
@@ -1319,9 +1322,9 @@ void HeapObject::VerifySmiField(int offset) {
#endif
-Heap* HeapObject::GetHeap() {
+Heap* HeapObject::GetHeap() const {
Heap* heap =
- MemoryChunk::FromAddress(reinterpret_cast<Address>(this))->heap();
+ MemoryChunk::FromAddress(reinterpret_cast<const byte*>(this))->heap();
SLOW_ASSERT(heap != NULL);
return heap;
}
@@ -1332,7 +1335,7 @@ Isolate* HeapObject::GetIsolate() {
}
-Map* HeapObject::map() {
+Map* HeapObject::map() const {
#ifdef DEBUG
// Clear mark potentially added by PathTracer.
uintptr_t raw_value =
@@ -1380,7 +1383,7 @@ void HeapObject::set_map_no_write_barrier(Map* value) {
}
-MapWord HeapObject::map_word() {
+MapWord HeapObject::map_word() const {
return MapWord(
reinterpret_cast<uintptr_t>(NOBARRIER_READ_FIELD(this, kMapOffset)));
}
@@ -1392,7 +1395,7 @@ void HeapObject::set_map_word(MapWord map_word) {
}
-MapWord HeapObject::synchronized_map_word() {
+MapWord HeapObject::synchronized_map_word() const {
return MapWord(
reinterpret_cast<uintptr_t>(ACQUIRE_READ_FIELD(this, kMapOffset)));
}
@@ -1476,7 +1479,7 @@ bool FixedArray::ContainsOnlySmisOrHoles() {
}
-FixedArrayBase* JSObject::elements() {
+FixedArrayBase* JSObject::elements() const {
Object* array = READ_FIELD(this, kElementsOffset);
return static_cast<FixedArrayBase*>(array);
}
@@ -1817,7 +1820,7 @@ void Oddball::set_kind(byte value) {
}
-Object* Cell::value() {
+Object* Cell::value() const {
return READ_FIELD(this, kValueOffset);
}
@@ -1830,7 +1833,7 @@ void Cell::set_value(Object* val, WriteBarrierMode ignored) {
ACCESSORS(PropertyCell, dependent_code, DependentCode, kDependentCodeOffset)
-Object* PropertyCell::type_raw() {
+Object* PropertyCell::type_raw() const {
return READ_FIELD(this, kTypeOffset);
}
@@ -3645,7 +3648,7 @@ void ExternalUint8ClampedArray::set(int index, uint8_t value) {
}
-void* ExternalArray::external_pointer() {
+void* ExternalArray::external_pointer() const {
intptr_t ptr = READ_INTPTR_FIELD(this, kExternalPointerOffset);
return reinterpret_cast<void*>(ptr);
}
@@ -4885,7 +4888,7 @@ bool Code::IsWeakObjectInIC(Object* object) {
}
-Object* Map::prototype() {
+Object* Map::prototype() const {
return READ_FIELD(this, kPrototypeOffset);
}
@@ -4961,7 +4964,7 @@ bool Map::HasElementsTransition() {
}
-bool Map::HasTransitionArray() {
+bool Map::HasTransitionArray() const {
Object* object = READ_FIELD(this, kTransitionsOrBackPointerOffset);
return object->IsTransitionArray();
}
@@ -5021,7 +5024,7 @@ bool Map::HasPrototypeTransitions() {
}
-TransitionArray* Map::transitions() {
+TransitionArray* Map::transitions() const {
ASSERT(HasTransitionArray());
Object* object = READ_FIELD(this, kTransitionsOrBackPointerOffset);
return TransitionArray::cast(object);
@@ -5286,7 +5289,7 @@ SMI_ACCESSORS(SharedFunctionInfo, profiler_ticks, kProfilerTicksOffset)
#define PSEUDO_SMI_ACCESSORS_LO(holder, name, offset) \
STATIC_ASSERT(holder::offset % kPointerSize == 0); \
- int holder::name() { \
+ int holder::name() const { \
int value = READ_INT_FIELD(this, offset); \
ASSERT(kHeapObjectTag == 1); \
ASSERT((value & kHeapObjectTag) == 0); \
@@ -5428,7 +5431,7 @@ void SharedFunctionInfo::set_start_position(int start_position) {
}
-Code* SharedFunctionInfo::code() {
+Code* SharedFunctionInfo::code() const {
return Code::cast(READ_FIELD(this, kCodeOffset));
}
@@ -5454,7 +5457,7 @@ void SharedFunctionInfo::ReplaceCode(Code* value) {
}
-ScopeInfo* SharedFunctionInfo::scope_info() {
+ScopeInfo* SharedFunctionInfo::scope_info() const {
return reinterpret_cast<ScopeInfo*>(READ_FIELD(this, kScopeInfoOffset));
}
@@ -5826,7 +5829,7 @@ ACCESSORS(JSMap, table, Object, kTableOffset)
#define ORDERED_HASH_TABLE_ITERATOR_ACCESSORS(name, type, offset) \
template<class Derived, class TableType> \
- type* OrderedHashTableIterator<Derived, TableType>::name() { \
+ type* OrderedHashTableIterator<Derived, TableType>::name() const { \
return type::cast(READ_FIELD(this, offset)); \
} \
template<class Derived, class TableType> \
@@ -6042,7 +6045,7 @@ bool Code::contains(byte* inner_pointer) {
ACCESSORS(JSArray, length, Object, kLengthOffset)
-void* JSArrayBuffer::backing_store() {
+void* JSArrayBuffer::backing_store() const {
intptr_t ptr = READ_INTPTR_FIELD(this, kBackingStoreOffset);
return reinterpret_cast<void*>(ptr);
}
@@ -6972,6 +6975,7 @@ void FlexibleBodyDescriptor<start_offset>::IterateBody(HeapObject* obj,
#undef BOOL_GETTER
#undef BOOL_ACCESSORS
#undef FIELD_ADDR
+#undef FIELD_ADDR_CONST
#undef READ_FIELD
#undef NOBARRIER_READ_FIELD
#undef WRITE_FIELD
« src/objects.h ('K') | « src/objects.h ('k') | src/spaces.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698