GeneratorResume.js 850 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var CreateIterResultObject = require('es-abstract/2023/CreateIterResultObject');
  4. var GeneratorValidate = require('./GeneratorValidate');
  5. var SLOT = require('internal-slot');
  6. module.exports = function GeneratorResume(generator, value, generatorBrand) {
  7. var state = GeneratorValidate(generator, generatorBrand); // step 1
  8. if (state === 'completed') {
  9. return CreateIterResultObject(void undefined, true); // step 2
  10. }
  11. if (state !== 'suspendedStart' && state !== 'suspendedYield') {
  12. throw new $TypeError('Assertion failed: generator state is unexpected: ' + state); // step 3
  13. }
  14. var genContext = SLOT.get(generator, '[[GeneratorContext]]');
  15. SLOT.set(generator, '[[GeneratorState]]', 'executing'); // step 7
  16. var result = genContext(value); // steps 5-6, 8-10
  17. return result;
  18. };