esnext.iterator.from.js 837 B

1234567891011121314151617181920
  1. // https://github.com/tc39/proposal-iterator-helpers
  2. var $ = require('../internals/export');
  3. var call = require('../internals/function-call');
  4. var isPrototypeOf = require('../internals/object-is-prototype-of');
  5. var IteratorPrototype = require('../internals/iterators-core').IteratorPrototype;
  6. var createIteratorProxy = require('../internals/iterator-create-proxy');
  7. var getIteratorFlattenable = require('../internals/get-iterator-flattenable');
  8. var IteratorProxy = createIteratorProxy(function () {
  9. return call(this.next, this.iterator);
  10. }, true);
  11. $({ target: 'Iterator', stat: true, forced: true }, {
  12. from: function from(O) {
  13. var iteratorRecord = getIteratorFlattenable(O);
  14. return isPrototypeOf(IteratorPrototype, iteratorRecord.iterator)
  15. ? iteratorRecord.iterator
  16. : new IteratorProxy(iteratorRecord);
  17. }
  18. });