Merge pull request #11055 from electron/fix-menu-bug

fix: Don't crash on `setApplicationMenu(null)`
This commit is contained in:
Samuel Attard 2017-11-11 14:33:18 +11:00 committed by GitHub
commit ba754cf5c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View file

@ -133,7 +133,7 @@ Menu.sendActionToFirstResponder = bindings.sendActionToFirstResponder
// set application menu with a preexisting menu // set application menu with a preexisting menu
Menu.setApplicationMenu = function (menu) { Menu.setApplicationMenu = function (menu) {
if (!(menu || menu.constructor === Menu)) { if (menu && menu.constructor !== Menu) {
throw new TypeError('Invalid menu') throw new TypeError('Invalid menu')
} }

View file

@ -291,15 +291,22 @@ describe('Menu module', () => {
}) })
describe('Menu.setApplicationMenu', () => { describe('Menu.setApplicationMenu', () => {
const menu = Menu.buildFromTemplate([ it('sets a menu', () => {
{ const menu = Menu.buildFromTemplate([
label: '1' {
}, { label: '1'
label: '2' }, {
} label: '2'
]) }
Menu.setApplicationMenu(menu) ])
assert.notEqual(Menu.getApplicationMenu(), null) Menu.setApplicationMenu(menu)
assert.notEqual(Menu.getApplicationMenu(), null)
})
it('unsets a menu with null', () => {
Menu.setApplicationMenu(null)
assert.equal(Menu.getApplicationMenu(), null)
})
}) })
describe('MenuItem.click', () => { describe('MenuItem.click', () => {