1 | 'use strict';
|
2 | var $ = require('../internals/export');
|
3 | var isObject = require('../internals/is-object');
|
4 | var isArray = require('../internals/is-array');
|
5 | var toAbsoluteIndex = require('../internals/to-absolute-index');
|
6 | var toLength = require('../internals/to-length');
|
7 | var toIndexedObject = require('../internals/to-indexed-object');
|
8 | var createProperty = require('../internals/create-property');
|
9 | var arrayMethodHasSpeciesSupport = require('../internals/array-method-has-species-support');
|
10 | var wellKnownSymbol = require('../internals/well-known-symbol');
|
11 |
|
12 | var SPECIES = wellKnownSymbol('species');
|
13 | var nativeSlice = [].slice;
|
14 | var max = Math.max;
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | $({ target: 'Array', proto: true, forced: !arrayMethodHasSpeciesSupport('slice') }, {
|
20 | slice: function slice(start, end) {
|
21 | var O = toIndexedObject(this);
|
22 | var length = toLength(O.length);
|
23 | var k = toAbsoluteIndex(start, length);
|
24 | var fin = toAbsoluteIndex(end === undefined ? length : end, length);
|
25 |
|
26 | var Constructor, result, n;
|
27 | if (isArray(O)) {
|
28 | Constructor = O.constructor;
|
29 |
|
30 | if (typeof Constructor == 'function' && (Constructor === Array || isArray(Constructor.prototype))) {
|
31 | Constructor = undefined;
|
32 | } else if (isObject(Constructor)) {
|
33 | Constructor = Constructor[SPECIES];
|
34 | if (Constructor === null) Constructor = undefined;
|
35 | }
|
36 | if (Constructor === Array || Constructor === undefined) {
|
37 | return nativeSlice.call(O, k, fin);
|
38 | }
|
39 | }
|
40 | result = new (Constructor === undefined ? Array : Constructor)(max(fin - k, 0));
|
41 | for (n = 0; k < fin; k++, n++) if (k in O) createProperty(result, n, O[k]);
|
42 | result.length = n;
|
43 | return result;
|
44 | }
|
45 | });
|