Projekt

Obecné

Profil

Stáhnout (679 Bajtů) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
'use strict';
2
3
var GetIntrinsic = require('../GetIntrinsic');
4
5
var $RangeError = GetIntrinsic('%RangeError%');
6
7
var ToInteger = require('./ToInteger');
8
var ToLength = require('./ToLength');
9
var SameValueZero = require('./SameValueZero');
10
11
// https://www.ecma-international.org/ecma-262/8.0/#sec-toindex
12
13
module.exports = function ToIndex(value) {
14
	if (typeof value === 'undefined') {
15
		return 0;
16
	}
17
	var integerIndex = ToInteger(value);
18
	if (integerIndex < 0) {
19
		throw new $RangeError('index must be >= 0');
20
	}
21
	var index = ToLength(integerIndex);
22
	if (!SameValueZero(integerIndex, index)) {
23
		throw new $RangeError('index must be >= 0 and < 2 ** 53 - 1');
24
	}
25
	return index;
26
};