mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
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) : '') + ' expected)';
|
|
|
|
this.stack = (new Error()).stack;
|
|
}
|
|
|
|
ArgumentsError.prototype = new Error();
|
|
ArgumentsError.prototype.constructor = Error;
|
|
ArgumentsError.prototype.name = 'ArgumentsError';
|
|
ArgumentsError.prototype.isArgumentsError = true;
|
|
|
|
module.exports = ArgumentsError;
|