diff --git a/shell/browser/api/atom_api_menu.cc b/shell/browser/api/atom_api_menu.cc index 5acdc0f0edde2..8e52ad8e7f45a 100644 --- a/shell/browser/api/atom_api_menu.cc +++ b/shell/browser/api/atom_api_menu.cc @@ -4,6 +4,7 @@ #include "shell/browser/api/atom_api_menu.h" +#include #include #include "native_mate/constructor.h" @@ -16,6 +17,13 @@ #include "shell/common/native_mate_converters/string16_converter.h" #include "shell/common/node_includes.h" +namespace { +// We need this map to keep references to currently opened menus. +// Without this menus would be destroyed by js garbage collector +// even when they are still displayed. +std::map> g_menus; +} // unnamed namespace + namespace electron { namespace api { @@ -202,10 +210,12 @@ bool Menu::WorksWhenHiddenAt(int index) const { } void Menu::OnMenuWillClose() { + g_menus.erase(weak_map_id()); Emit("menu-will-close"); } void Menu::OnMenuWillShow() { + g_menus[weak_map_id()] = v8::Global(isolate(), GetWrapper()); Emit("menu-will-show"); }