Commit 5d433b2d authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[fuzzer] Use std::unique_ptr for the FuzzerSupport

The FuzzerSupport was keeping a single instance of itself. With this CL,
this instance is now stored in a unique_ptr. Therefore it is not
necessary to register an onExit callback to delete the FuzzerSupport
instance.

Drive-by changes: Some cleanup with the FuzzerSupport.

R=clemensh@chromium.org

Bug: chromium:787723
Change-Id: I5188c7aa7e778ccd45fc80ed0115c947d23a0dee
Reviewed-on: https://chromium-review.googlesource.com/792949Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49723}
parent 5ff7af93
...@@ -14,19 +14,6 @@ ...@@ -14,19 +14,6 @@
namespace v8_fuzzer { namespace v8_fuzzer {
namespace {
FuzzerSupport* g_fuzzer_support = nullptr;
void DeleteFuzzerSupport() {
if (g_fuzzer_support) {
delete g_fuzzer_support;
g_fuzzer_support = nullptr;
}
}
} // namespace
FuzzerSupport::FuzzerSupport(int* argc, char*** argv) { FuzzerSupport::FuzzerSupport(int* argc, char*** argv) {
v8::internal::FLAG_expose_gc = true; v8::internal::FLAG_expose_gc = true;
v8::V8::SetFlagsFromCommandLine(argc, *argv, true); v8::V8::SetFlagsFromCommandLine(argc, *argv, true);
...@@ -72,10 +59,20 @@ FuzzerSupport::~FuzzerSupport() { ...@@ -72,10 +59,20 @@ FuzzerSupport::~FuzzerSupport() {
v8::V8::ShutdownPlatform(); v8::V8::ShutdownPlatform();
} }
std::unique_ptr<FuzzerSupport> FuzzerSupport::fuzzer_support_;
// static // static
FuzzerSupport* FuzzerSupport::Get() { return g_fuzzer_support; } void FuzzerSupport::InitializeFuzzerSupport(int* argc, char*** argv) {
DCHECK_NULL(FuzzerSupport::fuzzer_support_);
FuzzerSupport::fuzzer_support_ =
v8::base::make_unique<v8_fuzzer::FuzzerSupport>(argc, argv);
}
v8::Isolate* FuzzerSupport::GetIsolate() const { return isolate_; } // static
FuzzerSupport* FuzzerSupport::Get() {
DCHECK_NOT_NULL(FuzzerSupport::fuzzer_support_);
return FuzzerSupport::fuzzer_support_.get();
}
v8::Local<v8::Context> FuzzerSupport::GetContext() { v8::Local<v8::Context> FuzzerSupport::GetContext() {
v8::Isolate::Scope isolate_scope(isolate_); v8::Isolate::Scope isolate_scope(isolate_);
...@@ -93,7 +90,6 @@ bool FuzzerSupport::PumpMessageLoop( ...@@ -93,7 +90,6 @@ bool FuzzerSupport::PumpMessageLoop(
} // namespace v8_fuzzer } // namespace v8_fuzzer
extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
v8_fuzzer::g_fuzzer_support = new v8_fuzzer::FuzzerSupport(argc, argv); v8_fuzzer::FuzzerSupport::InitializeFuzzerSupport(argc, argv);
atexit(&v8_fuzzer::DeleteFuzzerSupport);
return 0; return 0;
} }
...@@ -13,12 +13,17 @@ namespace v8_fuzzer { ...@@ -13,12 +13,17 @@ namespace v8_fuzzer {
class FuzzerSupport { class FuzzerSupport {
public: public:
FuzzerSupport(int* argc, char*** argv); FuzzerSupport(int* argc, char*** argv);
~FuzzerSupport(); ~FuzzerSupport();
static void InitializeFuzzerSupport(int* argc, char*** argv);
static FuzzerSupport* Get(); static FuzzerSupport* Get();
v8::Isolate* GetIsolate() const; v8::Isolate* GetIsolate() const { return isolate_; }
v8::Local<v8::Context> GetContext(); v8::Local<v8::Context> GetContext();
bool PumpMessageLoop(v8::platform::MessageLoopBehavior = bool PumpMessageLoop(v8::platform::MessageLoopBehavior =
v8::platform::MessageLoopBehavior::kDoNotWait); v8::platform::MessageLoopBehavior::kDoNotWait);
...@@ -27,6 +32,7 @@ class FuzzerSupport { ...@@ -27,6 +32,7 @@ class FuzzerSupport {
FuzzerSupport(const FuzzerSupport&); FuzzerSupport(const FuzzerSupport&);
FuzzerSupport& operator=(const FuzzerSupport&); FuzzerSupport& operator=(const FuzzerSupport&);
static std::unique_ptr<FuzzerSupport> fuzzer_support_;
std::unique_ptr<v8::Platform> platform_; std::unique_ptr<v8::Platform> platform_;
v8::ArrayBuffer::Allocator* allocator_; v8::ArrayBuffer::Allocator* allocator_;
v8::Isolate* isolate_; v8::Isolate* isolate_;
......
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