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