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