diff --git a/lib/browser/api/menu.js b/lib/browser/api/menu.js index 0ee05a06edd9..421462671fbf 100644 --- a/lib/browser/api/menu.js +++ b/lib/browser/api/menu.js @@ -132,40 +132,31 @@ Menu.prototype._init = function () { } Menu.prototype.popup = function (window, x, y, positioningItem) { + let [newX, newY, newPositioningItem] = [x, y, positioningItem] let asyncPopup // menu.popup(x, y, positioningItem) - if (window != null && (typeof window !== 'object' || window.constructor !== BrowserWindow)) { - // Shift. - positioningItem = y - y = x - x = window - window = null + if (window != null) { + if (typeof window !== 'object' || window.constructor !== BrowserWindow) { + [newPositioningItem, newY, newX] = [y, x, window] + window = null + } } // menu.popup(window, {}) if (x != null && typeof x === 'object') { - const options = x - x = options.x - y = options.y - positioningItem = options.positioningItem - asyncPopup = options.async + [newX, newY, newPositioningItem] = [x.x, x.y, x.positioningItem] + asyncPopup = x.async } - // Default to showing in focused window. + // set up defaults if (window == null) window = BrowserWindow.getFocusedWindow() - - // Default to showing under mouse location. - if (typeof x !== 'number') x = -1 - if (typeof y !== 'number') y = -1 - - // Default to not highlighting any item. - if (typeof positioningItem !== 'number') positioningItem = -1 - - // Default to synchronous for backwards compatibility. + if (typeof x !== 'number') newX = -1 + if (typeof y !== 'number') newY = -1 + if (typeof positioningItem !== 'number') newPositioningItem = -1 if (typeof asyncPopup !== 'boolean') asyncPopup = false - this.popupAt(window, x, y, positioningItem, asyncPopup) + this.popupAt(window, newX, newY, newPositioningItem, asyncPopup) } Menu.prototype.closePopup = function (window) {