1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export function IndexError (index, min, max) {
|
12 | if (!(this instanceof IndexError)) {
|
13 | throw new SyntaxError('Constructor must be called with the new operator')
|
14 | }
|
15 |
|
16 | this.index = index
|
17 | if (arguments.length < 3) {
|
18 | this.min = 0
|
19 | this.max = min
|
20 | } else {
|
21 | this.min = min
|
22 | this.max = max
|
23 | }
|
24 |
|
25 | if (this.min !== undefined && this.index < this.min) {
|
26 | this.message = 'Index out of range (' + this.index + ' < ' + this.min + ')'
|
27 | } else if (this.max !== undefined && this.index >= this.max) {
|
28 | this.message = 'Index out of range (' + this.index + ' > ' + (this.max - 1) + ')'
|
29 | } else {
|
30 | this.message = 'Index out of range (' + this.index + ')'
|
31 | }
|
32 |
|
33 | this.stack = (new Error()).stack
|
34 | }
|
35 |
|
36 | IndexError.prototype = new RangeError()
|
37 | IndexError.prototype.constructor = RangeError
|
38 | IndexError.prototype.name = 'IndexError'
|
39 | IndexError.prototype.isIndexError = true
|