source: imaps-frontend/node_modules/es-abstract/2021/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
RevLine 
[d565449]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');
9
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/12.0/#sec-integerindexedelementset
17
18module.exports = function IntegerIndexedElementSet(O, index, value) {
19 if (typeof index !== 'number') {
20 throw new $TypeError('Assertion failed: `index` must be a Number');
21 }
22
23 var arrayTypeName = whichTypedArray(O); // step 4.b
24 if (!arrayTypeName) {
25 throw new $TypeError('Assertion failed: `O` must be a TypedArray'); // step 1
26 }
27
28 var contentType = arrayTypeName === 'BigInt64Array' || arrayTypeName === 'BigUint64Array' ? 'BigInt' : 'Number';
29 var numValue = contentType === 'BigInt' ? ToBigInt(value) : ToNumber(value); // steps 2 - 3
30
31 if (IsValidIntegerIndex(O, index)) { // step 4
32 var offset = typedArrayByteOffset(O); // step 4.a
33
34 var elementType = tableTAO.name['$' + arrayTypeName]; // step 4.e
35
36 var elementSize = tableTAO.size['$' + elementType]; // step 4.c
37
38 var indexedPosition = (index * elementSize) + offset; // step 4.d
39
40 SetValueInBuffer(typedArrayBuffer(O), indexedPosition, elementType, numValue, true, 'Unordered'); // step 4.e
41 }
42
43 // 5. Return NormalCompletion(undefined)
44};
Note: See TracBrowser for help on using the repository browser.