ArgumentsError.js 1.1 KB

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