Browse Source

Merge pull request #11961 from electron/fix-bw-callback

add conditional for menu.popup(window, callback)
shelley vohr 7 years ago
parent
commit
459a5e3a1f
2 changed files with 8 additions and 2 deletions
  1. 3 2
      lib/browser/api/menu.js
  2. 5 0
      spec/api-menu-spec.js

+ 3 - 2
lib/browser/api/menu.js

@@ -58,8 +58,9 @@ Menu.prototype.popup = function (window, x, y, positioningItem) {
     callback = newPosition
   }
 
-  // menu.popup({})
-  if (window != null && window.constructor === Object) {
+  // menu.popup({}) || menu.popup(window, callback)
+  if ((window != null && window.constructor === Object) ||
+      (x && typeof x === 'function')) {
     opts = window
     callback = arguments[1]
   // menu.popup(window, {})

+ 5 - 0
spec/api-menu-spec.js

@@ -383,6 +383,11 @@ describe('Menu module', () => {
       assert.equal(y, 101)
     })
 
+    it('works with a given BrowserWindow, no options, and a callback', (done) => {
+      menu.popup(w, () => done())
+      menu.closePopup()
+    })
+
     it('calls the callback', (done) => {
       menu.popup({}, () => done())
       menu.closePopup()