Commit 8ea1fd79 authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

cppgc: Port MarkingVerifier tests from Blink

Copy over from Blink two tests that the library was missing.

Bug: chromium:1056170
Change-Id: If4349e8c4dc0036f4894d274e5d38e63b0390c4b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2764751
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73462}
parent 103a42d3
......@@ -7,6 +7,7 @@
#include "include/cppgc/allocation.h"
#include "include/cppgc/member.h"
#include "include/cppgc/persistent.h"
#include "include/cppgc/prefinalizer.h"
#include "src/heap/cppgc/heap-object-header.h"
#include "src/heap/cppgc/heap.h"
#include "test/unittests/heap/cppgc/tests.h"
......@@ -145,7 +146,11 @@ TEST_F(MarkingVerifierTest, DoesntDieOnInConstructionObjectWithWriteBarrier) {
namespace {
class MarkingVerifierDeathTest : public MarkingVerifierTest {};
class MarkingVerifierDeathTest : public MarkingVerifierTest {
protected:
template <template <typename T> class Reference>
void TestResurrectingPreFinalizer();
};
} // namespace
......@@ -175,5 +180,58 @@ TEST_F(MarkingVerifierDeathTest, DieOnUnmarkedWeakMember) {
"");
}
namespace {
template <template <typename T> class Reference>
class ResurrectingPreFinalizer
: public GarbageCollected<ResurrectingPreFinalizer<Reference>> {
CPPGC_USING_PRE_FINALIZER(ResurrectingPreFinalizer<Reference>, Dispose);
public:
class Storage : public GarbageCollected<Storage> {
public:
void Trace(Visitor* visitor) const { visitor->Trace(ref); }
Reference<GCed> ref;
};
ResurrectingPreFinalizer(Storage* storage, GCed* object_that_dies)
: storage_(storage), object_that_dies_(object_that_dies) {}
void Trace(Visitor* visitor) const {
visitor->Trace(storage_);
visitor->Trace(object_that_dies_);
}
private:
void Dispose() { storage_->ref = object_that_dies_; }
Member<Storage> storage_;
Member<GCed> object_that_dies_;
};
} // namespace
template <template <typename T> class Reference>
void MarkingVerifierDeathTest::TestResurrectingPreFinalizer() {
Persistent<typename ResurrectingPreFinalizer<Reference>::Storage> storage(
MakeGarbageCollected<
typename ResurrectingPreFinalizer<Reference>::Storage>(
GetAllocationHandle()));
MakeGarbageCollected<ResurrectingPreFinalizer<Reference>>(
GetAllocationHandle(), storage.Get(),
MakeGarbageCollected<GCed>(GetAllocationHandle()));
EXPECT_DEATH_IF_SUPPORTED(PreciseGC(), "");
}
#if DEBUG
TEST_F(MarkingVerifierDeathTest, DiesOnResurrectedMember) {
TestResurrectingPreFinalizer<Member>();
}
TEST_F(MarkingVerifierDeathTest, DiesOnResurrectedWeakMember) {
TestResurrectingPreFinalizer<WeakMember>();
}
#endif // DEBUG
} // namespace internal
} // namespace cppgc
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment