fix: menu should not be garbage-collected when popuping (#21169)

* fix: retain menu when popuping

* test: menu should not be garbage-collected when popuping
This commit is contained in:
Cheng Zhao 2019-11-20 20:17:39 +09:00 committed by GitHub
parent ea23f18e94
commit 50f2d2b5ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 82 additions and 33 deletions

View file

@ -5,6 +5,7 @@
#include "shell/browser/api/atom_api_menu.h"
#include <map>
#include <utility>
#include "shell/browser/native_window.h"
#include "shell/common/gin_converters/accelerator_converter.h"
@ -217,6 +218,16 @@ void Menu::OnMenuWillShow() {
Emit("menu-will-show");
}
base::OnceClosure Menu::BindSelfToClosure(base::OnceClosure callback) {
// return ((callback, ref) => { callback() }).bind(null, callback, this)
v8::Global<v8::Value> ref(isolate(), GetWrapper());
return base::BindOnce(
[](base::OnceClosure callback, v8::Global<v8::Value> ref) {
std::move(callback).Run();
},
std::move(callback), std::move(ref));
}
// static
void Menu::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {