source: trip-planner-front/node_modules/core-js/modules/es.array.concat.js

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

initial commit

  • Property mode set to 100644
File size: 2.4 KB
Line 
1'use strict';
2var $ = require('../internals/export');
3var fails = require('../internals/fails');
4var isArray = require('../internals/is-array');
5var isObject = require('../internals/is-object');
6var toObject = require('../internals/to-object');
7var toLength = require('../internals/to-length');
8var createProperty = require('../internals/create-property');
9var arraySpeciesCreate = require('../internals/array-species-create');
10var arrayMethodHasSpeciesSupport = require('../internals/array-method-has-species-support');
11var wellKnownSymbol = require('../internals/well-known-symbol');
12var V8_VERSION = require('../internals/engine-v8-version');
13
14var IS_CONCAT_SPREADABLE = wellKnownSymbol('isConcatSpreadable');
15var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF;
16var MAXIMUM_ALLOWED_INDEX_EXCEEDED = 'Maximum allowed index exceeded';
17
18// We can't use this feature detection in V8 since it causes
19// deoptimization and serious performance degradation
20// https://github.com/zloirock/core-js/issues/679
21var IS_CONCAT_SPREADABLE_SUPPORT = V8_VERSION >= 51 || !fails(function () {
22 var array = [];
23 array[IS_CONCAT_SPREADABLE] = false;
24 return array.concat()[0] !== array;
25});
26
27var SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('concat');
28
29var isConcatSpreadable = function (O) {
30 if (!isObject(O)) return false;
31 var spreadable = O[IS_CONCAT_SPREADABLE];
32 return spreadable !== undefined ? !!spreadable : isArray(O);
33};
34
35var FORCED = !IS_CONCAT_SPREADABLE_SUPPORT || !SPECIES_SUPPORT;
36
37// `Array.prototype.concat` method
38// https://tc39.es/ecma262/#sec-array.prototype.concat
39// with adding support of @@isConcatSpreadable and @@species
40$({ target: 'Array', proto: true, forced: FORCED }, {
41 // eslint-disable-next-line no-unused-vars -- required for `.length`
42 concat: function concat(arg) {
43 var O = toObject(this);
44 var A = arraySpeciesCreate(O, 0);
45 var n = 0;
46 var i, k, length, len, E;
47 for (i = -1, length = arguments.length; i < length; i++) {
48 E = i === -1 ? O : arguments[i];
49 if (isConcatSpreadable(E)) {
50 len = toLength(E.length);
51 if (n + len > MAX_SAFE_INTEGER) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED);
52 for (k = 0; k < len; k++, n++) if (k in E) createProperty(A, n, E[k]);
53 } else {
54 if (n >= MAX_SAFE_INTEGER) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED);
55 createProperty(A, n++, E);
56 }
57 }
58 A.length = n;
59 return A;
60 }
61});
Note: See TracBrowser for help on using the repository browser.