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:
parent
f09f43a4a9
commit
db29978fe0
2 changed files with 24 additions and 0 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue