5 #ifndef V8_MAYBE_HANDLES_INL_H_ 6 #define V8_MAYBE_HANDLES_INL_H_ 8 #include "src/maybe-handles.h" 10 #include "src/handles-inl.h" 11 #include "src/objects/maybe-object-inl.h" 16 MaybeHandle<T>::MaybeHandle(T*
object, Isolate* isolate)
17 : MaybeHandle(handle(object, isolate)) {}
19 MaybeObjectHandle::MaybeObjectHandle()
20 : reference_type_(HeapObjectReferenceType::STRONG),
21 handle_(Handle<Object>::null()) {}
23 MaybeObjectHandle::MaybeObjectHandle(MaybeObject
object, Isolate* isolate) {
24 HeapObject* heap_object;
25 DCHECK(!object->IsCleared());
26 if (object->GetHeapObjectIfWeak(&heap_object)) {
27 handle_ = handle(heap_object, isolate);
28 reference_type_ = HeapObjectReferenceType::WEAK;
30 handle_ = handle(object->cast<Object>(), isolate);
31 reference_type_ = HeapObjectReferenceType::STRONG;
35 MaybeObjectHandle::MaybeObjectHandle(Handle<Object>
object)
36 : reference_type_(HeapObjectReferenceType::STRONG), handle_(object) {}
38 MaybeObjectHandle::MaybeObjectHandle(Object*
object, Isolate* isolate)
39 : reference_type_(HeapObjectReferenceType::STRONG),
40 handle_(object, isolate) {}
42 MaybeObjectHandle::MaybeObjectHandle(Object*
object,
43 HeapObjectReferenceType reference_type,
45 : reference_type_(reference_type), handle_(handle(object, isolate)) {}
47 MaybeObjectHandle::MaybeObjectHandle(Handle<Object>
object,
48 HeapObjectReferenceType reference_type)
49 : reference_type_(reference_type), handle_(object) {}
51 MaybeObjectHandle MaybeObjectHandle::Weak(Handle<Object>
object) {
52 return MaybeObjectHandle(
object, HeapObjectReferenceType::WEAK);
55 MaybeObjectHandle MaybeObjectHandle::Weak(Object*
object, Isolate* isolate) {
56 return MaybeObjectHandle(
object, HeapObjectReferenceType::WEAK, isolate);
59 MaybeObject MaybeObjectHandle::operator*()
const {
60 if (reference_type_ == HeapObjectReferenceType::WEAK) {
61 return HeapObjectReference::Weak(*handle_.ToHandleChecked());
63 return MaybeObject::FromObject(*handle_.ToHandleChecked());
67 MaybeObject MaybeObjectHandle::operator->()
const {
68 if (reference_type_ == HeapObjectReferenceType::WEAK) {
69 return HeapObjectReference::Weak(*handle_.ToHandleChecked());
71 return MaybeObject::FromObject(*handle_.ToHandleChecked());
75 Handle<Object> MaybeObjectHandle::object()
const {
76 return handle_.ToHandleChecked();
79 inline MaybeObjectHandle handle(MaybeObject
object, Isolate* isolate) {
80 return MaybeObjectHandle(
object, isolate);
86 #endif // V8_MAYBE_HANDLES_INL_H_