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: menu should not be garbage-collected when popuping #21169

Merged
merged 2 commits into from
Nov 20, 2019

Conversation

zcbenz
Copy link
Member

@zcbenz zcbenz commented Nov 18, 2019

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 from RepeatingCallback to OnceCallback, so we can ensure the strong reference is released correctly during compile time.

Checklist

Release Notes

Notes: Fix context menu disappearing when showing.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Nov 18, 2019

// Keep a weak reference to the menu.
const v8Util = process.electronBinding('v8_util')
const map = (v8Util as any).createIDWeakMap() as any
Copy link
Contributor

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?

Copy link
Contributor

@miniak miniak Nov 18, 2019

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

Copy link
Contributor

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

Copy link
Member

@deepak1556 deepak1556 left a 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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool hack 👍

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Nov 19, 2019
@miniak
Copy link
Contributor

miniak commented Nov 20, 2019

rebased to fix the unrelated flaky tests

@zcbenz zcbenz merged commit 50f2d2b into master Nov 20, 2019
@release-clerk
Copy link

release-clerk bot commented Nov 20, 2019

Release Notes Persisted

Fix context menu disappearing when showing.

@zcbenz zcbenz deleted the retain-menu-popup branch November 20, 2019 11:17
@trop
Copy link
Contributor

trop bot commented Nov 20, 2019

I was unable to backport this PR to "8-x-y" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor

trop bot commented Nov 20, 2019

I was unable to backport this PR to "7-1-x" cleanly;
you will need to perform this backport manually.

@trop trop bot removed the target/8-x-y label Nov 20, 2019
@trop
Copy link
Contributor

trop bot commented Nov 20, 2019

I was unable to backport this PR to "5-0-x" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor

trop bot commented Nov 20, 2019

I was unable to backport this PR to "6-1-x" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor

trop bot commented Nov 20, 2019

@zcbenz has manually backported this PR to "7-1-x", please check out #21225

@trop
Copy link
Contributor

trop bot commented Nov 20, 2019

@zcbenz has manually backported this PR to "6-1-x", please check out #21226

@trop
Copy link
Contributor

trop bot commented Nov 20, 2019

@zcbenz has manually backported this PR to "5-0-x", please check out #21227

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
6.1.x
Fixed in 6.1.5
7.2.x
Fixed in 7.1.3
8.2.x
Fixed in 8.0.0-beta.3
Development

Successfully merging this pull request may close these issues.

crash in AtomMenuController.menuDidClose
3 participants