#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_VECTOR_BACKING_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_COLLECTION_SUPPORT_HEAP_VECTOR_BACKING_H_
#include <type_traits>
#include "base/check_op.h"
#include "third_party/blink/renderer/platform/heap/custom_spaces.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/heap/thread_state_storage.h"
#include "third_party/blink/renderer/platform/heap/trace_traits.h"
#include "third_party/blink/renderer/platform/wtf/container_annotations.h"
#include "third_party/blink/renderer/platform/wtf/sanitizers.h"
#include "third_party/blink/renderer/platform/wtf/type_traits.h"
#include "third_party/blink/renderer/platform/wtf/vector_traits.h"
#include "v8/include/cppgc/allocation.h"
#include "v8/include/cppgc/custom-space.h"
#include "v8/include/cppgc/explicit-management.h"
#include "v8/include/cppgc/object-size-trait.h"
#include "v8/include/cppgc/trace-trait.h"
#include "v8/include/cppgc/visitor.h"
namespace blink {
namespace internal {
inline bool VTableInitialized(const void* object_payload) { … }
}
template <typename T, typename Traits = WTF::VectorTraits<T>>
class HeapVectorBacking final
: public GarbageCollected<HeapVectorBacking<T, Traits>> {
public:
using ClassType = HeapVectorBacking<T, Traits>;
using TraitsType = Traits;
ALWAYS_INLINE NO_SANITIZE_UNRELATED_CAST static T* ToArray(
ClassType* backing) { … }
ALWAYS_INLINE static ClassType* FromArray(T* payload) { … }
void Free(cppgc::HeapHandle& heap_handle) { … }
bool Resize(size_t new_size) { … }
~HeapVectorBacking()
requires(!Traits::kNeedsDestruction)
= default;
~HeapVectorBacking()
requires(Traits::kNeedsDestruction);
private:
static cppgc::AdditionalBytes GetAdditionalBytes(size_t wanted_array_size) { … }
};
template <typename T, typename Traits>
HeapVectorBacking<T, Traits>::~HeapVectorBacking()
requires(Traits::kNeedsDestruction)
{ … }
ThreadingTrait<HeapVectorBacking<T, Traits>>;
}
namespace WTF {
TraceInCollectionTrait<kNoWeakHandling, blink::HeapVectorBacking<T, Traits>, void>;
}
namespace cppgc {
SpaceTrait<blink::HeapVectorBacking<T>, std::enable_if_t<blink::HeapVectorBacking<T>::TraitsType::kCanMoveWithMemcpy>>;
MakeGarbageCollectedTrait<blink::HeapVectorBacking<T>>;
TraceTrait<blink::HeapVectorBacking<T, Traits>>;
}
#endif