blob: cd76bb1cd15f2e0b9d36aea6d2708120a5cb7959 [file] [log] [blame]
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_TRACE_TRAITS_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_TRACE_TRAITS_H_
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/heap/visitor.h"
#include "third_party/blink/renderer/platform/wtf/buildflags.h"
#include "third_party/blink/renderer/platform/wtf/hash_table.h"
#if BUILDFLAG(USE_V8_OILPAN)
#include "third_party/blink/renderer/platform/heap/v8_wrapper/trace_traits.h"
#else // !USE_V8_OILPAN
#include "third_party/blink/renderer/platform/heap/impl/trace_traits.h"
#endif // !USE_V8_OILPAN
namespace WTF {
// Catch-all for types that have a way to trace that don't have special
// handling for weakness in collections. This means that if this type
// contains WeakMember fields, they will simply be zeroed, but the entry
// will not be removed from the collection. This always happens for
// things in vectors, which don't currently support special handling of
// weak elements.
template <typename T, typename Traits>
struct TraceInCollectionTrait<kNoWeakHandling, T, Traits> {
static bool IsAlive(const blink::LivenessBroker& info, const T& t) {
return true;
}
static void Trace(blink::Visitor* visitor, const T& t) {
static_assert(IsTraceableInCollectionTrait<Traits>::value,
"T should be traceable");
visitor->Trace(t);
}
};
template <typename T, typename Traits>
struct TraceInCollectionTrait<kNoWeakHandling, blink::WeakMember<T>, Traits> {
static void Trace(blink::Visitor* visitor, const blink::WeakMember<T>& t) {
// Extract raw pointer to avoid using the WeakMember<> overload in Visitor.
visitor->TraceStrongly(t);
}
};
// Catch-all for types that have HashTrait support for tracing with weakness.
// Empty to enforce specialization.
template <typename T, typename Traits>
struct TraceInCollectionTrait<kWeakHandling, T, Traits> {};
template <typename T, typename Traits>
struct TraceInCollectionTrait<kWeakHandling, blink::WeakMember<T>, Traits> {
static bool IsAlive(const blink::LivenessBroker& info,
const blink::WeakMember<T>& value) {
return info.IsHeapObjectAlive(value);
}
};
} // namespace WTF
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_TRACE_TRAITS_H_