Last change
on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
917 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict';
|
---|
| 2 | // https://github.com/tc39/proposal-iterator-helpers
|
---|
| 3 | var $ = require('../internals/export');
|
---|
| 4 | var anObject = require('../internals/an-object');
|
---|
| 5 | var toPositiveInteger = require('../internals/to-positive-integer');
|
---|
| 6 | var createIteratorProxy = require('../internals/iterator-create-proxy');
|
---|
| 7 |
|
---|
| 8 | var IteratorProxy = createIteratorProxy(function (arg) {
|
---|
| 9 | var iterator = this.iterator;
|
---|
| 10 | var next = this.next;
|
---|
| 11 | var result, done;
|
---|
| 12 | while (this.remaining) {
|
---|
| 13 | this.remaining--;
|
---|
| 14 | result = anObject(next.call(iterator));
|
---|
| 15 | done = this.done = !!result.done;
|
---|
| 16 | if (done) return;
|
---|
| 17 | }
|
---|
| 18 | result = anObject(next.call(iterator, arg));
|
---|
| 19 | done = this.done = !!result.done;
|
---|
| 20 | if (!done) return result.value;
|
---|
| 21 | });
|
---|
| 22 |
|
---|
| 23 | $({ target: 'Iterator', proto: true, real: true }, {
|
---|
| 24 | drop: function drop(limit) {
|
---|
| 25 | return new IteratorProxy({
|
---|
| 26 | iterator: anObject(this),
|
---|
| 27 | remaining: toPositiveInteger(limit)
|
---|
| 28 | });
|
---|
| 29 | }
|
---|
| 30 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.