From 89b90be6a2429663c769be4837d90e95ae858e84 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Mon, 11 Dec 2017 14:43:35 -0800 Subject: [PATCH] :wrench: Feedback --- lib/browser/api/menu.js | 4 ++-- spec/api-menu-spec.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/browser/api/menu.js b/lib/browser/api/menu.js index d4a2aafb7934..787fd596f65c 100644 --- a/lib/browser/api/menu.js +++ b/lib/browser/api/menu.js @@ -48,12 +48,12 @@ Menu.prototype.popup = function (window, x, y, positioningItem) { let opts // menu.popup(x, y, positioningItem) - if (window && typeof window !== 'object' || window.constructor !== BrowserWindow) { + if (window != null && !(window instanceof BrowserWindow)) { [newPosition, newY, newX, newWindow] = [y, x, window, null] } // menu.popup({}) - if (typeof window === 'object' && window.constructor !== BrowserWindow) { + if (window && window.constructor !== BrowserWindow) { opts = window // menu.popup(window, {}) } else if (x && typeof x === 'object') { diff --git a/spec/api-menu-spec.js b/spec/api-menu-spec.js index b61db17baacc..75a77813a179 100644 --- a/spec/api-menu-spec.js +++ b/spec/api-menu-spec.js @@ -312,6 +312,16 @@ describe('Menu module', () => { menu.closePopup() }) + it('works without a given BrowserWindow and 0 options', () => { + const { browserWindow, x, y } = menu.popup(0, 1) + + assert.equal(browserWindow.constructor.name, 'BrowserWindow') + assert.equal(x, 0) + assert.equal(y, 1) + + menu.closePopup() + }) + it('works with a given BrowserWindow and no options', () => { const { browserWindow, x, y } = menu.popup(w, 100, 101)