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

chore: keep references to active menus to prevent gc #19427

Merged
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
11 changes: 11 additions & 0 deletions shell/browser/api/atom_api_menu.cc
Expand Up @@ -4,6 +4,8 @@

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

#include <map>

#include "native_mate/constructor.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
Expand All @@ -14,6 +16,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;
codebytere marked this conversation as resolved.
Show resolved Hide resolved
} // unnamed namespace

namespace electron {

namespace api {
Expand Down Expand Up @@ -200,10 +209,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