'a'
mh-two-thousand-and-two
2024-04-12 44d2c92345cd156a59fc327b3060292a282d2893
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
33
34
35
36
37
'use strict';
 
var $SyntaxError = require('es-errors/syntax');
var $TypeError = require('es-errors/type');
 
var whichTypedArray = require('which-typed-array');
var availableTypedArrays = require('available-typed-arrays')();
 
var IsArray = require('./IsArray');
var SpeciesConstructor = require('./SpeciesConstructor');
var TypedArrayCreate = require('./TypedArrayCreate');
 
var getConstructor = require('../helpers/typedArrayConstructors');
 
// https://262.ecma-international.org/7.0/#typedarray-species-create
 
module.exports = function TypedArraySpeciesCreate(exemplar, argumentList) {
    if (availableTypedArrays.length === 0) {
        throw new $SyntaxError('Assertion failed: Typed Arrays are not supported in this environment');
    }
 
    var kind = whichTypedArray(exemplar);
    if (!kind) {
        throw new $TypeError('Assertion failed: exemplar must be a TypedArray'); // step 1
    }
    if (!IsArray(argumentList)) {
        throw new $TypeError('Assertion failed: `argumentList` must be a List'); // step 1
    }
 
    var defaultConstructor = getConstructor(kind); // step 2
    if (typeof defaultConstructor !== 'function') {
        throw new $SyntaxError('Assertion failed: `constructor` of `exemplar` (' + kind + ') must exist. Please report this!');
    }
    var constructor = SpeciesConstructor(exemplar, defaultConstructor); // step 3
 
    return TypedArrayCreate(constructor, argumentList); // step 4
};