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.1 KB
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var callBound = require('call-bind/callBound');
|
---|
| 4 | var $arrayPush = callBound('Array.prototype.push');
|
---|
| 5 |
|
---|
| 6 | var getIteratorMethod = require('../helpers/getIteratorMethod');
|
---|
| 7 | var AdvanceStringIndex = require('./AdvanceStringIndex');
|
---|
| 8 | var GetIterator = require('./GetIterator');
|
---|
| 9 | var GetMethod = require('./GetMethod');
|
---|
| 10 | var IsArray = require('./IsArray');
|
---|
| 11 | var IteratorStep = require('./IteratorStep');
|
---|
| 12 | var IteratorValue = require('./IteratorValue');
|
---|
| 13 | var ToObject = require('./ToObject');
|
---|
| 14 | var ES = {
|
---|
| 15 | AdvanceStringIndex: AdvanceStringIndex,
|
---|
| 16 | GetMethod: GetMethod,
|
---|
| 17 | IsArray: IsArray
|
---|
| 18 | };
|
---|
| 19 |
|
---|
| 20 | // https://262.ecma-international.org/7.0/#sec-iterabletoarraylike
|
---|
| 21 |
|
---|
| 22 | module.exports = function IterableToArrayLike(items) {
|
---|
| 23 | var usingIterator = getIteratorMethod(ES, items);
|
---|
| 24 | if (typeof usingIterator !== 'undefined') {
|
---|
| 25 | var iterator = GetIterator(items, usingIterator);
|
---|
| 26 | var values = [];
|
---|
| 27 | var next = true;
|
---|
| 28 | while (next) {
|
---|
| 29 | next = IteratorStep(iterator);
|
---|
| 30 | if (next) {
|
---|
| 31 | var nextValue = IteratorValue(next);
|
---|
| 32 | $arrayPush(values, nextValue);
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 | return values;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | return ToObject(items);
|
---|
| 39 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.