mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
fix: throw error when inserting menu items out-of-range (#17401)
* fix: throw error when inserting menu items out-of-range * also check pos < 0
This commit is contained in:
@@ -110,6 +110,12 @@ Menu.prototype.insert = function (pos, item) {
|
||||
throw new TypeError('Invalid item')
|
||||
}
|
||||
|
||||
if (pos < 0) {
|
||||
throw new RangeError(`Position ${pos} cannot be less than 0`)
|
||||
} else if (pos > this.getItemCount()) {
|
||||
throw new RangeError(`Position ${pos} cannot be greater than the total MenuItem count`)
|
||||
}
|
||||
|
||||
// insert item depending on its type
|
||||
insertItemByType.call(this, item, pos)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user