main
Last change
on this file 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 | var TypedArrayElementSize = require('./TypedArrayElementSize');
|
---|
8 | var TypedArrayElementType = require('./TypedArrayElementType');
|
---|
9 |
|
---|
10 | var isTypedArray = require('is-typed-array');
|
---|
11 | var typedArrayBuffer = require('typed-array-buffer');
|
---|
12 | var typedArrayByteOffset = require('typed-array-byte-offset');
|
---|
13 |
|
---|
14 | // https://262.ecma-international.org/13.0/#sec-integerindexedelementget
|
---|
15 |
|
---|
16 | module.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.