source: imaps-frontend/node_modules/es-abstract/2022/IntegerIndexedElementGet.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: 1.2 KB
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var GetValueFromBuffer = require('./GetValueFromBuffer');
6var IsValidIntegerIndex = require('./IsValidIntegerIndex');
7var TypedArrayElementSize = require('./TypedArrayElementSize');
8var TypedArrayElementType = require('./TypedArrayElementType');
9
10var isTypedArray = require('is-typed-array');
11var typedArrayBuffer = require('typed-array-buffer');
12var typedArrayByteOffset = require('typed-array-byte-offset');
13
14// https://262.ecma-international.org/13.0/#sec-integerindexedelementget
15
16module.exports = function IntegerIndexedElementGet(O, index) {
17 if (!isTypedArray(O)) {
18 throw new $TypeError('Assertion failed: `O` must be a TypedArray');
19 }
20
21 if (typeof index !== 'number') {
22 throw new $TypeError('Assertion failed: `index` must be a Number');
23 }
24
25 if (!IsValidIntegerIndex(O, index)) {
26 return void undefined; // step 1
27 }
28
29 var offset = typedArrayByteOffset(O); // step 2
30
31 var elementSize = TypedArrayElementSize(O); // step 3
32
33 var indexedPosition = (index * elementSize) + offset; // step 4
34
35 var elementType = TypedArrayElementType(O); // step 5
36
37 return GetValueFromBuffer(typedArrayBuffer(O), indexedPosition, elementType, true, 'Unordered'); // step 11
38};
Note: See TracBrowser for help on using the repository browser.