GeneratorResume.js 898 B

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