IteratorStep.js 655 B

123456789101112131415161718192021
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var IteratorComplete = require('./IteratorComplete');
  4. var IteratorNext = require('./IteratorNext');
  5. var isIteratorRecord = require('../helpers/records/iterator-record');
  6. // https://262.ecma-international.org/14.0/#sec-iteratorstep
  7. module.exports = function IteratorStep(iteratorRecord) {
  8. if (!isIteratorRecord(iteratorRecord)) {
  9. throw new $TypeError('Assertion failed: `iteratorRecord` must be an Iterator Record'); // step 1
  10. }
  11. var result = IteratorNext(iteratorRecord); // step 1
  12. var done = IteratorComplete(result); // step 2
  13. return done === true ? false : result; // steps 3-4
  14. };