don't reassign parameters in Menu.prototype.popup

This commit is contained in:
Shelley Vohr 2017-10-24 00:07:39 -04:00
parent b1e707d535
commit f93121b226
No known key found for this signature in database
GPG key ID: F13993A75599653C

View file

@ -11,7 +11,8 @@ let groupIdIndex = 0
Object.setPrototypeOf(Menu.prototype, EventEmitter.prototype) Object.setPrototypeOf(Menu.prototype, EventEmitter.prototype)
// cleaned up /* Instance Methods */
Menu.prototype._init = function () { Menu.prototype._init = function () {
this.commandsMap = {} this.commandsMap = {}
this.groupsMap = {} this.groupsMap = {}
@ -45,39 +46,33 @@ Menu.prototype._init = function () {
// create and show a popup // create and show a popup
Menu.prototype.popup = function (window, x, y, positioningItem) { Menu.prototype.popup = function (window, x, y, positioningItem) {
let asyncPopup let asyncPopup
let [newX, newY, newPosition, newWindow] = [x, y, positioningItem, window]
// menu.popup(x, y, positioningItem) // menu.popup(x, y, positioningItem)
if (window != null && (typeof window !== 'object' || window.constructor !== BrowserWindow)) { if (window !== null) {
// Shift. // shift over values
positioningItem = y if (typeof window !== 'object' || window.constructor !== BrowserWindow) {
y = x [newPosition, newY, newX, newWindow] = [y, x, window, null]
x = window }
window = null
} }
// menu.popup(window, {}) // menu.popup(window, {})
if (x != null && typeof x === 'object') { if (x !== null && typeof x === 'object') {
const options = x const opts = x
x = options.x newX = opts.x
y = options.y newY = opts.y
positioningItem = options.positioningItem newPosition = opts.positioningItem
asyncPopup = options.async asyncPopup = opts.async
} }
// Default to showing in focused window. // set defaults
if (window == null) window = BrowserWindow.getFocusedWindow() if (typeof x !== 'number') newX = -1
if (typeof y !== 'number') newY = -1
// Default to showing under mouse location. if (typeof positioningItem !== 'number') newPosition = -1
if (typeof x !== 'number') x = -1 if (window === null) newWindow = BrowserWindow.getFocusedWindow()
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 asyncPopup !== 'boolean') asyncPopup = false if (typeof asyncPopup !== 'boolean') asyncPopup = false
this.popupAt(window, x, y, positioningItem, asyncPopup) this.popupAt(newWindow, newX, newY, newPosition, asyncPopup)
} }
// close an existing popup // close an existing popup
@ -138,6 +133,8 @@ Menu.prototype._callMenuWillShow = function () {
}) })
} }
/* Static Methods */
// return application menu // return application menu
Menu.getApplicationMenu = () => applicationMenu Menu.getApplicationMenu = () => applicationMenu
@ -187,7 +184,7 @@ Menu.buildFromTemplate = function (template) {
return menu return menu
} }
/* Helper Methods */ /* Helper Functions */
// Search between separators to find a radio menu item and return its group id // Search between separators to find a radio menu item and return its group id
function generateGroupId (items, pos) { function generateGroupId (items, pos) {