UNPKG

721 BJavaScriptView Raw
1var isObject = require('../internals/is-object');
2var isArray = require('../internals/is-array');
3var wellKnownSymbol = require('../internals/well-known-symbol');
4
5var SPECIES = wellKnownSymbol('species');
6
7// `ArraySpeciesCreate` abstract operation
8// https://tc39.github.io/ecma262/#sec-arrayspeciescreate
9module.exports = function (originalArray, length) {
10 var C;
11 if (isArray(originalArray)) {
12 C = originalArray.constructor;
13 // cross-realm fallback
14 if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined;
15 else if (isObject(C)) {
16 C = C[SPECIES];
17 if (C === null) C = undefined;
18 }
19 } return new (C === undefined ? Array : C)(length === 0 ? 0 : length);
20};