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