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:
Shelley Vohr 2019-03-18 07:58:42 -07:00 committed by GitHub
parent f09f43a4a9
commit db29978fe0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

@ -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)