UNPKG

637 BJavaScriptView Raw
1'use strict';
2// https://github.com/tc39/proposal-iterator-helpers
3var $ = require('../internals/export');
4var anObject = require('../internals/an-object');
5var createIteratorProxy = require('../internals/create-iterator-proxy');
6
7var IteratorProxy = createIteratorProxy(function (arg) {
8 var result = anObject(this.next.call(this.iterator, arg));
9 var done = this.done = !!result.done;
10 if (!done) return [this.index++, result.value];
11});
12
13$({ target: 'Iterator', proto: true, real: true }, {
14 asIndexedPairs: function asIndexedPairs() {
15 return new IteratorProxy({
16 iterator: anObject(this),
17 index: 0
18 });
19 }
20});