ArgumentsError.js 1012 B

123456789101112131415161718192021222324
  1. /**
  2. * Create a syntax error with the message:
  3. * 'Wrong number of arguments in function <fn> (<count> provided, <min>-<max> expected)'
  4. * @param {string} fn Function name
  5. * @param {number} count Actual argument count
  6. * @param {number} min Minimum required argument count
  7. * @param {number} [max] Maximum required argument count
  8. * @extends Error
  9. */
  10. export function ArgumentsError(fn, count, min, max) {
  11. if (!(this instanceof ArgumentsError)) {
  12. throw new SyntaxError('Constructor must be called with the new operator');
  13. }
  14. this.fn = fn;
  15. this.count = count;
  16. this.min = min;
  17. this.max = max;
  18. this.message = 'Wrong number of arguments in function ' + fn + ' (' + count + ' provided, ' + min + (max !== undefined && max !== null ? '-' + max : '') + ' expected)';
  19. this.stack = new Error().stack;
  20. }
  21. ArgumentsError.prototype = new Error();
  22. ArgumentsError.prototype.constructor = Error;
  23. ArgumentsError.prototype.name = 'ArgumentsError';
  24. ArgumentsError.prototype.isArgumentsError = true;