From 9d54fdfd12742bc8ffd46aad3e8676d4f18aedd8 Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Mon, 23 Nov 2020 22:41:06 -0800 Subject: [PATCH] fix: crash on exit in Event destructor (#26537) --- shell/browser/api/event.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/shell/browser/api/event.cc b/shell/browser/api/event.cc index f5bec3a41fca..648e1a280e2a 100644 --- a/shell/browser/api/event.cc +++ b/shell/browser/api/event.cc @@ -21,11 +21,15 @@ Event::Event() {} Event::~Event() { if (callback_) { v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate(); - v8::HandleScope scope(isolate); - auto message = gin::DataObjectBuilder(isolate) - .Set("error", "reply was never sent") - .Build(); - SendReply(isolate, message); + // 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") + .Build(); + SendReply(isolate, message); + } } } @@ -62,7 +66,7 @@ gin::ObjectTemplateBuilder Event::GetObjectTemplateBuilder( } const char* Event::GetTypeName() { - return "WebRequest"; + return "Event"; } // static