Pass actual isolate to GetForegroundTaskRunner()
Makes XFA PDFium/Oilpan compatible with Chrome/Gin.
Bug: chromium:1121682
Change-Id: I17349bd1fd159009351cbaa152b77aa8386ffdf1
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/73116
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@google.com>
diff --git a/fxjs/gc/heap.cpp b/fxjs/gc/heap.cpp
index 404ee10..46ab7d0 100644
--- a/fxjs/gc/heap.cpp
+++ b/fxjs/gc/heap.cpp
@@ -5,15 +5,20 @@
#include "fxjs/gc/heap.h"
#include "core/fxcrt/fx_system.h"
+#include "core/fxcrt/unowned_ptr.h"
#include "third_party/base/ptr_util.h"
namespace {
size_t g_platform_ref_count = 0;
v8::Platform* g_platform = nullptr;
+v8::Isolate* g_isolate = nullptr;
} // namespace
+// Taken from v8/samples/cppgc/cppgc-for-v8-embedders.cc.
+// Adaptper that makes the global v8::Platform compatible with a
+// cppgc::Platform.
class CFXGC_Platform final : public cppgc::Platform {
public:
CFXGC_Platform() = default;
@@ -31,7 +36,7 @@
// V8's default platform creates a new task runner when passed the
// v8::Isolate pointer the first time. For non-default platforms this will
// require getting the appropriate task runner.
- return g_platform->GetForegroundTaskRunner(nullptr);
+ return g_platform->GetForegroundTaskRunner(g_isolate);
}
std::unique_ptr<cppgc::JobHandle> PostJob(
@@ -41,10 +46,11 @@
}
};
-void FXGC_Initialize(v8::Platform* platform) {
+void FXGC_Initialize(v8::Platform* platform, v8::Isolate* isolate) {
if (platform) {
ASSERT(!g_platform);
g_platform = platform;
+ g_isolate = isolate;
cppgc::InitializeProcess(platform->GetPageAllocator());
}
}
@@ -53,6 +59,7 @@
if (g_platform && g_platform_ref_count == 0) {
cppgc::ShutdownProcess();
g_platform = nullptr;
+ g_isolate = nullptr;
}
}
diff --git a/fxjs/gc/heap.h b/fxjs/gc/heap.h
index bf60833..1ac90a4 100644
--- a/fxjs/gc/heap.h
+++ b/fxjs/gc/heap.h
@@ -11,13 +11,18 @@
#include "v8/include/cppgc/heap.h"
#include "v8/include/libplatform/libplatform.h"
+namespace v8 {
+class Isolate;
+class Platform;
+} // namespace v8
+
struct FXGCHeapDeleter {
void operator()(cppgc::Heap* heap);
};
using FXGCScopedHeap = std::unique_ptr<cppgc::Heap, FXGCHeapDeleter>;
-void FXGC_Initialize(v8::Platform* platform);
+void FXGC_Initialize(v8::Platform* platform, v8::Isolate* isolate);
void FXGC_Release();
FXGCScopedHeap FXGC_CreateHeap();
void FXGC_ForceGarbageCollection(cppgc::Heap* heap);
diff --git a/fxjs/ijs_runtime.cpp b/fxjs/ijs_runtime.cpp
index b5d3f4a..496d662 100644
--- a/fxjs/ijs_runtime.cpp
+++ b/fxjs/ijs_runtime.cpp
@@ -26,7 +26,8 @@
#ifdef PDF_ENABLE_V8
FXJS_Initialize(slot, static_cast<v8::Isolate*>(isolate));
#ifdef PDF_ENABLE_XFA
- FXGC_Initialize(static_cast<v8::Platform*>(platform));
+ FXGC_Initialize(static_cast<v8::Platform*>(platform),
+ static_cast<v8::Isolate*>(isolate));
#endif // PDF_ENABLE_XFA
#endif // PDF_ENABLE_V8
}
diff --git a/testing/fxgc_unittest.cpp b/testing/fxgc_unittest.cpp
index 3c54ee6..0e467cf 100644
--- a/testing/fxgc_unittest.cpp
+++ b/testing/fxgc_unittest.cpp
@@ -14,7 +14,7 @@
void FXGCUnitTest::SetUp() {
FXV8UnitTest::SetUp();
- FXGC_Initialize(V8TestEnvironment::GetInstance()->platform());
+ FXGC_Initialize(V8TestEnvironment::GetInstance()->platform(), nullptr);
heap_ = FXGC_CreateHeap();
ASSERT_TRUE(heap_);
}