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:
841 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $TypeError = require('es-errors/type');
|
---|
| 4 |
|
---|
| 5 | var IsInteger = require('./IsInteger');
|
---|
| 6 |
|
---|
| 7 | var isNegativeZero = require('../helpers/isNegativeZero');
|
---|
| 8 |
|
---|
| 9 | var isTypedArray = require('is-typed-array');
|
---|
| 10 | var typedArrayBuffer = require('typed-array-buffer');
|
---|
| 11 |
|
---|
| 12 | // https://262.ecma-international.org/11.0/#sec-isvalidintegerindex
|
---|
| 13 |
|
---|
| 14 | module.exports = function IsValidIntegerIndex(O, index) {
|
---|
| 15 | if (!isTypedArray) {
|
---|
| 16 | throw new $TypeError('Assertion failed: `O` must be a Typed Array');
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | typedArrayBuffer(O); // step 1
|
---|
| 20 |
|
---|
| 21 | if (typeof index !== 'number') {
|
---|
| 22 | throw new $TypeError('Assertion failed: Type(index) is not Number'); // step 2
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | if (!IsInteger(index)) { return false; } // step 3
|
---|
| 26 |
|
---|
| 27 | if (isNegativeZero(index)) { return false; } // step 4
|
---|
| 28 |
|
---|
| 29 | if (index < 0 || index >= O.length) { return false; } // step 5
|
---|
| 30 |
|
---|
| 31 | return true; // step 6
|
---|
| 32 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.