main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
638 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var $RangeError = require('es-errors/range');
|
---|
4 |
|
---|
5 | var ToIntegerOrInfinity = require('./ToIntegerOrInfinity');
|
---|
6 | var ToLength = require('./ToLength');
|
---|
7 | var SameValue = require('./SameValue');
|
---|
8 |
|
---|
9 | // https://262.ecma-international.org/8.0/#sec-toindex
|
---|
10 |
|
---|
11 | module.exports = function ToIndex(value) {
|
---|
12 | if (typeof value === 'undefined') {
|
---|
13 | return 0;
|
---|
14 | }
|
---|
15 | var integerIndex = ToIntegerOrInfinity(value);
|
---|
16 | if (integerIndex < 0) {
|
---|
17 | throw new $RangeError('index must be >= 0');
|
---|
18 | }
|
---|
19 | var index = ToLength(integerIndex);
|
---|
20 | if (!SameValue(integerIndex, index)) {
|
---|
21 | throw new $RangeError('index must be >= 0 and < 2 ** 53 - 1');
|
---|
22 | }
|
---|
23 | return index;
|
---|
24 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.