main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
620 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $RangeError = require('es-errors/range');
|
---|
| 4 |
|
---|
| 5 | var ToInteger = require('./ToInteger');
|
---|
| 6 | var ToLength = require('./ToLength');
|
---|
| 7 | var SameValueZero = require('./SameValueZero');
|
---|
| 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 = ToInteger(value);
|
---|
| 16 | if (integerIndex < 0) {
|
---|
| 17 | throw new $RangeError('index must be >= 0');
|
---|
| 18 | }
|
---|
| 19 | var index = ToLength(integerIndex);
|
---|
| 20 | if (!SameValueZero(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.