[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $TypeError = require('es-errors/type');
|
---|
| 4 |
|
---|
| 5 | var IsValidIntegerIndex = require('./IsValidIntegerIndex');
|
---|
| 6 | var SetValueInBuffer = require('./SetValueInBuffer');
|
---|
| 7 | var ToBigInt = require('./ToBigInt');
|
---|
| 8 | var ToNumber = require('./ToNumber');
|
---|
| 9 | var TypedArrayElementSize = require('./TypedArrayElementSize');
|
---|
| 10 | var TypedArrayElementType = require('./TypedArrayElementType');
|
---|
| 11 |
|
---|
| 12 | var typedArrayBuffer = require('typed-array-buffer');
|
---|
| 13 | var typedArrayByteOffset = require('typed-array-byte-offset');
|
---|
| 14 | var whichTypedArray = require('which-typed-array');
|
---|
| 15 |
|
---|
| 16 | // https://262.ecma-international.org/13.0/#sec-integerindexedelementset
|
---|
| 17 |
|
---|
| 18 | module.exports = function IntegerIndexedElementSet(O, index, value) {
|
---|
| 19 | var arrayTypeName = whichTypedArray(O);
|
---|
| 20 | if (!arrayTypeName) {
|
---|
| 21 | throw new $TypeError('Assertion failed: `O` must be a TypedArray');
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | if (typeof index !== 'number') {
|
---|
| 25 | throw new $TypeError('Assertion failed: `index` must be a Number');
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | var contentType = arrayTypeName === 'BigInt64Array' || arrayTypeName === 'BigUint64Array' ? 'BigInt' : 'Number';
|
---|
| 29 | var numValue = contentType === 'BigInt' ? ToBigInt(value) : ToNumber(value); // steps 1 - 2
|
---|
| 30 |
|
---|
| 31 | if (IsValidIntegerIndex(O, index)) { // step 3
|
---|
| 32 | var offset = typedArrayByteOffset(O); // step 3.a
|
---|
| 33 |
|
---|
| 34 | var elementSize = TypedArrayElementSize(O); // step 3.b
|
---|
| 35 |
|
---|
| 36 | var indexedPosition = (index * elementSize) + offset; // step 3.c
|
---|
| 37 |
|
---|
| 38 | var elementType = TypedArrayElementType(O); // step 3.d
|
---|
| 39 |
|
---|
| 40 | SetValueInBuffer(typedArrayBuffer(O), indexedPosition, elementType, numValue, true, 'Unordered'); // step 3.e
|
---|
| 41 | }
|
---|
| 42 | };
|
---|