summaryrefslogtreecommitdiff
path: root/tools/eslint/node_modules/escope/node_modules/es6-weak-map/node_modules/es6-iterator/#/chain.js
blob: 6dc1543b35453149347e6512d461601a5d366100 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';

var setPrototypeOf = require('es5-ext/object/set-prototype-of')
  , d              = require('d')
  , Iterator       = require('../')
  , validIterable  = require('../valid-iterable')

  , push = Array.prototype.push
  , defineProperties = Object.defineProperties
  , IteratorChain;

IteratorChain = function (iterators) {
	defineProperties(this, {
		__iterators__: d('', iterators),
		__current__: d('w', iterators.shift())
	});
};
if (setPrototypeOf) setPrototypeOf(IteratorChain, Iterator);

IteratorChain.prototype = Object.create(Iterator.prototype, {
	constructor: d(IteratorChain),
	next: d(function () {
		var result;
		if (!this.__current__) return { done: true, value: undefined };
		result = this.__current__.next();
		while (result.done) {
			this.__current__ = this.__iterators__.shift();
			if (!this.__current__) return { done: true, value: undefined };
			result = this.__current__.next();
		}
		return result;
	})
});

module.exports = function () {
	var iterators = [this];
	push.apply(iterators, arguments);
	iterators.forEach(validIterable);
	return new IteratorChain(iterators);
};