f8242846ca64f910f65eb55eddf5958ce6957ad187f58d52800f49f22e1849022cb53ecf2e509a427401ba9293549402e8c38286c98e51cc700e5d337c6748 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. var $SyntaxError = require('es-errors/syntax');
  3. var $TypeError = require('es-errors/type');
  4. var whichTypedArray = require('which-typed-array');
  5. var availableTypedArrays = require('available-typed-arrays')();
  6. var IsArray = require('./IsArray');
  7. var SpeciesConstructor = require('./SpeciesConstructor');
  8. var TypedArrayCreate = require('./TypedArrayCreate');
  9. var getConstructor = require('../helpers/typedArrayConstructors');
  10. // https://262.ecma-international.org/7.0/#typedarray-species-create
  11. module.exports = function TypedArraySpeciesCreate(exemplar, argumentList) {
  12. if (availableTypedArrays.length === 0) {
  13. throw new $SyntaxError('Assertion failed: Typed Arrays are not supported in this environment');
  14. }
  15. var kind = whichTypedArray(exemplar);
  16. if (!kind) {
  17. throw new $TypeError('Assertion failed: exemplar must be a TypedArray'); // step 1
  18. }
  19. if (!IsArray(argumentList)) {
  20. throw new $TypeError('Assertion failed: `argumentList` must be a List'); // step 1
  21. }
  22. var defaultConstructor = getConstructor(kind); // step 2
  23. if (typeof defaultConstructor !== 'function') {
  24. throw new $SyntaxError('Assertion failed: `constructor` of `exemplar` (' + kind + ') must exist. Please report this!');
  25. }
  26. var constructor = SpeciesConstructor(exemplar, defaultConstructor); // step 3
  27. return TypedArrayCreate(constructor, argumentList); // step 4
  28. };