source: imaps-frontend/node_modules/es-abstract/2023/IntegerIndexedElementSet.js

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.5 KB
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var IsValidIntegerIndex = require('./IsValidIntegerIndex');
6var SetValueInBuffer = require('./SetValueInBuffer');
7var ToBigInt = require('./ToBigInt');
8var ToNumber = require('./ToNumber');
9var TypedArrayElementSize = require('./TypedArrayElementSize');
10var TypedArrayElementType = require('./TypedArrayElementType');
11
12var typedArrayBuffer = require('typed-array-buffer');
13var typedArrayByteOffset = require('typed-array-byte-offset');
14var whichTypedArray = require('which-typed-array');
15
16// https://262.ecma-international.org/13.0/#sec-integerindexedelementset
17
18module.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};
Note: See TracBrowser for help on using the repository browser.