source: frontend/node_modules/core-js/internals/iterate.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.7 KB
Line 
1'use strict';
2var bind = require('../internals/function-bind-context');
3var call = require('../internals/function-call');
4var anObject = require('../internals/an-object');
5var tryToString = require('../internals/try-to-string');
6var isArrayIteratorMethod = require('../internals/is-array-iterator-method');
7var lengthOfArrayLike = require('../internals/length-of-array-like');
8var isPrototypeOf = require('../internals/object-is-prototype-of');
9var getIterator = require('../internals/get-iterator');
10var getIteratorMethod = require('../internals/get-iterator-method');
11var iteratorClose = require('../internals/iterator-close');
12
13var $TypeError = TypeError;
14
15var Result = function (stopped, result) {
16 this.stopped = stopped;
17 this.result = result;
18};
19
20var ResultPrototype = Result.prototype;
21
22module.exports = function (iterable, unboundFunction, options) {
23 var that = options && options.that;
24 var AS_ENTRIES = !!(options && options.AS_ENTRIES);
25 var IS_RECORD = !!(options && options.IS_RECORD);
26 var IS_ITERATOR = !!(options && options.IS_ITERATOR);
27 var INTERRUPTED = !!(options && options.INTERRUPTED);
28 var fn = bind(unboundFunction, that);
29 var iterator, iterFn, index, length, result, next, step;
30
31 var stop = function (condition) {
32 var $iterator = iterator;
33 iterator = undefined;
34 if ($iterator) iteratorClose($iterator, 'normal');
35 return new Result(true, condition);
36 };
37
38 var callFn = function (value) {
39 if (AS_ENTRIES) {
40 anObject(value);
41 return INTERRUPTED ? fn(value[0], value[1], stop) : fn(value[0], value[1]);
42 } return INTERRUPTED ? fn(value, stop) : fn(value);
43 };
44
45 if (IS_RECORD) {
46 iterator = iterable.iterator;
47 } else if (IS_ITERATOR) {
48 iterator = iterable;
49 } else {
50 iterFn = getIteratorMethod(iterable);
51 if (!iterFn) throw new $TypeError(tryToString(iterable) + ' is not iterable');
52 // optimisation for array iterators
53 if (isArrayIteratorMethod(iterFn)) {
54 for (index = 0, length = lengthOfArrayLike(iterable); length > index; index++) {
55 result = callFn(iterable[index]);
56 if (result && isPrototypeOf(ResultPrototype, result)) return result;
57 } return new Result(false);
58 }
59 iterator = getIterator(iterable, iterFn);
60 }
61
62 next = IS_RECORD ? iterable.next : iterator.next;
63 while (!(step = call(next, iterator)).done) {
64 // `IteratorValue` errors should propagate without closing the iterator
65 var value = step.value;
66 try {
67 result = callFn(value);
68 } catch (error) {
69 if (iterator) iteratorClose(iterator, 'throw', error);
70 else throw error;
71 }
72 if (typeof result == 'object' && result && isPrototypeOf(ResultPrototype, result)) return result;
73 } return new Result(false);
74};
Note: See TracBrowser for help on using the repository browser.