5 #ifndef V8_MAYBE_HANDLES_H_ 6 #define V8_MAYBE_HANDLES_H_ 10 #include "src/handles.h" 24 class MaybeHandle final {
26 V8_INLINE MaybeHandle() =
default;
31 template <
typename S,
typename =
typename std::enable_if<
32 std::is_convertible<S*, T*>::value ||
33 std::is_same<T, Object>::value ||
34 (std::is_same<T, HeapObject>::value &&
35 (std::is_same<S, FixedArray>::value ||
36 std::is_same<S, Map>::value))>::type>
37 V8_INLINE MaybeHandle(Handle<S> handle) : location_(handle.location_) {}
42 template <
typename S,
typename =
typename std::enable_if<
43 std::is_convertible<S*, T*>::value ||
44 std::is_same<T, Object>::value ||
45 (std::is_same<T, HeapObject>::value &&
46 std::is_same<S, Map>::value)>::type>
47 V8_INLINE MaybeHandle(MaybeHandle<S> maybe_handle)
48 : location_(maybe_handle.location_) {}
50 V8_INLINE MaybeHandle(T*
object, Isolate* isolate);
52 V8_INLINE
void Assert()
const { DCHECK_NOT_NULL(location_); }
53 V8_INLINE
void Check()
const { CHECK_NOT_NULL(location_); }
55 V8_INLINE Handle<T> ToHandleChecked()
const {
57 return Handle<T>(location_);
62 V8_INLINE
bool ToHandle(Handle<S>* out)
const {
63 if (location_ ==
nullptr) {
64 *out = Handle<T>::null();
67 *out = Handle<T>(location_);
74 V8_INLINE Address address()
const {
75 return reinterpret_cast<Address
>(location_);
78 bool is_null()
const {
return location_ ==
nullptr; }
81 Address* location_ =
nullptr;
86 friend class MaybeHandle;
108 return reference_type_ == other.reference_type_ &&
109 handle_.ToHandle(&this_handle) ==
110 other.handle_.ToHandle(&other_handle) &&
111 this_handle.is_identical_to(other_handle);
114 bool is_null()
const {
return handle_.is_null(); }
118 HeapObjectReferenceType reference_type,
121 HeapObjectReferenceType reference_type);
123 HeapObjectReferenceType reference_type_;
130 #endif // V8_MAYBE_HANDLES_H_