-
Notifications
You must be signed in to change notification settings - Fork 15k
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: menu should not be garbage-collected when popuping #21169
Conversation
|
||
// Keep a weak reference to the menu. | ||
const v8Util = process.electronBinding('v8_util') | ||
const map = (v8Util as any).createIDWeakMap() as any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add createIDWeakMap()
to V8UtilBinding
in typings/internal-ambient.d.ts
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just created a PR to make this type-safe
ref #21171
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's merge this one first, I will fix this in the other PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool hack 👍
2556f12
to
c9905d4
Compare
rebased to fix the unrelated flaky tests |
Release Notes Persisted
|
I was unable to backport this PR to "8-x-y" cleanly; |
I was unable to backport this PR to "7-1-x" cleanly; |
I was unable to backport this PR to "5-0-x" cleanly; |
I was unable to backport this PR to "6-1-x" cleanly; |
Description of Change
Fixes #20737
This PR makes sure the Menu object is being retained when popuping, so it won't be garbage-collected until the menu is closed. This is done by keeping a strong reference to the menu when
popup
is called, and release it when the close callback is called.Most changes in this PR are about changing the callback of
popup
fromRepeatingCallback
toOnceCallback
, so we can ensure the strong reference is released correctly during compile time.Checklist
npm test
passesRelease Notes
Notes: Fix context menu disappearing when showing.