// Copyright 2020 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "include/cppgc/member.h" #include #include #include "include/cppgc/allocation.h" #include "include/cppgc/garbage-collected.h" #include "include/cppgc/internal/member-storage.h" #include "include/cppgc/persistent.h" #include "include/cppgc/sentinel-pointer.h" #include "include/cppgc/type-traits.h" #include "test/unittests/heap/cppgc/tests.h" #include "testing/gtest/include/gtest/gtest.h" namespace cppgc { namespace internal { namespace { struct GCed : GarbageCollected { double d; virtual void Trace(cppgc::Visitor*) const {} }; struct DerivedMixin : GarbageCollectedMixin { void Trace(cppgc::Visitor* v) const override {} }; struct DerivedGCed : GCed, DerivedMixin { void Trace(cppgc::Visitor* v) const override { GCed::Trace(v); } }; // Compile tests. static_assert(!IsWeakV>, "Member is always strong."); static_assert(IsWeakV>, "WeakMember is always weak."); static_assert(IsMemberTypeV>, "Member must be Member."); static_assert(!IsMemberTypeV>, "WeakMember must not be Member."); static_assert(!IsMemberTypeV>, "UntracedMember must not be Member."); static_assert(!IsMemberTypeV, "int must not be Member."); static_assert(!IsWeakMemberTypeV>, "Member must not be WeakMember."); static_assert(IsWeakMemberTypeV>, "WeakMember must be WeakMember."); static_assert(!IsWeakMemberTypeV>, "UntracedMember must not be WeakMember."); static_assert(!IsWeakMemberTypeV, "int must not be WeakMember."); static_assert(!IsUntracedMemberTypeV>, "Member must not be UntracedMember."); static_assert(!IsUntracedMemberTypeV>, "WeakMember must not be UntracedMember."); static_assert(IsUntracedMemberTypeV>, "UntracedMember must be UntracedMember."); static_assert(!IsUntracedMemberTypeV, "int must not be UntracedMember."); struct CustomWriteBarrierPolicy { static size_t InitializingWriteBarriersTriggered; static size_t AssigningWriteBarriersTriggered; static void InitializingBarrier(const void* slot, const void* value) { ++InitializingWriteBarriersTriggered; } template static void AssigningBarrier(const void* slot, const void* value) { ++AssigningWriteBarriersTriggered; } template static void AssigningBarrier(const void* slot, DefaultMemberStorage) { ++AssigningWriteBarriersTriggered; } }; size_t CustomWriteBarrierPolicy::InitializingWriteBarriersTriggered = 0; size_t CustomWriteBarrierPolicy::AssigningWriteBarriersTriggered = 0; using MemberWithCustomBarrier = BasicMember; struct CustomCheckingPolicy { static std::vector Cached; static size_t ChecksTriggered; void CheckPointer(const void* ptr) { EXPECT_NE(Cached.cend(), std::find(Cached.cbegin(), Cached.cend(), ptr)); ++ChecksTriggered; } }; std::vector CustomCheckingPolicy::Cached; size_t CustomCheckingPolicy::ChecksTriggered = 0; using MemberWithCustomChecking = BasicMember; class MemberTest : public testing::TestSupportingAllocationOnly {}; } // namespace template