zhangnaisong
2023-08-05 24d66c8d82b628a06e93dbb1abfea2049b3d45ab
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
'use strict';
 
var GetIntrinsic = require('get-intrinsic');
 
var $TypeError = GetIntrinsic('%TypeError%');
 
var callBound = require('call-bind/callBound');
var $taSome = callBound('%TypedArray.prototype.some%', true);
 
var Type = require('./Type');
 
var isTypedArray = require('is-typed-array');
 
// https://262.ecma-international.org/6.0/#sec-validatetypedarray
 
module.exports = function ValidateTypedArray(O) {
    if (Type(O) !== 'Object') {
        throw new $TypeError('Assertion failed: O must be an Object');
    }
    if (!isTypedArray(O)) {
        throw new $TypeError('Assertion failed: O must be a TypedArray');
    }
 
    // without `.some` (like in node 0.10), there's no way to check buffer detachment, but also no way to be detached
    if ($taSome) {
        $taSome(O, function () { return true; });
    }
 
    return O.buffer;
};