esnext.async-iterator.from.js 892 B

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