Commit 60ba2206 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

cppgc: Remove explit setter to enable testing features

cppgc/testing.h is already part of a testonly gn target which only can
be included from other test targets. This prevents any production
target to depend on cppgc/testing.h.

Bug: chromium:1056170
Change-Id: I51f6c47ffac2a05c8c63d7b4663c456a64fe75b4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2689196Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72670}
parent bdf74a17
......@@ -15,28 +15,9 @@ class HeapHandle;
/**
* Namespace contains testing helpers.
* Helpers are only enabled after invoking `Heap::EnableTestingAPIsForTesting()`
and will crash otherwise.
*/
namespace testing {
/**
* Testing helper used to acces heap internals.
* Only enabled after invoking `EnableTestingAPIsForTesting()`.
*/
class V8_EXPORT Heap final {
public:
/**
* Enables testing APIs that can be found in the corresponding `testing`
* namespace.
*
* \param heap_handle
*/
static void EnableTestingAPIsForTesting(HeapHandle& heap_handle);
};
/**
* Overrides the state of the stack with the provided value. Takes precedence
* over other parameters that set the stack state. Must no be nested.
......
......@@ -54,20 +54,6 @@ class ObjectSizeCounter : private HeapVisitor<ObjectSizeCounter> {
} // namespace
// static
HeapBase& HeapBase::ForTesting(cppgc::HeapHandle& heap_handle) {
auto& heap = From(heap_handle);
CHECK(heap.TestingEnabled());
return heap;
}
// static
const HeapBase& HeapBase::ForTesting(const cppgc::HeapHandle& heap_handle) {
const auto& heap = From(heap_handle);
CHECK(heap.TestingEnabled());
return heap;
}
HeapBase::HeapBase(
std::shared_ptr<cppgc::Platform> platform,
const std::vector<std::unique_ptr<CustomSpaceBase>>& custom_spaces,
......
......@@ -71,9 +71,6 @@ class V8_EXPORT_PRIVATE HeapBase : public cppgc::HeapHandle {
return static_cast<const HeapBase&>(heap_handle);
}
static HeapBase& ForTesting(cppgc::HeapHandle& heap_handle);
static const HeapBase& ForTesting(const cppgc::HeapHandle& heap_handle);
HeapBase(std::shared_ptr<cppgc::Platform> platform,
const std::vector<std::unique_ptr<CustomSpaceBase>>& custom_spaces,
StackSupport stack_support,
......@@ -161,9 +158,6 @@ class V8_EXPORT_PRIVATE HeapBase : public cppgc::HeapHandle {
bool in_disallow_gc_scope() const { return disallow_gc_scope_ > 0; }
bool in_atomic_pause() const { return in_atomic_pause_; }
void EnableTestingAPIsForTesting() { testing_enabled_ = true; }
bool TestingEnabled() const { return testing_enabled_; }
HeapStatistics CollectStatistics(HeapStatistics::DetailLevel);
protected:
......@@ -206,7 +200,6 @@ class V8_EXPORT_PRIVATE HeapBase : public cppgc::HeapHandle {
std::unique_ptr<EmbedderStackState> override_stack_state_;
bool in_atomic_pause_ = false;
bool testing_enabled_ = false;
friend class MarkerBase::IncrementalMarkingTask;
friend class testing::TestWithHeap;
......
......@@ -10,20 +10,16 @@
namespace cppgc {
namespace testing {
void Heap::EnableTestingAPIsForTesting(HeapHandle& heap_handle) {
internal::HeapBase::From(heap_handle).EnableTestingAPIsForTesting();
}
OverrideEmbedderStackStateScope::OverrideEmbedderStackStateScope(
HeapHandle& heap_handle, EmbedderStackState state)
: heap_handle_(heap_handle) {
auto& heap = internal::HeapBase::ForTesting(heap_handle_);
auto& heap = internal::HeapBase::From(heap_handle_);
CHECK_NULL(heap.override_stack_state_.get());
heap.override_stack_state_ = std::make_unique<EmbedderStackState>(state);
}
OverrideEmbedderStackStateScope::~OverrideEmbedderStackStateScope() {
auto& heap = internal::HeapBase::ForTesting(heap_handle_);
auto& heap = internal::HeapBase::From(heap_handle_);
heap.override_stack_state_.reset();
}
......
......@@ -22,13 +22,7 @@ class GCed : public GarbageCollected<GCed> {
};
} // namespace
TEST_F(TestingTest, EnableTesting) {
EXPECT_FALSE(internal::Heap::From(GetHeap())->TestingEnabled());
cppgc::testing::Heap::EnableTestingAPIsForTesting(GetHeap()->GetHeapHandle());
EXPECT_TRUE(internal::Heap::From(GetHeap())->TestingEnabled());
}
TEST_F(TestingTest, OverrideEmbedderStackStateScope) {
TEST_F(TestingTest, OverrideEmbeddertackStateScope) {
{
auto* gced = MakeGarbageCollected<GCed>(GetHeap()->GetAllocationHandle());
WeakPersistent<GCed> weak{gced};
......@@ -36,7 +30,6 @@ TEST_F(TestingTest, OverrideEmbedderStackStateScope) {
Heap::Config::PreciseAtomicConfig());
EXPECT_FALSE(weak);
}
cppgc::testing::Heap::EnableTestingAPIsForTesting(GetHeap()->GetHeapHandle());
{
auto* gced = MakeGarbageCollected<GCed>(GetHeap()->GetAllocationHandle());
WeakPersistent<GCed> weak{gced};
......
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