IteratorNext.js 891 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var Call = require('./Call');
  4. var isObject = require('../helpers/isObject');
  5. var isIteratorRecord = require('../helpers/records/iterator-record-2023');
  6. // https://262.ecma-international.org/14.0/#sec-iteratornext
  7. module.exports = function IteratorNext(iteratorRecord) {
  8. if (!isIteratorRecord(iteratorRecord)) {
  9. throw new $TypeError('Assertion failed: `iteratorRecord` must be an Iterator Record'); // step 1
  10. }
  11. var result;
  12. if (arguments.length < 2) { // step 1
  13. result = Call(iteratorRecord['[[NextMethod]]'], iteratorRecord['[[Iterator]]']); // step 1.a
  14. } else { // step 2
  15. result = Call(iteratorRecord['[[NextMethod]]'], iteratorRecord['[[Iterator]]'], [arguments[1]]); // step 2.a
  16. }
  17. if (!isObject(result)) {
  18. throw new $TypeError('iterator next must return an object'); // step 3
  19. }
  20. return result; // step 4
  21. };