5d8e92e0d87755aac7426dfc21fd60b951f21d154ce3f56bed7f0db8a84526bb832b3e15406c0b7e8cf3d86a84a29dd72095cb3af7dab8b04303ee8daabec8 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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 TypedArrayCreateFromConstructor = require('./TypedArrayCreateFromConstructor');
  8. var getConstructor = require('../helpers/typedArrayConstructors');
  9. // https://262.ecma-international.org/15.0/#sec-typedarray-create-same-type
  10. module.exports = function TypedArrayCreateSameType(exemplar, argumentList) {
  11. if (availableTypedArrays.length === 0) {
  12. throw new $SyntaxError('Assertion failed: Typed Arrays are not supported in this environment');
  13. }
  14. var kind = whichTypedArray(exemplar);
  15. if (!kind) {
  16. throw new $TypeError('Assertion failed: exemplar must be a TypedArray'); // step 1
  17. }
  18. if (!IsArray(argumentList)) {
  19. throw new $TypeError('Assertion failed: `argumentList` must be a List'); // step 1
  20. }
  21. var constructor = getConstructor(kind); // step 2
  22. if (typeof constructor !== 'function') {
  23. throw new $SyntaxError('Assertion failed: `constructor` of `exemplar` (' + kind + ') must exist. Please report this!');
  24. }
  25. return TypedArrayCreateFromConstructor(constructor, argumentList); // steps 3 - 6
  26. };