IteratorToList.js 782 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. var callBound = require('call-bind/callBound');
  3. var $arrayPush = callBound('Array.prototype.push');
  4. var IteratorStep = require('./IteratorStep');
  5. var IteratorValue = require('./IteratorValue');
  6. var Type = require('./Type');
  7. var assertRecord = require('../helpers/assertRecord');
  8. // https://262.ecma-international.org/14.0/#sec-iteratortolist
  9. module.exports = function IteratorToList(iteratorRecord) {
  10. assertRecord(Type, 'Iterator Record', 'iteratorRecord', iteratorRecord);
  11. var values = []; // step 1
  12. var next = true; // step 2
  13. while (next) { // step 3
  14. next = IteratorStep(iteratorRecord); // step 3.a
  15. if (next) {
  16. var nextValue = IteratorValue(next); // step 3.b.i
  17. $arrayPush(values, nextValue); // step 3.b.ii
  18. }
  19. }
  20. return values; // step 4
  21. };