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