source: imaps-frontend/node_modules/es-abstract/2017/ArraySpeciesCreate.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $Array = GetIntrinsic('%Array%');
6var $species = GetIntrinsic('%Symbol.species%', true);
7var $TypeError = require('es-errors/type');
8
9var Get = require('./Get');
10var IsArray = require('./IsArray');
11var IsConstructor = require('./IsConstructor');
12var Type = require('./Type');
13
14var isInteger = require('../helpers/isInteger');
15
16// https://262.ecma-international.org/6.0/#sec-arrayspeciescreate
17
18module.exports = function ArraySpeciesCreate(originalArray, length) {
19 if (!isInteger(length) || length < 0) {
20 throw new $TypeError('Assertion failed: length must be an integer >= 0');
21 }
22 var len = length === 0 ? 0 : length;
23 var C;
24 var isArray = IsArray(originalArray);
25 if (isArray) {
26 C = Get(originalArray, 'constructor');
27 // TODO: figure out how to make a cross-realm normal Array, a same-realm Array
28 // if (IsConstructor(C)) {
29 // if C is another realm's Array, C = undefined
30 // Object.getPrototypeOf(Object.getPrototypeOf(Object.getPrototypeOf(Array))) === null ?
31 // }
32 if ($species && Type(C) === 'Object') {
33 C = Get(C, $species);
34 if (C === null) {
35 C = void 0;
36 }
37 }
38 }
39 if (typeof C === 'undefined') {
40 return $Array(len);
41 }
42 if (!IsConstructor(C)) {
43 throw new $TypeError('C must be a constructor');
44 }
45 return new C(len); // Construct(C, len);
46};
47
Note: See TracBrowser for help on using the repository browser.