UNPKG

988 BJavaScriptView Raw
1'use strict';
2var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
3var speciesConstructor = require('../internals/species-constructor');
4var fails = require('../internals/fails');
5
6var aTypedArray = ArrayBufferViewCore.aTypedArray;
7var aTypedArrayConstructor = ArrayBufferViewCore.aTypedArrayConstructor;
8var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
9var $slice = [].slice;
10
11var FORCED = fails(function () {
12 // eslint-disable-next-line no-undef
13 new Int8Array(1).slice();
14});
15
16// `%TypedArray%.prototype.slice` method
17// https://tc39.es/ecma262/#sec-%typedarray%.prototype.slice
18exportTypedArrayMethod('slice', function slice(start, end) {
19 var list = $slice.call(aTypedArray(this), start, end);
20 var C = speciesConstructor(this, this.constructor);
21 var index = 0;
22 var length = list.length;
23 var result = new (aTypedArrayConstructor(C))(length);
24 while (length > index) result[index] = list[index++];
25 return result;
26}, FORCED);