source: imaps-frontend/node_modules/es-abstract/2024/IsValidIntegerIndex.js

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: 1.4 KB
RevLine 
[d565449]1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var IsDetachedBuffer = require('./IsDetachedBuffer');
6var IsIntegralNumber = require('./IsIntegralNumber');
7var IsTypedArrayOutOfBounds = require('./IsTypedArrayOutOfBounds');
8var MakeTypedArrayWithBufferWitnessRecord = require('./MakeTypedArrayWithBufferWitnessRecord');
9var TypedArrayLength = require('./TypedArrayLength');
10
11var isNegativeZero = require('../helpers/isNegativeZero');
12
13var isTypedArray = require('is-typed-array');
14var typedArrayBuffer = require('typed-array-buffer');
15
16// https://262.ecma-international.org/15.0/#sec-isvalidintegerindex
17
18module.exports = function IsValidIntegerIndex(O, index) {
19 if (!isTypedArray(O)) {
20 throw new $TypeError('Assertion failed: `O` is not a TypedArray object');
21 }
22 if (typeof index !== 'number') {
23 throw new $TypeError('Assertion failed: `index` is not a Number');
24 }
25
26 var buffer = typedArrayBuffer(O);
27
28 if (IsDetachedBuffer(buffer)) { return false; } // step 1
29
30 if (!IsIntegralNumber(index)) { return false; } // step 2
31
32 if (isNegativeZero(index)) { return false; } // step 3
33
34 var taRecord = MakeTypedArrayWithBufferWitnessRecord(O, 'UNORDERED'); // step 4
35 if (IsTypedArrayOutOfBounds(taRecord)) {
36 return false; // step 6
37 }
38 var length = TypedArrayLength(taRecord); // step 7
39
40 if (index < 0 || index >= length) { return false; } // step 8
41
42 return true; // step 9
43};
Note: See TracBrowser for help on using the repository browser.