source: imaps-frontend/node_modules/es-abstract/2017/CreateListFromArrayLike.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.3 KB
Line 
1'use strict';
2
3var callBound = require('call-bound');
4
5var $TypeError = require('es-errors/type');
6var $indexOf = callBound('Array.prototype.indexOf', true) || callBound('String.prototype.indexOf');
7var $push = callBound('Array.prototype.push');
8
9var Get = require('./Get');
10var IsArray = require('./IsArray');
11var ToLength = require('./ToLength');
12var ToString = require('./ToString');
13var Type = require('./Type');
14
15var isObject = require('../helpers/isObject');
16
17var defaultElementTypes = ['Undefined', 'Null', 'Boolean', 'String', 'Symbol', 'Number', 'Object'];
18
19// https://262.ecma-international.org/6.0/#sec-createlistfromarraylike
20module.exports = function CreateListFromArrayLike(obj) {
21 var elementTypes = arguments.length > 1
22 ? arguments[1]
23 : defaultElementTypes;
24
25 if (!isObject(obj)) {
26 throw new $TypeError('Assertion failed: `obj` must be an Object');
27 }
28 if (!IsArray(elementTypes)) {
29 throw new $TypeError('Assertion failed: `elementTypes`, if provided, must be an array');
30 }
31 var len = ToLength(Get(obj, 'length'));
32 var list = [];
33 var index = 0;
34 while (index < len) {
35 var indexName = ToString(index);
36 var next = Get(obj, indexName);
37 var nextType = Type(next);
38 if ($indexOf(elementTypes, nextType) < 0) {
39 throw new $TypeError('item type ' + nextType + ' is not a valid elementType');
40 }
41 $push(list, next);
42 index += 1;
43 }
44 return list;
45};
Note: See TracBrowser for help on using the repository browser.