From fb8b1fd1c97a0e5cd62d5c4d27538c5b4afecee8 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 28 Oct 2019 11:26:48 -0700 Subject: [PATCH] fix: prevent menu gc during popup (#20745) --- shell/browser/api/atom_api_menu.h | 1 + shell/browser/api/atom_api_menu_mac.mm | 3 +++ shell/browser/api/atom_api_menu_views.cc | 3 +++ 3 files changed, 7 insertions(+) diff --git a/shell/browser/api/atom_api_menu.h b/shell/browser/api/atom_api_menu.h index 4263f8c8443b..a31b18278801 100644 --- a/shell/browser/api/atom_api_menu.h +++ b/shell/browser/api/atom_api_menu.h @@ -12,6 +12,7 @@ #include "gin/arguments.h" #include "shell/browser/api/atom_api_top_level_window.h" #include "shell/browser/ui/atom_menu_model.h" +#include "shell/common/api/locker.h" #include "shell/common/gin_helper/trackable_object.h" namespace electron { diff --git a/shell/browser/api/atom_api_menu_mac.mm b/shell/browser/api/atom_api_menu_mac.mm index 246918ab22dc..7cda00005adc 100644 --- a/shell/browser/api/atom_api_menu_mac.mm +++ b/shell/browser/api/atom_api_menu_mac.mm @@ -56,6 +56,9 @@ void MenuMac::PopupOnUI(const base::WeakPtr& native_window, int y, int positioning_item, base::Closure callback) { + mate::Locker locker(isolate()); + v8::HandleScope handle_scope(isolate()); + if (!native_window) return; NSWindow* nswindow = native_window->GetNativeWindow().GetNativeNSWindow(); diff --git a/shell/browser/api/atom_api_menu_views.cc b/shell/browser/api/atom_api_menu_views.cc index fa51699dbd98..f2f6aa7f9633 100644 --- a/shell/browser/api/atom_api_menu_views.cc +++ b/shell/browser/api/atom_api_menu_views.cc @@ -25,6 +25,9 @@ void MenuViews::PopupAt(TopLevelWindow* window, int y, int positioning_item, const base::Closure& callback) { + mate::Locker locker(isolate()); + v8::HandleScope handle_scope(isolate()); + auto* native_window = static_cast(window->window()); if (!native_window) return;