v8  8.6.395 (node 15.0.1)
V8 is Google's open source JavaScript engine
gc-info.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_GC_INFO_H_
6 #define INCLUDE_CPPGC_INTERNAL_GC_INFO_H_
7 
8 #include <stdint.h>
9 
10 #include "cppgc/internal/finalizer-trait.h"
11 #include "cppgc/trace-trait.h"
12 #include "v8config.h" // NOLINT(build/include_directory)
13 
14 namespace cppgc {
15 namespace internal {
16 
17 using GCInfoIndex = uint16_t;
18 
19 class V8_EXPORT RegisteredGCInfoIndex final {
20  public:
21  RegisteredGCInfoIndex(FinalizationCallback finalization_callback,
22  TraceCallback trace_callback, bool has_v_table);
23  GCInfoIndex GetIndex() const { return index_; }
24 
25  private:
26  const GCInfoIndex index_;
27 };
28 
29 // Trait determines how the garbage collector treats objects wrt. to traversing,
30 // finalization, and naming.
31 template <typename T>
32 struct GCInfoTrait {
33  static GCInfoIndex Index() {
34  static_assert(sizeof(T), "T must be fully defined");
35  static const RegisteredGCInfoIndex registered_index(
36  FinalizerTrait<T>::kCallback, TraceTrait<T>::Trace,
37  std::is_polymorphic<T>::value);
38  return registered_index.GetIndex();
39  }
40 };
41 
42 } // namespace internal
43 } // namespace cppgc
44 
45 #endif // INCLUDE_CPPGC_INTERNAL_GC_INFO_H_