tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TraceKind.h (1782B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef gc_TraceKind_h
      8 #define gc_TraceKind_h
      9 
     10 #include "js/TraceKind.h"
     11 
     12 namespace js {
     13 namespace gc {
     14 
     15 // Map from all trace kinds to the base GC type.
     16 template <JS::TraceKind kind>
     17 struct MapTraceKindToType {};
     18 
     19 #define DEFINE_TRACE_KIND_MAP(name, type, _, _1)   \
     20  template <>                                      \
     21  struct MapTraceKindToType<JS::TraceKind::name> { \
     22    using Type = type;                             \
     23  };
     24 JS_FOR_EACH_TRACEKIND(DEFINE_TRACE_KIND_MAP);
     25 #undef DEFINE_TRACE_KIND_MAP
     26 
     27 // Map from a possibly-derived type to the base GC type.
     28 template <typename T>
     29 struct BaseGCType {
     30  using type =
     31      typename MapTraceKindToType<JS::MapTypeToTraceKind<T>::kind>::Type;
     32  static_assert(std::is_base_of_v<type, T>, "Failed to find base type");
     33 };
     34 
     35 template <typename T>
     36 struct TraceKindCanBeGray {};
     37 #define EXPAND_TRACEKIND_DEF(_, type, canBeGray, _1) \
     38  template <>                                        \
     39  struct TraceKindCanBeGray<type> {                  \
     40    static constexpr bool value = canBeGray;         \
     41  };
     42 JS_FOR_EACH_TRACEKIND(EXPAND_TRACEKIND_DEF)
     43 #undef EXPAND_TRACEKIND_DEF
     44 
     45 struct TraceKindCanBeGrayFunctor {
     46  template <typename T>
     47  bool operator()() {
     48    return TraceKindCanBeGray<T>::value;
     49  }
     50 };
     51 
     52 static inline bool TraceKindCanBeMarkedGray(JS::TraceKind kind) {
     53  return DispatchTraceKindTyped(TraceKindCanBeGrayFunctor(), kind);
     54 }
     55 
     56 } /* namespace gc */
     57 } /* namespace js */
     58 
     59 #endif /* gc_TraceKind_h */