UNPKG

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