source: trip-planner-front/node_modules/core-js/modules/es.array.slice.js@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.9 KB
Line 
1'use strict';
2var $ = require('../internals/export');
3var isObject = require('../internals/is-object');
4var isArray = require('../internals/is-array');
5var toAbsoluteIndex = require('../internals/to-absolute-index');
6var toLength = require('../internals/to-length');
7var toIndexedObject = require('../internals/to-indexed-object');
8var createProperty = require('../internals/create-property');
9var wellKnownSymbol = require('../internals/well-known-symbol');
10var arrayMethodHasSpeciesSupport = require('../internals/array-method-has-species-support');
11
12var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('slice');
13
14var SPECIES = wellKnownSymbol('species');
15var nativeSlice = [].slice;
16var max = Math.max;
17
18// `Array.prototype.slice` method
19// https://tc39.es/ecma262/#sec-array.prototype.slice
20// fallback for not array-like ES3 strings and DOM objects
21$({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT }, {
22 slice: function slice(start, end) {
23 var O = toIndexedObject(this);
24 var length = toLength(O.length);
25 var k = toAbsoluteIndex(start, length);
26 var fin = toAbsoluteIndex(end === undefined ? length : end, length);
27 // inline `ArraySpeciesCreate` for usage native `Array#slice` where it's possible
28 var Constructor, result, n;
29 if (isArray(O)) {
30 Constructor = O.constructor;
31 // cross-realm fallback
32 if (typeof Constructor == 'function' && (Constructor === Array || isArray(Constructor.prototype))) {
33 Constructor = undefined;
34 } else if (isObject(Constructor)) {
35 Constructor = Constructor[SPECIES];
36 if (Constructor === null) Constructor = undefined;
37 }
38 if (Constructor === Array || Constructor === undefined) {
39 return nativeSlice.call(O, k, fin);
40 }
41 }
42 result = new (Constructor === undefined ? Array : Constructor)(max(fin - k, 0));
43 for (n = 0; k < fin; k++, n++) if (k in O) createProperty(result, n, O[k]);
44 result.length = n;
45 return result;
46 }
47});
Note: See TracBrowser for help on using the repository browser.