2535f96e69490fa6fce2bee66222381414a87ab8c568d995548d9e9122249b055155712deeb9bbe340595c603e1c0324d2ab6a6a078f0c8c69fe161e8d8d4b 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 TypedArrayCreate = require('./TypedArrayCreate');
  8. var getConstructor = require('../helpers/typedArrayConstructors');
  9. // https://262.ecma-international.org/14.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 TypedArrayCreate(constructor, argumentList); // steps 3 - 6
  26. };