summaryrefslogtreecommitdiff
path: root/deps/v8/src/objects/maybe-object.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/objects/maybe-object.h')
-rw-r--r--deps/v8/src/objects/maybe-object.h126
1 files changed, 14 insertions, 112 deletions
diff --git a/deps/v8/src/objects/maybe-object.h b/deps/v8/src/objects/maybe-object.h
index e62099b2d5..a1645c0604 100644
--- a/deps/v8/src/objects/maybe-object.h
+++ b/deps/v8/src/objects/maybe-object.h
@@ -5,121 +5,31 @@
#ifndef V8_OBJECTS_MAYBE_OBJECT_H_
#define V8_OBJECTS_MAYBE_OBJECT_H_
-#include "include/v8-internal.h"
-#include "include/v8.h"
-#include "src/globals.h"
-#include "src/objects.h"
-#include "src/objects/smi.h"
+#include "src/objects/tagged-impl.h"
namespace v8 {
namespace internal {
-class HeapObject;
-class Isolate;
-class StringStream;
-
// A MaybeObject is either a SMI, a strong reference to a HeapObject, a weak
// reference to a HeapObject, or a cleared weak reference. It's used for
// implementing in-place weak references (see design doc: goo.gl/j6SdcK )
-class MaybeObject {
+class MaybeObject : public TaggedImpl<HeapObjectReferenceType::WEAK, Address> {
public:
- MaybeObject() : ptr_(kNullAddress) {}
- explicit MaybeObject(Address ptr) : ptr_(ptr) {}
-
- bool operator==(const MaybeObject& other) const { return ptr_ == other.ptr_; }
- bool operator!=(const MaybeObject& other) const { return ptr_ != other.ptr_; }
-
- Address ptr() const { return ptr_; }
-
- // Enable incremental transition of client code.
- MaybeObject* operator->() { return this; }
- const MaybeObject* operator->() const { return this; }
-
- bool IsSmi() const { return HAS_SMI_TAG(ptr_); }
- inline bool ToSmi(Smi* value);
- inline Smi ToSmi() const;
-
- bool IsCleared() const {
- return static_cast<uint32_t>(ptr_) == kClearedWeakHeapObjectLower32;
- }
-
- inline bool IsStrongOrWeak() const;
- inline bool IsStrong() const;
-
- // If this MaybeObject is a strong pointer to a HeapObject, returns true and
- // sets *result. Otherwise returns false.
- inline bool GetHeapObjectIfStrong(HeapObject* result) const;
-
- // DCHECKs that this MaybeObject is a strong pointer to a HeapObject and
- // returns the HeapObject.
- inline HeapObject GetHeapObjectAssumeStrong() const;
-
- inline bool IsWeak() const;
- inline bool IsWeakOrCleared() const;
-
- // If this MaybeObject is a weak pointer to a HeapObject, returns true and
- // sets *result. Otherwise returns false.
- inline bool GetHeapObjectIfWeak(HeapObject* result) const;
-
- // DCHECKs that this MaybeObject is a weak pointer to a HeapObject and
- // returns the HeapObject.
- inline HeapObject GetHeapObjectAssumeWeak() const;
+ constexpr MaybeObject() : TaggedImpl(kNullAddress) {}
+ constexpr explicit MaybeObject(Address ptr) : TaggedImpl(ptr) {}
- // If this MaybeObject is a strong or weak pointer to a HeapObject, returns
- // true and sets *result. Otherwise returns false.
- inline bool GetHeapObject(HeapObject* result) const;
- inline bool GetHeapObject(HeapObject* result,
- HeapObjectReferenceType* reference_type) const;
+ // These operator->() overloads are required for handlified code.
+ constexpr const MaybeObject* operator->() const { return this; }
- // DCHECKs that this MaybeObject is a strong or a weak pointer to a HeapObject
- // and returns the HeapObject.
- inline HeapObject GetHeapObject() const;
+ V8_INLINE static MaybeObject FromSmi(Smi smi);
- // DCHECKs that this MaybeObject is a strong or a weak pointer to a HeapObject
- // or a SMI and returns the HeapObject or SMI.
- inline Object GetHeapObjectOrSmi() const;
+ V8_INLINE static MaybeObject FromObject(Object object);
- inline bool IsObject() const;
- template <typename T>
- T cast() const {
- DCHECK(!HasWeakHeapObjectTag(ptr_));
- return T::cast(Object(ptr_));
- }
-
- static MaybeObject FromSmi(Smi smi) {
- DCHECK(HAS_SMI_TAG(smi->ptr()));
- return MaybeObject(smi->ptr());
- }
-
- static MaybeObject FromObject(Object object) {
- DCHECK(!HasWeakHeapObjectTag(object.ptr()));
- return MaybeObject(object.ptr());
- }
-
- static inline MaybeObject MakeWeak(MaybeObject object);
+ V8_INLINE static MaybeObject MakeWeak(MaybeObject object);
#ifdef VERIFY_HEAP
static void VerifyMaybeObjectPointer(Isolate* isolate, MaybeObject p);
#endif
-
- // Prints this object without details.
- void ShortPrint(FILE* out = stdout);
-
- // Prints this object without details to a message accumulator.
- void ShortPrint(StringStream* accumulator);
-
- void ShortPrint(std::ostream& os);
-
-#ifdef OBJECT_PRINT
- void Print();
- void Print(std::ostream& os);
-#else
- void Print() { ShortPrint(); }
- void Print(std::ostream& os) { ShortPrint(os); }
-#endif
-
- private:
- Address ptr_;
};
// A HeapObjectReference is either a strong reference to a HeapObject, a weak
@@ -127,19 +37,11 @@ class MaybeObject {
class HeapObjectReference : public MaybeObject {
public:
explicit HeapObjectReference(Address address) : MaybeObject(address) {}
- explicit HeapObjectReference(Object object) : MaybeObject(object->ptr()) {}
-
- static HeapObjectReference Strong(Object object) {
- DCHECK(!object->IsSmi());
- DCHECK(!HasWeakHeapObjectTag(object));
- return HeapObjectReference(object);
- }
-
- static HeapObjectReference Weak(Object object) {
- DCHECK(!object->IsSmi());
- DCHECK(!HasWeakHeapObjectTag(object));
- return HeapObjectReference(object->ptr() | kWeakHeapObjectMask);
- }
+ V8_INLINE explicit HeapObjectReference(Object object);
+
+ V8_INLINE static HeapObjectReference Strong(Object object);
+
+ V8_INLINE static HeapObjectReference Weak(Object object);
V8_INLINE static HeapObjectReference ClearedValue(Isolate* isolate);