3fcb5f1e6671201af93cef0ded9e8d03b87c433ff1d1be5a3189f0e07712cbfa281db3f4985b65d8fda11040e522364b3ee079e774e974d4f9799a18d1f83f 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. var global = require('../internals/global');
  3. var fails = require('../internals/fails');
  4. var uncurryThis = require('../internals/function-uncurry-this');
  5. var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
  6. var ArrayIterators = require('../modules/es.array.iterator');
  7. var wellKnownSymbol = require('../internals/well-known-symbol');
  8. var ITERATOR = wellKnownSymbol('iterator');
  9. var Uint8Array = global.Uint8Array;
  10. var arrayValues = uncurryThis(ArrayIterators.values);
  11. var arrayKeys = uncurryThis(ArrayIterators.keys);
  12. var arrayEntries = uncurryThis(ArrayIterators.entries);
  13. var aTypedArray = ArrayBufferViewCore.aTypedArray;
  14. var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
  15. var TypedArrayPrototype = Uint8Array && Uint8Array.prototype;
  16. var GENERIC = !fails(function () {
  17. TypedArrayPrototype[ITERATOR].call([1]);
  18. });
  19. var ITERATOR_IS_VALUES = !!TypedArrayPrototype
  20. && TypedArrayPrototype.values
  21. && TypedArrayPrototype[ITERATOR] === TypedArrayPrototype.values
  22. && TypedArrayPrototype.values.name === 'values';
  23. var typedArrayValues = function values() {
  24. return arrayValues(aTypedArray(this));
  25. };
  26. // `%TypedArray%.prototype.entries` method
  27. // https://tc39.es/ecma262/#sec-%typedarray%.prototype.entries
  28. exportTypedArrayMethod('entries', function entries() {
  29. return arrayEntries(aTypedArray(this));
  30. }, GENERIC);
  31. // `%TypedArray%.prototype.keys` method
  32. // https://tc39.es/ecma262/#sec-%typedarray%.prototype.keys
  33. exportTypedArrayMethod('keys', function keys() {
  34. return arrayKeys(aTypedArray(this));
  35. }, GENERIC);
  36. // `%TypedArray%.prototype.values` method
  37. // https://tc39.es/ecma262/#sec-%typedarray%.prototype.values
  38. exportTypedArrayMethod('values', typedArrayValues, GENERIC || !ITERATOR_IS_VALUES, { name: 'values' });
  39. // `%TypedArray%.prototype[@@iterator]` method
  40. // https://tc39.es/ecma262/#sec-%typedarray%.prototype-@@iterator
  41. exportTypedArrayMethod(ITERATOR, typedArrayValues, GENERIC || !ITERATOR_IS_VALUES, { name: 'values' });