source: imaps-frontend/node_modules/es-abstract/2021/ArraySpeciesCreate.js

main
Last change on this file 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 $species = GetIntrinsic('%Symbol.species%', true);
6var $TypeError = require('es-errors/type');
7
8var ArrayCreate = require('./ArrayCreate');
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/12.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
23 var isArray = IsArray(originalArray);
24 if (!isArray) {
25 return ArrayCreate(length);
26 }
27
28 var C = Get(originalArray, 'constructor');
29 // TODO: figure out how to make a cross-realm normal Array, a same-realm Array
30 // if (IsConstructor(C)) {
31 // if C is another realm's Array, C = undefined
32 // Object.getPrototypeOf(Object.getPrototypeOf(Object.getPrototypeOf(Array))) === null ?
33 // }
34 if ($species && Type(C) === 'Object') {
35 C = Get(C, $species);
36 if (C === null) {
37 C = void 0;
38 }
39 }
40
41 if (typeof C === 'undefined') {
42 return ArrayCreate(length);
43 }
44 if (!IsConstructor(C)) {
45 throw new $TypeError('C must be a constructor');
46 }
47 return new C(length); // Construct(C, length);
48};
49
Note: See TracBrowser for help on using the repository browser.