diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/embedder_test_main.cpp | 13 | ||||
-rw-r--r-- | testing/test_support.cpp | 35 | ||||
-rw-r--r-- | testing/test_support.h | 14 |
3 files changed, 32 insertions, 30 deletions
diff --git a/testing/embedder_test_main.cpp b/testing/embedder_test_main.cpp index ade6118e64..03c192b08a 100644 --- a/testing/embedder_test_main.cpp +++ b/testing/embedder_test_main.cpp @@ -34,16 +34,16 @@ class Environment : public testing::Environment { #ifdef PDF_ENABLE_V8 #ifdef V8_USE_EXTERNAL_STARTUP_DATA if (g_v8_natives && g_v8_snapshot) { - InitializeV8ForPDFium(g_exe_path, std::string(), nullptr, nullptr, - &platform_); + platform_ = + InitializeV8ForPDFium(g_exe_path, std::string(), nullptr, nullptr); } else { g_v8_natives = new v8::StartupData; g_v8_snapshot = new v8::StartupData; - InitializeV8ForPDFium(g_exe_path, std::string(), g_v8_natives, - g_v8_snapshot, &platform_); + platform_ = InitializeV8ForPDFium(g_exe_path, std::string(), g_v8_natives, + g_v8_snapshot); } #else - InitializeV8ForPDFium(g_exe_path, &platform_); + platform_ = InitializeV8ForPDFium(g_exe_path); #endif // V8_USE_EXTERNAL_STARTUP_DATA #endif // FPDF_ENABLE_V8 } @@ -51,13 +51,12 @@ class Environment : public testing::Environment { void TearDown() override { #ifdef PDF_ENABLE_V8 v8::V8::ShutdownPlatform(); - delete platform_; #endif // PDF_ENABLE_V8 } private: #ifdef PDF_ENABLE_V8 - v8::Platform* platform_; + std::unique_ptr<v8::Platform> platform_; #endif // PDF_ENABLE_V8 }; diff --git a/testing/test_support.cpp b/testing/test_support.cpp index b32ec7de96..f682451c27 100644 --- a/testing/test_support.cpp +++ b/testing/test_support.cpp @@ -60,17 +60,18 @@ bool GetExternalData(const std::string& exe_path, } #endif // V8_USE_EXTERNAL_STARTUP_DATA -void InitializeV8Common(const char* exe_path, v8::Platform** platform) { +std::unique_ptr<v8::Platform> InitializeV8Common(const char* exe_path) { v8::V8::InitializeICUDefaultLocation(exe_path); - *platform = v8::platform::CreateDefaultPlatform(); - v8::V8::InitializePlatform(*platform); + std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform(); + v8::V8::InitializePlatform(platform.get()); // By enabling predictable mode, V8 won't post any background tasks. // By enabling GC, it makes it easier to chase use-after-free. const char v8_flags[] = "--predictable --expose-gc"; v8::V8::SetFlagsFromString(v8_flags, static_cast<int>(strlen(v8_flags))); v8::V8::Initialize(); + return platform; } #endif // PDF_ENABLE_V8 @@ -177,27 +178,29 @@ std::string GenerateMD5Base16(const uint8_t* data, uint32_t size) { #ifdef PDF_ENABLE_V8 #ifdef V8_USE_EXTERNAL_STARTUP_DATA -bool InitializeV8ForPDFium(const std::string& exe_path, - const std::string& bin_dir, - v8::StartupData* natives_blob, - v8::StartupData* snapshot_blob, - v8::Platform** platform) { - InitializeV8Common(exe_path.c_str(), platform); +std::unique_ptr<v8::Platform> InitializeV8ForPDFium( + const std::string& exe_path, + const std::string& bin_dir, + v8::StartupData* natives_blob, + v8::StartupData* snapshot_blob) { + std::unique_ptr<v8::Platform> platform = InitializeV8Common(exe_path.c_str()); if (natives_blob && snapshot_blob) { if (!GetExternalData(exe_path, bin_dir, "natives_blob.bin", natives_blob)) - return false; + return nullptr; if (!GetExternalData(exe_path, bin_dir, "snapshot_blob.bin", snapshot_blob)) - return false; + return nullptr; v8::V8::SetNativesDataBlob(natives_blob); v8::V8::SetSnapshotDataBlob(snapshot_blob); } - return true; + return platform; } #else // V8_USE_EXTERNAL_STARTUP_DATA -bool InitializeV8ForPDFium(const std::string& exe_path, - v8::Platform** platform) { - InitializeV8Common(exe_path.c_str(), platform); - return true; +std::unique_ptr<v8::Platform> InitializeV8ForPDFium( + const std::string& exe_path, + std::unique_ptr<v8::Platform>* platform) { + std::unique_ptr<v8::Platform> platform = + InitializeV8Common(exe_path.c_str(), platform); + return platform; } #endif // V8_USE_EXTERNAL_STARTUP_DATA #endif // PDF_ENABLE_V8 diff --git a/testing/test_support.h b/testing/test_support.h index ec4b4aeacb..1b7692c3ed 100644 --- a/testing/test_support.h +++ b/testing/test_support.h @@ -91,14 +91,14 @@ class Platform; namespace v8 { class StartupData; } -bool InitializeV8ForPDFium(const std::string& exe_path, - const std::string& bin_dir, - v8::StartupData* natives_blob, - v8::StartupData* snapshot_blob, - v8::Platform** platform); +std::unique_ptr<v8::Platform> InitializeV8ForPDFium( + const std::string& exe_path, + const std::string& bin_dir, + v8::StartupData* natives_blob, + v8::StartupData* snapshot_blob); #else // V8_USE_EXTERNAL_STARTUP_DATA -bool InitializeV8ForPDFium(const std::string& exe_path, - v8::Platform** platform); +std::unique_ptr<v8::Platform> InitializeV8ForPDFium( + const std::string& exe_path); #endif // V8_USE_EXTERNAL_STARTUP_DATA #endif // PDF_ENABLE_V8 |