'f'
mh-two-thousand-and-two
2024-04-12 26f2711ef9461961fb953e2b497bd314ef95e345
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict';
 
var $TypeError = require('es-errors/type');
 
var IsTypedArrayOutOfBounds = require('./IsTypedArrayOutOfBounds');
var MakeTypedArrayWithBufferWitnessRecord = require('./MakeTypedArrayWithBufferWitnessRecord');
var Type = require('./Type');
 
var isTypedArray = require('is-typed-array');
 
// https://262.ecma-international.org/15.0/#sec-validatetypedarray
 
module.exports = function ValidateTypedArray(O, order) {
    if (order !== 'SEQ-CST' && order !== 'UNORDERED') {
        throw new $TypeError('Assertion failed: `order` must be ~SEQ-CST~ or ~UNORDERED~');
    }
 
    if (Type(O) !== 'Object') {
        throw new $TypeError('Assertion failed: `O` must be an Object'); // step 1
    }
    if (!isTypedArray(O)) {
        throw new $TypeError('Assertion failed: `O` must be a Typed Array'); // steps 1 - 2
    }
 
    var taRecord = MakeTypedArrayWithBufferWitnessRecord(O, order); // step 3
 
    if (IsTypedArrayOutOfBounds(taRecord)) {
        throw new $TypeError('`O` must be in-bounds and backed by a non-detached buffer'); // step 4
    }
 
    return taRecord; // step 5
};