esnext.async-iterator.from.js 814 B

1234567891011121314151617
  1. var $ = require('../internals/export');
  2. var toObject = require('../internals/to-object');
  3. var isPrototypeOf = require('../internals/object-is-prototype-of');
  4. var getAsyncIteratorFlattenable = require('../internals/get-async-iterator-flattenable');
  5. var AsyncIteratorPrototype = require('../internals/async-iterator-prototype');
  6. var WrapAsyncIterator = require('../internals/async-iterator-wrap');
  7. // `AsyncIterator.from` method
  8. // https://github.com/tc39/proposal-async-iterator-helpers
  9. $({ target: 'AsyncIterator', stat: true }, {
  10. from: function from(O) {
  11. var iteratorRecord = getAsyncIteratorFlattenable(typeof O == 'string' ? toObject(O) : O);
  12. return isPrototypeOf(AsyncIteratorPrototype, iteratorRecord.iterator)
  13. ? iteratorRecord.iterator
  14. : new WrapAsyncIterator(iteratorRecord);
  15. }
  16. });