to-index.js 457 B

1234567891011121314
  1. var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
  2. var toLength = require('../internals/to-length');
  3. var $RangeError = RangeError;
  4. // `ToIndex` abstract operation
  5. // https://tc39.es/ecma262/#sec-toindex
  6. module.exports = function (it) {
  7. if (it === undefined) return 0;
  8. var number = toIntegerOrInfinity(it);
  9. var length = toLength(number);
  10. if (number !== length) throw $RangeError('Wrong length or index');
  11. return length;
  12. };