source: imaps-frontend/node_modules/es-abstract/2020/IsValidIntegerIndex.js@ d565449

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: 841 bytes
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var IsInteger = require('./IsInteger');
6
7var isNegativeZero = require('../helpers/isNegativeZero');
8
9var isTypedArray = require('is-typed-array');
10var typedArrayBuffer = require('typed-array-buffer');
11
12// https://262.ecma-international.org/11.0/#sec-isvalidintegerindex
13
14module.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.