forked from josdejong/mathjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArgumentsError.js
More file actions
30 lines (26 loc) · 1 KB
/
ArgumentsError.js
File metadata and controls
30 lines (26 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* Create a syntax error with the message:
* 'Wrong number of arguments in function <fn> (<count> provided, <min>-<max> expected)'
* @param {string} fn Function name
* @param {number} count Actual argument count
* @param {number} min Minimum required argument count
* @param {number} [max] Maximum required argument count
* @extends Error
*/
export function ArgumentsError (fn, count, min, max) {
if (!(this instanceof ArgumentsError)) {
throw new SyntaxError('Constructor must be called with the new operator')
}
this.fn = fn
this.count = count
this.min = min
this.max = max
this.message = 'Wrong number of arguments in function ' + fn +
' (' + count + ' provided, ' +
min + ((max !== undefined && max !== null) ? ('-' + max) : '') + ' expected)'
this.stack = (new Error()).stack
}
ArgumentsError.prototype = new Error()
ArgumentsError.prototype.constructor = Error
ArgumentsError.prototype.name = 'ArgumentsError'
ArgumentsError.prototype.isArgumentsError = true