chore: stop leaking v8 environment (#22761)

This commit is contained in:
Jeremy Apthorp 2020-03-20 14:15:55 -07:00 committed by GitHub
parent 22c17bcc5b
commit 07a049ef1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 22 deletions

View file

@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/no_destructor.h"
#include "gin/dictionary.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/node_includes.h"
@ -13,11 +14,14 @@
namespace {
v8::Global<v8::Object> event_emitter_prototype;
v8::Global<v8::Object>* GetEventEmitterPrototypeReference() {
static base::NoDestructor<v8::Global<v8::Object>> event_emitter_prototype;
return event_emitter_prototype.get();
}
void SetEventEmitterPrototype(v8::Isolate* isolate,
v8::Local<v8::Object> proto) {
event_emitter_prototype.Reset(isolate, proto);
GetEventEmitterPrototypeReference()->Reset(isolate, proto);
}
void Initialize(v8::Local<v8::Object> exports,
@ -36,8 +40,8 @@ void Initialize(v8::Local<v8::Object> exports,
namespace electron {
v8::Local<v8::Object> GetEventEmitterPrototype(v8::Isolate* isolate) {
CHECK(!event_emitter_prototype.IsEmpty());
return event_emitter_prototype.Get(isolate);
CHECK(!GetEventEmitterPrototypeReference()->IsEmpty());
return GetEventEmitterPrototypeReference()->Get(isolate);
}
} // namespace electron