fix: crash on exit in Event destructor (#26537)

This commit is contained in:
Jeremy Rose 2020-11-23 22:41:06 -08:00 committed by GitHub
parent b894151745
commit 9d54fdfd12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,9 @@ Event::Event() {}
Event::~Event() {
if (callback_) {
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
// If there's no current context, it means we're shutting down, so we don't
// need to send an event.
if (!isolate->GetCurrentContext().IsEmpty()) {
v8::HandleScope scope(isolate);
auto message = gin::DataObjectBuilder(isolate)
.Set("error", "reply was never sent")
@ -28,6 +31,7 @@ Event::~Event() {
SendReply(isolate, message);
}
}
}
void Event::SetCallback(InvokeCallback callback) {
DCHECK(!callback_);
@ -62,7 +66,7 @@ gin::ObjectTemplateBuilder Event::GetObjectTemplateBuilder(
}
const char* Event::GetTypeName() {
return "WebRequest";
return "Event";
}
// static