| | |
| | |
| | |
| |
|
| | #ifndef INCLUDE_CPPGC_INTERNAL_POINTER_POLICIES_H_ |
| | #define INCLUDE_CPPGC_INTERNAL_POINTER_POLICIES_H_ |
| |
|
| | #include <cstdint> |
| | #include <type_traits> |
| |
|
| | #include "cppgc/source-location.h" |
| | #include "v8config.h" |
| |
|
| | namespace cppgc { |
| | namespace internal { |
| |
|
| | class PersistentRegion; |
| |
|
| | |
| | class StrongMemberTag; |
| | class WeakMemberTag; |
| | class UntracedMemberTag; |
| |
|
| | struct DijkstraWriteBarrierPolicy { |
| | static void InitializingBarrier(const void*, const void*) { |
| | |
| | |
| | } |
| | static void AssigningBarrier(const void*, const void*) { |
| | |
| | } |
| | }; |
| |
|
| | struct NoWriteBarrierPolicy { |
| | static void InitializingBarrier(const void*, const void*) {} |
| | static void AssigningBarrier(const void*, const void*) {} |
| | }; |
| |
|
| | class V8_EXPORT EnabledCheckingPolicy { |
| | protected: |
| | EnabledCheckingPolicy(); |
| | void CheckPointer(const void* ptr); |
| |
|
| | private: |
| | void* impl_; |
| | }; |
| |
|
| | class DisabledCheckingPolicy { |
| | protected: |
| | void CheckPointer(const void* raw) {} |
| | }; |
| |
|
| | #if V8_ENABLE_CHECKS |
| | using DefaultCheckingPolicy = EnabledCheckingPolicy; |
| | #else |
| | using DefaultCheckingPolicy = DisabledCheckingPolicy; |
| | #endif |
| |
|
| | class KeepLocationPolicy { |
| | public: |
| | constexpr const SourceLocation& Location() const { return location_; } |
| |
|
| | protected: |
| | constexpr explicit KeepLocationPolicy(const SourceLocation& location) |
| | : location_(location) {} |
| |
|
| | |
| | KeepLocationPolicy(const KeepLocationPolicy&) = delete; |
| | KeepLocationPolicy& operator=(const KeepLocationPolicy&) = delete; |
| |
|
| | |
| | KeepLocationPolicy(KeepLocationPolicy&&) = default; |
| | KeepLocationPolicy& operator=(KeepLocationPolicy&&) = default; |
| |
|
| | private: |
| | SourceLocation location_; |
| | }; |
| |
|
| | class IgnoreLocationPolicy { |
| | public: |
| | constexpr SourceLocation Location() const { return {}; } |
| |
|
| | protected: |
| | constexpr explicit IgnoreLocationPolicy(const SourceLocation&) {} |
| | }; |
| |
|
| | #if CPPGC_SUPPORTS_OBJECT_NAMES |
| | using DefaultLocationPolicy = KeepLocationPolicy; |
| | #else |
| | using DefaultLocationPolicy = IgnoreLocationPolicy; |
| | #endif |
| |
|
| | struct StrongPersistentPolicy { |
| | using IsStrongPersistent = std::true_type; |
| |
|
| | static V8_EXPORT PersistentRegion& GetPersistentRegion(void* object); |
| | }; |
| |
|
| | struct WeakPersistentPolicy { |
| | using IsStrongPersistent = std::false_type; |
| |
|
| | static V8_EXPORT PersistentRegion& GetPersistentRegion(void* object); |
| | }; |
| |
|
| | |
| | template <typename T, typename WeaknessPolicy, |
| | typename LocationPolicy = DefaultLocationPolicy, |
| | typename CheckingPolicy = DefaultCheckingPolicy> |
| | class BasicPersistent; |
| | template <typename T, typename WeaknessTag, typename WriteBarrierPolicy, |
| | typename CheckingPolicy = DefaultCheckingPolicy> |
| | class BasicMember; |
| |
|
| | |
| | |
| | struct SentinelPointer { |
| | template <typename T> |
| | operator T*() const { |
| | static constexpr intptr_t kSentinelValue = -1; |
| | return reinterpret_cast<T*>(kSentinelValue); |
| | } |
| | |
| | friend bool operator==(SentinelPointer, SentinelPointer) { return true; } |
| | friend bool operator!=(SentinelPointer, SentinelPointer) { return false; } |
| | }; |
| |
|
| | } |
| |
|
| | constexpr internal::SentinelPointer kSentinelPointer; |
| |
|
| | } |
| |
|
| | #endif |
| |
|