UNPKG

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