massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / core-js / modules / es.array.slice.js
1 'use strict';
2 var $ = require('../internals/export');
3 var global = require('../internals/global');
4 var isArray = require('../internals/is-array');
5 var isConstructor = require('../internals/is-constructor');
6 var isObject = require('../internals/is-object');
7 var toAbsoluteIndex = require('../internals/to-absolute-index');
8 var lengthOfArrayLike = require('../internals/length-of-array-like');
9 var toIndexedObject = require('../internals/to-indexed-object');
10 var createProperty = require('../internals/create-property');
11 var wellKnownSymbol = require('../internals/well-known-symbol');
12 var arrayMethodHasSpeciesSupport = require('../internals/array-method-has-species-support');
13 var un$Slice = require('../internals/array-slice');
14
15 var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('slice');
16
17 var SPECIES = wellKnownSymbol('species');
18 var Array = global.Array;
19 var max = Math.max;
20
21 // `Array.prototype.slice` method
22 // https://tc39.es/ecma262/#sec-array.prototype.slice
23 // fallback for not array-like ES3 strings and DOM objects
24 $({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT }, {
25   slice: function slice(start, end) {
26     var O = toIndexedObject(this);
27     var length = lengthOfArrayLike(O);
28     var k = toAbsoluteIndex(start, length);
29     var fin = toAbsoluteIndex(end === undefined ? length : end, length);
30     // inline `ArraySpeciesCreate` for usage native `Array#slice` where it's possible
31     var Constructor, result, n;
32     if (isArray(O)) {
33       Constructor = O.constructor;
34       // cross-realm fallback
35       if (isConstructor(Constructor) && (Constructor === Array || isArray(Constructor.prototype))) {
36         Constructor = undefined;
37       } else if (isObject(Constructor)) {
38         Constructor = Constructor[SPECIES];
39         if (Constructor === null) Constructor = undefined;
40       }
41       if (Constructor === Array || Constructor === undefined) {
42         return un$Slice(O, k, fin);
43       }
44     }
45     result = new (Constructor === undefined ? Array : Constructor)(max(fin - k, 0));
46     for (n = 0; k < fin; k++, n++) if (k in O) createProperty(result, n, O[k]);
47     result.length = n;
48     return result;
49   }
50 });