simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

ArgumentsError.js (1013B)


      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 
     15   this.fn = fn;
     16   this.count = count;
     17   this.min = min;
     18   this.max = max;
     19   this.message = 'Wrong number of arguments in function ' + fn + ' (' + count + ' provided, ' + min + (max !== undefined && max !== null ? '-' + max : '') + ' expected)';
     20   this.stack = new Error().stack;
     21 }
     22 ArgumentsError.prototype = new Error();
     23 ArgumentsError.prototype.constructor = Error;
     24 ArgumentsError.prototype.name = 'ArgumentsError';
     25 ArgumentsError.prototype.isArgumentsError = true;