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 |
|
---|
3 | var $TypeError = require('es-errors/type');
|
---|
4 |
|
---|
5 | var GetValueFromBuffer = require('./GetValueFromBuffer');
|
---|
6 | var IsValidIntegerIndex = require('./IsValidIntegerIndex');
|
---|
7 |
|
---|
8 | var typedArrayBuffer = require('typed-array-buffer');
|
---|
9 | var typedArrayByteOffset = require('typed-array-byte-offset');
|
---|
10 | var whichTypedArray = require('which-typed-array');
|
---|
11 |
|
---|
12 | var tableTAO = require('./tables/typed-array-objects');
|
---|
13 |
|
---|
14 | // https://262.ecma-international.org/12.0/#sec-integerindexedelementget
|
---|
15 |
|
---|
16 | module.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.