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