esnext.iterator.from.js 1020 B

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