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:
parent
ea23f18e94
commit
50f2d2b5ab
9 changed files with 82 additions and 33 deletions
|
@ -822,6 +822,31 @@ describe('Menu module', function () {
|
|||
menu.closePopup()
|
||||
})
|
||||
})
|
||||
|
||||
it('prevents menu from getting garbage-collected when popuping', (done) => {
|
||||
const menu = Menu.buildFromTemplate([{ role: 'paste' }])
|
||||
menu.popup({ window: w })
|
||||
|
||||
// Keep a weak reference to the menu.
|
||||
const v8Util = process.electronBinding('v8_util')
|
||||
const map = (v8Util as any).createIDWeakMap() as any
|
||||
map.set(0, menu)
|
||||
|
||||
setTimeout(() => {
|
||||
// Do garbage collection, since |menu| is not referenced in this closure
|
||||
// it would be gone after next call.
|
||||
v8Util.requestGarbageCollectionForTesting()
|
||||
setTimeout(() => {
|
||||
// Try to receive menu from weak reference.
|
||||
if (map.has(0)) {
|
||||
map.get(0).closePopup()
|
||||
done()
|
||||
} else {
|
||||
done('Menu is garbage-collected while popuping')
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Menu.setApplicationMenu', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue