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