IterableToList.js 619 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var callBound = require('call-bind/callBound');
  3. var $arrayPush = callBound('Array.prototype.push');
  4. var GetIterator = require('./GetIterator');
  5. var IteratorStep = require('./IteratorStep');
  6. var IteratorValue = require('./IteratorValue');
  7. // https://262.ecma-international.org/8.0/#sec-iterabletolist
  8. module.exports = function IterableToList(items, method) {
  9. var iterator = GetIterator(items, method);
  10. var values = [];
  11. var next = true;
  12. while (next) {
  13. next = IteratorStep(iterator);
  14. if (next) {
  15. var nextValue = IteratorValue(next);
  16. $arrayPush(values, nextValue);
  17. }
  18. }
  19. return values;
  20. };