source: imaps-frontend/node_modules/es-abstract/2024/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
Line 
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');
8var TypedArrayLength = require('./TypedArrayLength');
9
10var isTypedArrayWithBufferWitnessRecord = require('../helpers/records/typed-array-with-buffer-witness-record');
11
12var typedArrayByteOffset = require('typed-array-byte-offset');
13
14// https://262.ecma-international.org/15.0/#sec-validateatomicaccess
15
16module.exports = function ValidateAtomicAccess(taRecord, requestIndex) {
17 if (!isTypedArrayWithBufferWitnessRecord(taRecord)) {
18 throw new $TypeError('Assertion failed: `taRecord` must be a TypedArray With Buffer Witness Record');
19 }
20
21 var length = TypedArrayLength(taRecord); // step 1
22
23 var accessIndex = ToIndex(requestIndex); // step 2
24
25 /*
26 // this assertion can never be reached
27 if (!(accessIndex >= 0)) {
28 throw new $TypeError('Assertion failed: accessIndex >= 0'); // step 4
29 }
30 */
31
32 if (accessIndex >= length) {
33 throw new $RangeError('index out of range'); // step 4
34 }
35
36 var typedArray = taRecord['[[Object]]']; // step 5
37
38 var elementSize = TypedArrayElementSize(typedArray); // step 6
39
40 var offset = typedArrayByteOffset(typedArray); // step 7
41
42 return (accessIndex * elementSize) + offset; // step 8
43};
Note: See TracBrowser for help on using the repository browser.