v8  8.4.371 (node 14.15.5)
V8 is Google's open source JavaScript engine
pointer-policies.h
Go to the documentation of this file.
1 // Copyright 2020 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef INCLUDE_CPPGC_INTERNAL_POINTER_POLICIES_H_
6 #define INCLUDE_CPPGC_INTERNAL_POINTER_POLICIES_H_
7 
8 #include <cstdint>
9 #include <type_traits>
10 
11 #include "cppgc/source-location.h"
12 #include "v8config.h" // NOLINT(build/include_directory)
13 
14 namespace cppgc {
15 namespace internal {
16 
17 class PersistentRegion;
18 
19 // Tags to distinguish between strong and weak member types.
20 class StrongMemberTag;
21 class WeakMemberTag;
22 class UntracedMemberTag;
23 
25  static void InitializingBarrier(const void*, const void*) {
26  // Since in initializing writes the source object is always white, having no
27  // barrier doesn't break the tri-color invariant.
28  }
29  static void AssigningBarrier(const void*, const void*) {
30  // TODO(chromium:1056170): Add actual implementation.
31  }
32 };
33 
35  static void InitializingBarrier(const void*, const void*) {}
36  static void AssigningBarrier(const void*, const void*) {}
37 };
38 
40  protected:
42  void CheckPointer(const void* ptr);
43 
44  private:
45  void* impl_;
46 };
47 
49  protected:
50  void CheckPointer(const void* raw) {}
51 };
52 
53 #if V8_ENABLE_CHECKS
55 #else
56 using DefaultCheckingPolicy = DisabledCheckingPolicy;
57 #endif
58 
60  public:
61  constexpr const SourceLocation& Location() const { return location_; }
62 
63  protected:
64  constexpr explicit KeepLocationPolicy(const SourceLocation& location)
65  : location_(location) {}
66 
67  // KeepLocationPolicy must not copy underlying source locations.
70 
71  // Location of the original moved from object should be preserved.
74 
75  private:
76  SourceLocation location_;
77 };
78 
80  public:
81  constexpr SourceLocation Location() const { return {}; }
82 
83  protected:
84  constexpr explicit IgnoreLocationPolicy(const SourceLocation&) {}
85 };
86 
87 #if CPPGC_SUPPORTS_OBJECT_NAMES
89 #else
90 using DefaultLocationPolicy = IgnoreLocationPolicy;
91 #endif
92 
94  using IsStrongPersistent = std::true_type;
95 
97 };
98 
100  using IsStrongPersistent = std::false_type;
101 
103 };
104 
105 // Persistent/Member forward declarations.
106 template <typename T, typename WeaknessPolicy,
107  typename LocationPolicy = DefaultLocationPolicy,
108  typename CheckingPolicy = DefaultCheckingPolicy>
109 class BasicPersistent;
110 template <typename T, typename WeaknessTag, typename WriteBarrierPolicy,
111  typename CheckingPolicy = DefaultCheckingPolicy>
112 class BasicMember;
113 
114 // Special tag type used to denote some sentinel member. The semantics of the
115 // sentinel is defined by the embedder.
117  template <typename T>
118  operator T*() const { // NOLINT
119  static constexpr intptr_t kSentinelValue = -1;
120  return reinterpret_cast<T*>(kSentinelValue);
121  }
122  // Hidden friends.
123  friend bool operator==(SentinelPointer, SentinelPointer) { return true; }
124  friend bool operator!=(SentinelPointer, SentinelPointer) { return false; }
125 };
126 
127 } // namespace internal
128 
130 
131 } // namespace cppgc
132 
133 #endif // INCLUDE_CPPGC_INTERNAL_POINTER_POLICIES_H_