 Chromium Code Reviews
 Chromium Code Reviews Issue 343583002:
  Make the internal parts of our external API a bit more const-correct.  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
    
  
    Issue 343583002:
  Make the internal parts of our external API a bit more const-correct.  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge| 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 /** \mainpage V8 API Reference Guide | 5 /** \mainpage V8 API Reference Guide | 
| 6 * | 6 * | 
| 7 * V8 is Google's open source JavaScript engine. | 7 * V8 is Google's open source JavaScript engine. | 
| 8 * | 8 * | 
| 9 * This set of documents provides reference material generated from the | 9 * This set of documents provides reference material generated from the | 
| 10 * V8 header file, include/v8.h. | 10 * V8 header file, include/v8.h. | 
| (...skipping 5441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5452 int smi_shift_bits = kSmiTagSize + kSmiShiftSize; | 5452 int smi_shift_bits = kSmiTagSize + kSmiShiftSize; | 
| 5453 intptr_t tagged_value = | 5453 intptr_t tagged_value = | 
| 5454 (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag; | 5454 (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag; | 
| 5455 return reinterpret_cast<internal::Object*>(tagged_value); | 5455 return reinterpret_cast<internal::Object*>(tagged_value); | 
| 5456 } | 5456 } | 
| 5457 | 5457 | 
| 5458 // Smi constants for 32-bit systems. | 5458 // Smi constants for 32-bit systems. | 
| 5459 template <> struct SmiTagging<4> { | 5459 template <> struct SmiTagging<4> { | 
| 5460 static const int kSmiShiftSize = 0; | 5460 static const int kSmiShiftSize = 0; | 
| 5461 static const int kSmiValueSize = 31; | 5461 static const int kSmiValueSize = 31; | 
| 5462 V8_INLINE static int SmiToInt(internal::Object* value) { | 5462 V8_INLINE static int SmiToInt(const internal::Object* value) { | 
| 5463 int shift_bits = kSmiTagSize + kSmiShiftSize; | 5463 int shift_bits = kSmiTagSize + kSmiShiftSize; | 
| 5464 // Throw away top 32 bits and shift down (requires >> to be sign extending). | 5464 // Throw away top 32 bits and shift down (requires >> to be sign extending). | 
| 5465 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; | 5465 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; | 
| 5466 } | 5466 } | 
| 5467 V8_INLINE static internal::Object* IntToSmi(int value) { | 5467 V8_INLINE static internal::Object* IntToSmi(int value) { | 
| 5468 return internal::IntToSmi<kSmiShiftSize>(value); | 5468 return internal::IntToSmi<kSmiShiftSize>(value); | 
| 5469 } | 5469 } | 
| 5470 V8_INLINE static bool IsValidSmi(intptr_t value) { | 5470 V8_INLINE static bool IsValidSmi(intptr_t value) { | 
| 5471 // To be representable as an tagged small integer, the two | 5471 // To be representable as an tagged small integer, the two | 
| 5472 // most-significant bits of 'value' must be either 00 or 11 due to | 5472 // most-significant bits of 'value' must be either 00 or 11 due to | 
| 5473 // sign-extension. To check this we add 01 to the two | 5473 // sign-extension. To check this we add 01 to the two | 
| 5474 // most-significant bits, and check if the most-significant bit is 0 | 5474 // most-significant bits, and check if the most-significant bit is 0 | 
| 5475 // | 5475 // | 
| 5476 // CAUTION: The original code below: | 5476 // CAUTION: The original code below: | 
| 5477 // bool result = ((value + 0x40000000) & 0x80000000) == 0; | 5477 // bool result = ((value + 0x40000000) & 0x80000000) == 0; | 
| 5478 // may lead to incorrect results according to the C language spec, and | 5478 // may lead to incorrect results according to the C language spec, and | 
| 5479 // in fact doesn't work correctly with gcc4.1.1 in some cases: The | 5479 // in fact doesn't work correctly with gcc4.1.1 in some cases: The | 
| 5480 // compiler may produce undefined results in case of signed integer | 5480 // compiler may produce undefined results in case of signed integer | 
| 5481 // overflow. The computation must be done w/ unsigned ints. | 5481 // overflow. The computation must be done w/ unsigned ints. | 
| 5482 return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U; | 5482 return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U; | 
| 5483 } | 5483 } | 
| 5484 }; | 5484 }; | 
| 5485 | 5485 | 
| 5486 // Smi constants for 64-bit systems. | 5486 // Smi constants for 64-bit systems. | 
| 5487 template <> struct SmiTagging<8> { | 5487 template <> struct SmiTagging<8> { | 
| 5488 static const int kSmiShiftSize = 31; | 5488 static const int kSmiShiftSize = 31; | 
| 5489 static const int kSmiValueSize = 32; | 5489 static const int kSmiValueSize = 32; | 
| 5490 V8_INLINE static int SmiToInt(internal::Object* value) { | 5490 V8_INLINE static int SmiToInt(const internal::Object* value) { | 
| 5491 int shift_bits = kSmiTagSize + kSmiShiftSize; | 5491 int shift_bits = kSmiTagSize + kSmiShiftSize; | 
| 5492 // Shift down and throw away top 32 bits. | 5492 // Shift down and throw away top 32 bits. | 
| 5493 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); | 5493 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); | 
| 5494 } | 5494 } | 
| 5495 V8_INLINE static internal::Object* IntToSmi(int value) { | 5495 V8_INLINE static internal::Object* IntToSmi(int value) { | 
| 5496 return internal::IntToSmi<kSmiShiftSize>(value); | 5496 return internal::IntToSmi<kSmiShiftSize>(value); | 
| 5497 } | 5497 } | 
| 5498 V8_INLINE static bool IsValidSmi(intptr_t value) { | 5498 V8_INLINE static bool IsValidSmi(intptr_t value) { | 
| 5499 // To be representable as a long smi, the value must be a 32-bit integer. | 5499 // To be representable as a long smi, the value must be a 32-bit integer. | 
| 5500 return (value == static_cast<int32_t>(value)); | 5500 return (value == static_cast<int32_t>(value)); | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5568 | 5568 | 
| 5569 static const uint32_t kNumIsolateDataSlots = 4; | 5569 static const uint32_t kNumIsolateDataSlots = 4; | 
| 5570 | 5570 | 
| 5571 V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate); | 5571 V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate); | 
| 5572 V8_INLINE static void CheckInitialized(v8::Isolate* isolate) { | 5572 V8_INLINE static void CheckInitialized(v8::Isolate* isolate) { | 
| 5573 #ifdef V8_ENABLE_CHECKS | 5573 #ifdef V8_ENABLE_CHECKS | 
| 5574 CheckInitializedImpl(isolate); | 5574 CheckInitializedImpl(isolate); | 
| 5575 #endif | 5575 #endif | 
| 5576 } | 5576 } | 
| 5577 | 5577 | 
| 5578 V8_INLINE static bool HasHeapObjectTag(internal::Object* value) { | 5578 V8_INLINE static bool HasHeapObjectTag(const internal::Object* value) { | 
| 5579 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | 5579 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | 
| 5580 kHeapObjectTag); | 5580 kHeapObjectTag); | 
| 5581 } | 5581 } | 
| 5582 | 5582 | 
| 5583 V8_INLINE static int SmiValue(internal::Object* value) { | 5583 V8_INLINE static int SmiValue(const internal::Object* value) { | 
| 5584 return PlatformSmiTagging::SmiToInt(value); | 5584 return PlatformSmiTagging::SmiToInt(value); | 
| 5585 } | 5585 } | 
| 5586 | 5586 | 
| 5587 V8_INLINE static internal::Object* IntToSmi(int value) { | 5587 V8_INLINE static internal::Object* IntToSmi(int value) { | 
| 5588 return PlatformSmiTagging::IntToSmi(value); | 5588 return PlatformSmiTagging::IntToSmi(value); | 
| 5589 } | 5589 } | 
| 5590 | 5590 | 
| 5591 V8_INLINE static bool IsValidSmi(intptr_t value) { | 5591 V8_INLINE static bool IsValidSmi(intptr_t value) { | 
| 5592 return PlatformSmiTagging::IsValidSmi(value); | 5592 return PlatformSmiTagging::IsValidSmi(value); | 
| 5593 } | 5593 } | 
| 5594 | 5594 | 
| 5595 V8_INLINE static int GetInstanceType(internal::Object* obj) { | 5595 V8_INLINE static int GetInstanceType(const internal::Object* obj) { | 
| 5596 typedef internal::Object O; | 5596 typedef internal::Object O; | 
| 5597 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); | 5597 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); | 
| 5598 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); | 5598 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); | 
| 5599 } | 5599 } | 
| 5600 | 5600 | 
| 5601 V8_INLINE static int GetOddballKind(internal::Object* obj) { | 5601 V8_INLINE static int GetOddballKind(const internal::Object* obj) { | 
| 5602 typedef internal::Object O; | 5602 typedef internal::Object O; | 
| 5603 return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); | 5603 return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); | 
| 5604 } | 5604 } | 
| 5605 | 5605 | 
| 5606 V8_INLINE static bool IsExternalTwoByteString(int instance_type) { | 5606 V8_INLINE static bool IsExternalTwoByteString(int instance_type) { | 
| 5607 int representation = (instance_type & kFullStringRepresentationMask); | 5607 int representation = (instance_type & kFullStringRepresentationMask); | 
| 5608 return representation == kExternalTwoByteRepresentationTag; | 5608 return representation == kExternalTwoByteRepresentationTag; | 
| 5609 } | 5609 } | 
| 5610 | 5610 | 
| 5611 V8_INLINE static uint8_t GetNodeFlag(internal::Object** obj, int shift) { | 5611 V8_INLINE static uint8_t GetNodeFlag(internal::Object** obj, int shift) { | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 5624 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; | 5624 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; | 
| 5625 return *addr & kNodeStateMask; | 5625 return *addr & kNodeStateMask; | 
| 5626 } | 5626 } | 
| 5627 | 5627 | 
| 5628 V8_INLINE static void UpdateNodeState(internal::Object** obj, | 5628 V8_INLINE static void UpdateNodeState(internal::Object** obj, | 
| 5629 uint8_t value) { | 5629 uint8_t value) { | 
| 5630 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; | 5630 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; | 
| 5631 *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value); | 5631 *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value); | 
| 5632 } | 5632 } | 
| 5633 | 5633 | 
| 5634 V8_INLINE static void SetEmbedderData(v8::Isolate *isolate, | 5634 V8_INLINE static void SetEmbedderData(v8::Isolate* isolate, | 
| 5635 uint32_t slot, | 5635 uint32_t slot, | 
| 5636 void *data) { | 5636 void* data) { | 
| 5637 uint8_t *addr = reinterpret_cast<uint8_t *>(isolate) + | 5637 uint8_t *addr = reinterpret_cast<uint8_t *>(isolate) + | 
| 5638 kIsolateEmbedderDataOffset + slot * kApiPointerSize; | 5638 kIsolateEmbedderDataOffset + slot * kApiPointerSize; | 
| 
Michael Starzinger
2014/06/18 13:48:16
nit: There are three different indentation styles
 | |
| 5639 *reinterpret_cast<void**>(addr) = data; | 5639 *reinterpret_cast<void**>(addr) = data; | 
| 5640 } | 5640 } | 
| 5641 | 5641 | 
| 5642 V8_INLINE static void* GetEmbedderData(v8::Isolate* isolate, uint32_t slot) { | 5642 V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate, | 
| 5643 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + | 5643 uint32_t slot) { | 
| 5644 const uint8_t* addr = reinterpret_cast<const uint8_t*>(isolate) + | |
| 5644 kIsolateEmbedderDataOffset + slot * kApiPointerSize; | 5645 kIsolateEmbedderDataOffset + slot * kApiPointerSize; | 
| 5645 return *reinterpret_cast<void**>(addr); | 5646 return *reinterpret_cast<void* const*>(addr); | 
| 5646 } | 5647 } | 
| 5647 | 5648 | 
| 5648 V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate, | 5649 V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate, | 
| 5649 int index) { | 5650 int index) { | 
| 5650 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; | 5651 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; | 
| 5651 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); | 5652 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); | 
| 5652 } | 5653 } | 
| 5653 | 5654 | 
| 5654 template <typename T> | 5655 template <typename T> | 
| 5655 V8_INLINE static T ReadField(internal::Object* ptr, int offset) { | 5656 V8_INLINE static T ReadField(const internal::Object* ptr, int offset) { | 
| 5656 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; | 5657 const uint8_t* addr = | 
| 5657 return *reinterpret_cast<T*>(addr); | 5658 reinterpret_cast<const uint8_t*>(ptr) + offset - kHeapObjectTag; | 
| 5659 return *reinterpret_cast<const T*>(addr); | |
| 5658 } | 5660 } | 
| 5659 | 5661 | 
| 5660 template <typename T> | 5662 template <typename T> | 
| 5661 V8_INLINE static T ReadEmbedderData(v8::Context* context, int index) { | 5663 V8_INLINE static T ReadEmbedderData(const v8::Context* context, int index) { | 
| 5662 typedef internal::Object O; | 5664 typedef internal::Object O; | 
| 5663 typedef internal::Internals I; | 5665 typedef internal::Internals I; | 
| 5664 O* ctx = *reinterpret_cast<O**>(context); | 5666 O* ctx = *reinterpret_cast<O* const*>(context); | 
| 5665 int embedder_data_offset = I::kContextHeaderSize + | 5667 int embedder_data_offset = I::kContextHeaderSize + | 
| 5666 (internal::kApiPointerSize * I::kContextEmbedderDataIndex); | 5668 (internal::kApiPointerSize * I::kContextEmbedderDataIndex); | 
| 5667 O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset); | 5669 O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset); | 
| 5668 int value_offset = | 5670 int value_offset = | 
| 5669 I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index); | 5671 I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index); | 
| 5670 return I::ReadField<T>(embedder_data, value_offset); | 5672 return I::ReadField<T>(embedder_data, value_offset); | 
| 5671 } | 5673 } | 
| 5672 }; | 5674 }; | 
| 5673 | 5675 | 
| 5674 } // namespace internal | 5676 } // namespace internal | 
| (...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6654 */ | 6656 */ | 
| 6655 | 6657 | 
| 6656 | 6658 | 
| 6657 } // namespace v8 | 6659 } // namespace v8 | 
| 6658 | 6660 | 
| 6659 | 6661 | 
| 6660 #undef TYPE_CHECK | 6662 #undef TYPE_CHECK | 
| 6661 | 6663 | 
| 6662 | 6664 | 
| 6663 #endif // V8_H_ | 6665 #endif // V8_H_ | 
| OLD | NEW |