source: imaps-frontend/node_modules/es-iterator-helpers/aos/GeneratorResumeAbrupt.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var CompletionRecord = require('es-abstract/2024/CompletionRecord');
6var CreateIterResultObject = require('es-abstract/2024/CreateIterResultObject');
7var GeneratorValidate = require('./GeneratorValidate');
8var NormalCompletion = require('es-abstract/2024/NormalCompletion');
9
10var SLOT = require('internal-slot');
11
12module.exports = function GeneratorResumeAbrupt(generator, abruptCompletion, generatorBrand) {
13 if (!(abruptCompletion instanceof CompletionRecord)) {
14 throw new $TypeError('Assertion failed: abruptCompletion must be a Completion Record');
15 }
16
17 var state = GeneratorValidate(generator, generatorBrand); // step 1
18
19 if (state === 'suspendedStart') { // step 2
20 SLOT.set(generator, '[[GeneratorState]]', 'completed'); // step 3.a
21 SLOT.set(generator, '[[GeneratorContext]]', null); // step 3.b
22 state = 'completed'; // step 3.c
23 }
24
25 var value = abruptCompletion.value();
26
27 if (state === 'completed') { // step 3
28 return CreateIterResultObject(value, true); // steps 3.a-b
29 }
30
31 if (state !== 'suspendedYield') {
32 throw new $TypeError('Assertion failed: generator state is unexpected: ' + state); // step 4
33 }
34 if (abruptCompletion.type() === 'return') {
35 // due to representing `GeneratorContext` as a function, we can't safely re-invoke it, so we can't support sending it a return completion
36 return CreateIterResultObject(SLOT.get(generator, '[[CloseIfAbrupt]]')(NormalCompletion(abruptCompletion.value())), true);
37 }
38
39 var genContext = SLOT.get(generator, '[[GeneratorContext]]'); // step 5
40
41 SLOT.set(generator, '[[GeneratorState]]', 'executing'); // step 8
42
43 var result = genContext(value); // steps 6-7, 8-11
44
45 return result; // step 12
46};
Note: See TracBrowser for help on using the repository browser.