source: imaps-frontend/node_modules/es-abstract/2015/IntegerIndexedElementGet.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[d565449]1'use strict';
2
3var $SyntaxError = require('es-errors/syntax');
4var $TypeError = require('es-errors/type');
[79a0317]5var isNegativeZero = require('math-intrinsics/isNegativeZero');
[d565449]6
7var GetValueFromBuffer = require('./GetValueFromBuffer');
8var IsDetachedBuffer = require('./IsDetachedBuffer');
9var IsInteger = require('./IsInteger');
10
11var typedArrayLength = require('typed-array-length');
12var typedArrayBuffer = require('typed-array-buffer');
13var typedArrayByteOffset = require('typed-array-byte-offset');
14var whichTypedArray = require('which-typed-array');
15
16var tableTAO = require('./tables/typed-array-objects');
17
18// https://262.ecma-international.org/6.0/#sec-integerindexedelementget
19
20module.exports = function IntegerIndexedElementGet(O, index) {
21 if (typeof index !== 'number') {
22 throw new $TypeError('`index` must be a Number'); // step 1
23 }
24 var arrayTypeName = whichTypedArray(O); // step 10
25 if (!arrayTypeName) {
26 throw new $TypeError('`O` must be a TypedArray'); // step 2
27 }
28 if (arrayTypeName === 'BigInt64Array' || arrayTypeName === 'BigUint64Array') {
29 throw new $SyntaxError('BigInt64Array and BigUint64Array do not exist until ES2020');
30 }
31
32 var buffer = typedArrayBuffer(O); // step 3
33
34 if (IsDetachedBuffer(buffer)) {
35 throw new $TypeError('`O` has a detached buffer'); // step 4
36 }
37
38 if (!IsInteger(index) || isNegativeZero(index)) {
39 return void undefined; // steps 5 - 6
40 }
41
42 var length = typedArrayLength(O); // step 7
43
44 if (index < 0 || index >= length) {
45 return void undefined; // step 8
46 }
47
48 var offset = typedArrayByteOffset(O); // step 9
49
50 var elementType = tableTAO.name['$' + arrayTypeName]; // step 13
51
52 var elementSize = tableTAO.size['$' + elementType]; // step 11
53
54 var indexedPosition = (index * elementSize) + offset; // step 12
55
56 return GetValueFromBuffer(buffer, indexedPosition, elementType); // step 14
57};
Note: See TracBrowser for help on using the repository browser.