source: imaps-frontend/node_modules/es-abstract/2021/ValidateAtomicAccess.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.3 KB
RevLine 
[d565449]1'use strict';
2
3var $RangeError = require('es-errors/range');
4var $TypeError = require('es-errors/type');
5
6var ToIndex = require('./ToIndex');
7
8var isTypedArray = require('is-typed-array');
9var typedArrayByteOffset = require('typed-array-byte-offset');
10var typedArrayLength = require('typed-array-length');
11var whichTypedArray = require('which-typed-array');
12
13var tableTAO = require('./tables/typed-array-objects');
14
15// https://262.ecma-international.org/12.0/#sec-validateatomicaccess
16
17module.exports = function ValidateAtomicAccess(typedArray, requestIndex) {
18 if (!isTypedArray(typedArray)) {
19 throw new $TypeError('Assertion failed: `typedArray` must be a TypedArray'); // step 1
20 }
21
22 var length = typedArrayLength(typedArray); // step 2
23
24 var accessIndex = ToIndex(requestIndex); // step 3
25
26 /*
27 // this assertion can never be reached
28 if (!(accessIndex >= 0)) {
29 throw new $TypeError('Assertion failed: accessIndex >= 0'); // step 4
30 }
31 */
32
33 if (accessIndex >= length) {
34 throw new $RangeError('index out of range'); // step 5
35 }
36
37 var arrayTypeName = whichTypedArray(typedArray); // step 6
38
39 var taType = tableTAO.name['$' + arrayTypeName];
40 var elementSize = tableTAO.size['$' + taType]; // step 7
41
42 var offset = typedArrayByteOffset(typedArray); // step 8
43
44 return (accessIndex * elementSize) + offset; // step 9
45};
Note: See TracBrowser for help on using the repository browser.