5 #ifndef V8_OBJECTS_SMI_H_ 6 #define V8_OBJECTS_SMI_H_ 8 #include "src/globals.h" 9 #include "src/objects/heap-object.h" 12 #include "src/objects/object-macros.h" 29 #if V8_CAN_HAVE_DCHECK_IN_CONSTEXPR 30 DCHECK(HAS_SMI_TAG(ptr));
33 Smi* operator->() {
return this; }
34 const Smi* operator->()
const {
return this; }
37 inline int value()
const {
return Internals::SmiValue(ptr()); }
38 inline Smi ToUint32Smi() {
39 if (value() <= 0)
return Smi::FromInt(0);
40 return Smi::FromInt(static_cast<uint32_t>(value()));
44 static inline int ToInt(
const Object*
object);
45 static inline int ToInt(
ObjectPtr object);
48 bool ToInt32(int32_t* value) {
49 *value = this->value();
54 static inline constexpr
Smi FromInt(
int value) {
55 #if V8_CAN_HAVE_DCHECK_IN_CONSTEXPR 56 DCHECK(Smi::IsValid(value));
58 return Smi(Internals::IntToSmi(value));
61 static inline Smi FromIntptr(intptr_t value) {
62 DCHECK(Smi::IsValid(value));
63 int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
64 return Smi((value << smi_shift_bits) | kSmiTag);
68 typename =
typename std::enable_if<std::is_enum<E>::value>
::type>
69 static inline Smi FromEnum(E value) {
70 STATIC_ASSERT(
sizeof(E) <=
sizeof(
int));
71 return FromInt(static_cast<int>(value));
75 static inline bool constexpr IsValid(intptr_t value) {
76 #if V8_CAN_HAVE_DCHECK_IN_CONSTEXPR 77 DCHECK(Internals::IsValidSmi(value) ==
78 (value >= kMinValue && value <= kMaxValue));
80 return Internals::IsValidSmi(value);
95 V8_EXPORT_PRIVATE
void SmiPrint(std::ostream& os)
const;
104 static inline constexpr
Smi zero() {
return Smi::FromInt(0); }
105 static constexpr
int kMinValue = kSmiMinValue;
106 static constexpr
int kMaxValue = kSmiMaxValue;
112 #include "src/objects/object-macros-undef.h" 114 #endif // V8_OBJECTS_SMI_H_