source: imaps-frontend/node_modules/es-abstract/2017/IntegerIndexedElementSet.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[d565449]1'use strict';
2
[79a0317]3var $SyntaxError = require('es-errors/syntax');
[d565449]4var $TypeError = require('es-errors/type');
5
6var IsDetachedBuffer = require('./IsDetachedBuffer');
7var IsInteger = require('./IsInteger');
8var SetValueInBuffer = require('./SetValueInBuffer');
9var ToNumber = require('./ToNumber');
10
[79a0317]11var isNegativeZero = require('math-intrinsics/isNegativeZero');
[d565449]12var typedArrayBuffer = require('typed-array-buffer');
13var typedArrayByteOffset = require('typed-array-byte-offset');
14var typedArrayLength = require('typed-array-length');
15var whichTypedArray = require('which-typed-array');
16
17var tableTAO = require('./tables/typed-array-objects');
18
19// https://262.ecma-international.org/8.0/#sec-integerindexedelementset
20
21module.exports = function IntegerIndexedElementSet(O, index, value) {
22 if (typeof index !== 'number') {
23 throw new $TypeError('`index` must be a Number'); // step 1
24 }
25 var arrayTypeName = whichTypedArray(O); // step 12
26 if (!arrayTypeName) {
27 throw new $TypeError('`O` must be a TypedArray'); // step 2
28 }
[79a0317]29 if (arrayTypeName === 'BigInt64Array' || arrayTypeName === 'BigUint64Array') {
30 throw new $SyntaxError('BigInt64Array and BigUint64Array do not exist until ES2020'); // step 2
31 }
[d565449]32
33 var numValue = ToNumber(value); // step 3
34
35 var buffer = typedArrayBuffer(O); // step 5
36
37 if (IsDetachedBuffer(buffer)) {
38 throw new $TypeError('`O` has a detached buffer'); // step 6
39 }
40
41 if (!IsInteger(index) || isNegativeZero(index)) {
42 return false; // steps 7 - 8
43 }
44
45 var length = typedArrayLength(O); // step 9
46
47 if (index < 0 || index >= length) {
48 return false; // step 10
49 }
50
51 var offset = typedArrayByteOffset(O); // step 11
52
53 var elementType = tableTAO.name['$' + arrayTypeName]; // step 15
54
55 var elementSize = tableTAO.size['$' + elementType]; // step 13
56
57 var indexedPosition = (index * elementSize) + offset; // step 14
58
59 SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, 'Unordered'); // step 16
60
61 return true; // step 17
62};
Note: See TracBrowser for help on using the repository browser.