esnext.async-iterator.from.js 1.0 KB

123456789101112131415161718192021222324252627282930
  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 createAsyncIteratorProxy = require('../internals/async-iterator-create-proxy');
  8. var getAsyncIteratorMethod = require('../internals/get-async-iterator-method');
  9. var AsyncIterator = path.AsyncIterator;
  10. var AsyncIteratorProxy = createAsyncIteratorProxy(function (arg) {
  11. return anObject(this.next.call(this.iterator, arg));
  12. }, true);
  13. $({ target: 'AsyncIterator', stat: true }, {
  14. from: function from(O) {
  15. var object = toObject(O);
  16. var usingIterator = getAsyncIteratorMethod(object);
  17. var iterator;
  18. if (usingIterator != null) {
  19. iterator = aFunction(usingIterator).call(object);
  20. if (iterator instanceof AsyncIterator) return iterator;
  21. } else {
  22. iterator = object;
  23. } return new AsyncIteratorProxy({
  24. iterator: iterator
  25. });
  26. }
  27. });