v8  8.4.371 (node 14.15.5)
V8 is Google's open source JavaScript engine
liveness-broker.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_LIVENESS_BROKER_H_
6 #define INCLUDE_CPPGC_LIVENESS_BROKER_H_
7 
8 #include "cppgc/heap.h"
9 #include "cppgc/member.h"
10 #include "cppgc/trace-trait.h"
11 #include "v8config.h" // NOLINT(build/include_directory)
12 
13 namespace cppgc {
14 
15 namespace internal {
16 class LivenessBrokerFactory;
17 } // namespace internal
18 
19 class V8_EXPORT LivenessBroker final {
20  public:
21  template <typename T>
22  bool IsHeapObjectAlive(const T* object) const {
23  return object &&
24  IsHeapObjectAliveImpl(
25  TraceTrait<T>::GetTraceDescriptor(object).base_object_payload);
26  }
27 
28  template <typename T>
29  bool IsHeapObjectAlive(const WeakMember<T>& weak_member) const {
30  return (weak_member != kSentinelPointer) &&
31  IsHeapObjectAlive<T>(weak_member.Get());
32  }
33 
34  template <typename T>
35  bool IsHeapObjectAlive(const UntracedMember<T>& untraced_member) const {
36  return (untraced_member != kSentinelPointer) &&
37  IsHeapObjectAlive<T>(untraced_member.Get());
38  }
39 
40  private:
41  LivenessBroker() = default;
42 
43  bool IsHeapObjectAliveImpl(const void*) const;
44 
45  friend class internal::LivenessBrokerFactory;
46 };
47 
48 } // namespace cppgc
49 
50 #endif // INCLUDE_CPPGC_LIVENESS_BROKER_H_