source: imaps-frontend/node_modules/es-abstract/2016/ArrayCreate.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.4 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $ArrayPrototype = GetIntrinsic('%Array.prototype%');
6var $RangeError = require('es-errors/range');
7var $SyntaxError = require('es-errors/syntax');
8var $TypeError = require('es-errors/type');
9var isInteger = require('math-intrinsics/isInteger');
10var MAX_ARRAY_LENGTH = require('math-intrinsics/constants/maxArrayLength');
11var $setProto = require('set-proto');
12
13// https://262.ecma-international.org/6.0/#sec-arraycreate
14
15module.exports = function ArrayCreate(length) {
16 if (!isInteger(length) || length < 0) {
17 throw new $TypeError('Assertion failed: `length` must be an integer Number >= 0');
18 }
19 if (length > MAX_ARRAY_LENGTH) {
20 throw new $RangeError('length is greater than (2**32 - 1)');
21 }
22 var proto = arguments.length > 1 ? arguments[1] : $ArrayPrototype;
23 var A = []; // steps 5 - 7, and 9
24 if (proto !== $ArrayPrototype) { // step 8
25 if (!$setProto) {
26 throw new $SyntaxError('ArrayCreate: a `proto` argument that is not `Array.prototype` is not supported in an environment that does not support setting the [[Prototype]]');
27 }
28 $setProto(A, proto);
29 }
30 if (length !== 0) { // bypasses the need for step 2
31 A.length = length;
32 }
33 /* step 10, the above as a shortcut for the below
34 OrdinaryDefineOwnProperty(A, 'length', {
35 '[[Configurable]]': false,
36 '[[Enumerable]]': false,
37 '[[Value]]': length,
38 '[[Writable]]': true
39 });
40 */
41 return A;
42};
Note: See TracBrowser for help on using the repository browser.