Minor improvements for FXGC code.
- Remove dead code in FXGCHeapDeleter, with tests.
- Fix a typo in the existing HeapEmbedderTest.
- Sprinkle some more asserts in heap.cpp.
Change-Id: Ib7bb2a56da6f96547285619a66b8a05cfadddf50
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/70771
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/gc/heap.cpp b/fxjs/gc/heap.cpp
index d75c675..9dade5c 100644
--- a/fxjs/gc/heap.cpp
+++ b/fxjs/gc/heap.cpp
@@ -4,6 +4,7 @@
#include "fxjs/gc/heap.h"
+#include "core/fxcrt/fx_system.h"
#include "third_party/base/ptr_util.h"
namespace {
@@ -42,6 +43,7 @@
void FXGC_Initialize(v8::Platform* platform) {
if (platform) {
+ ASSERT(!g_platform);
g_platform = platform;
cppgc::InitializeProcess(platform->GetPageAllocator());
}
@@ -68,9 +70,8 @@
}
void FXGCHeapDeleter::operator()(cppgc::Heap* heap) {
- if (!heap)
- return;
-
+ ASSERT(heap);
+ ASSERT(g_platform_ref_count > 0);
--g_platform_ref_count;
delete heap;
}
diff --git a/fxjs/gc/heap_embeddertest.cpp b/fxjs/gc/heap_embeddertest.cpp
index 5f77914..4930d44 100644
--- a/fxjs/gc/heap_embeddertest.cpp
+++ b/fxjs/gc/heap_embeddertest.cpp
@@ -58,7 +58,13 @@
EXPECT_TRUE(heap2);
FXGCScopedHeap heap3 = FXGC_CreateHeap();
- EXPECT_TRUE(heap2);
+ EXPECT_TRUE(heap3);
+
+ // Test manually destroying the heap.
+ heap3.reset();
+ EXPECT_FALSE(heap3);
+ heap3.reset();
+ EXPECT_FALSE(heap3);
}
TEST_F(HeapEmbedderTest, NoReferences) {