Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: keep references to active menus created by api Menu #22151

Merged
merged 1 commit into from Feb 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions shell/browser/api/atom_api_menu.cc
Expand Up @@ -4,6 +4,7 @@

#include "shell/browser/api/atom_api_menu.h"

#include <map>
#include <utility>

#include "native_mate/constructor.h"
Expand All @@ -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<uint32_t, v8::Global<v8::Object>> g_menus;
} // unnamed namespace

namespace electron {

namespace api {
Expand Down Expand Up @@ -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<v8::Object>(isolate(), GetWrapper());
Emit("menu-will-show");
}

Expand Down