Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | // https://github.com/tc39/proposal-iterator-helpers
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var path = require('../internals/path');
|
---|
4 | var aFunction = require('../internals/a-function');
|
---|
5 | var anObject = require('../internals/an-object');
|
---|
6 | var toObject = require('../internals/to-object');
|
---|
7 | var createIteratorProxy = require('../internals/iterator-create-proxy');
|
---|
8 | var getIteratorMethod = require('../internals/get-iterator-method');
|
---|
9 |
|
---|
10 | var Iterator = path.Iterator;
|
---|
11 |
|
---|
12 | var IteratorProxy = createIteratorProxy(function (arg) {
|
---|
13 | var result = anObject(this.next.call(this.iterator, arg));
|
---|
14 | var done = this.done = !!result.done;
|
---|
15 | if (!done) return result.value;
|
---|
16 | }, true);
|
---|
17 |
|
---|
18 | $({ target: 'Iterator', stat: true }, {
|
---|
19 | from: function from(O) {
|
---|
20 | var object = toObject(O);
|
---|
21 | var usingIterator = getIteratorMethod(object);
|
---|
22 | var iterator;
|
---|
23 | if (usingIterator != null) {
|
---|
24 | iterator = aFunction(usingIterator).call(object);
|
---|
25 | if (iterator instanceof Iterator) return iterator;
|
---|
26 | } else {
|
---|
27 | iterator = object;
|
---|
28 | } return new IteratorProxy({
|
---|
29 | iterator: iterator
|
---|
30 | });
|
---|
31 | }
|
---|
32 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.