source: imaps-frontend/node_modules/es-abstract/2018/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.7 KB
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var IsDetachedBuffer = require('./IsDetachedBuffer');
6var IsInteger = require('./IsInteger');
7var SetValueInBuffer = require('./SetValueInBuffer');
8var ToNumber = require('./ToNumber');
9
10var isNegativeZero = require('is-negative-zero');
11var typedArrayBuffer = require('typed-array-buffer');
12var typedArrayByteOffset = require('typed-array-byte-offset');
13var typedArrayLength = require('typed-array-length');
14var whichTypedArray = require('which-typed-array');
15
16var tableTAO = require('./tables/typed-array-objects');
17
18// https://262.ecma-international.org/8.0/#sec-integerindexedelementset
19
20module.exports = function IntegerIndexedElementSet(O, index, value) {
21 if (typeof index !== 'number') {
22 throw new $TypeError('`index` must be a Number'); // step 1
23 }
24 var arrayTypeName = whichTypedArray(O); // step 12
25 if (!arrayTypeName) {
26 throw new $TypeError('`O` must be a TypedArray'); // step 2
27 }
28
29 var numValue = ToNumber(value); // step 3
30
31 var buffer = typedArrayBuffer(O); // step 5
32
33 if (IsDetachedBuffer(buffer)) {
34 throw new $TypeError('`O` has a detached buffer'); // step 6
35 }
36
37 if (!IsInteger(index) || isNegativeZero(index)) {
38 return false; // steps 7 - 8
39 }
40
41 var length = typedArrayLength(O); // step 9
42
43 if (index < 0 || index >= length) {
44 return false; // step 10
45 }
46
47 var offset = typedArrayByteOffset(O); // step 11
48
49 var elementType = tableTAO.name['$' + arrayTypeName]; // step 15
50
51 var elementSize = tableTAO.size['$' + elementType]; // step 13
52
53 var indexedPosition = (index * elementSize) + offset; // step 14
54
55 SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, 'Unordered'); // step 16
56
57 return true; // step 17
58};
Note: See TracBrowser for help on using the repository browser.