IterableToList.js 721 B

1234567891011121314151617181920212223242526272829
  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/12.0/#sec-iterabletolist
  8. module.exports = function IterableToList(items) {
  9. var iterator;
  10. if (arguments.length > 1) {
  11. iterator = GetIterator(items, 'sync', arguments[1]);
  12. } else {
  13. iterator = GetIterator(items, 'sync');
  14. }
  15. var values = [];
  16. var next = true;
  17. while (next) {
  18. next = IteratorStep(iterator);
  19. if (next) {
  20. var nextValue = IteratorValue(next);
  21. $arrayPush(values, nextValue);
  22. }
  23. }
  24. return values;
  25. };