Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / js / src / gc / TraceKind.h
blobfdcb162239661a1443e9401fb4835434a5606436
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/. */
7 #ifndef gc_TraceKind_h
8 #define gc_TraceKind_h
10 #include "js/TraceKind.h"
12 namespace js {
13 namespace gc {
15 // Map from all trace kinds to the base GC type.
16 template <JS::TraceKind kind>
17 struct MapTraceKindToType {};
19 #define DEFINE_TRACE_KIND_MAP(name, type, _, _1) \
20 template <> \
21 struct MapTraceKindToType<JS::TraceKind::name> { \
22 using Type = type; \
24 JS_FOR_EACH_TRACEKIND(DEFINE_TRACE_KIND_MAP);
25 #undef DEFINE_TRACE_KIND_MAP
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");
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; \
42 JS_FOR_EACH_TRACEKIND(EXPAND_TRACEKIND_DEF)
43 #undef EXPAND_TRACEKIND_DEF
45 struct TraceKindCanBeGrayFunctor {
46 template <typename T>
47 bool operator()() {
48 return TraceKindCanBeGray<T>::value;
52 static inline bool TraceKindCanBeMarkedGray(JS::TraceKind kind) {
53 return DispatchTraceKindTyped(TraceKindCanBeGrayFunctor(), kind);
56 } /* namespace gc */
57 } /* namespace js */
59 #endif /* gc_TraceKind_h */