v8  8.4.371 (node 14.15.5)
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 "v8config.h" // NOLINT(build/include_directory)
12 
13 namespace cppgc {
14 namespace internal {
15 
16 using GCInfoIndex = uint16_t;
17 
18 class V8_EXPORT RegisteredGCInfoIndex final {
19  public:
20  RegisteredGCInfoIndex(FinalizationCallback finalization_callback,
21  bool has_v_table);
22  GCInfoIndex GetIndex() const { return index_; }
23 
24  private:
25  const GCInfoIndex index_;
26 };
27 
28 // Trait determines how the garbage collector treats objects wrt. to traversing,
29 // finalization, and naming.
30 template <typename T>
31 struct GCInfoTrait {
32  static GCInfoIndex Index() {
33  static_assert(sizeof(T), "T must be fully defined");
34  static const RegisteredGCInfoIndex registered_index(
35  FinalizerTrait<T>::kCallback, std::is_polymorphic<T>::value);
36  return registered_index.GetIndex();
37  }
38 };
39 
40 } // namespace internal
41 } // namespace cppgc
42 
43 #endif // INCLUDE_CPPGC_INTERNAL_GC_INFO_H_