source: imaps-frontend/node_modules/es-iterator-helpers/aos/GeneratorStart.js

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.5 KB
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var CreateIterResultObject = require('es-abstract/2024/CreateIterResultObject');
6var IsCallable = require('es-abstract/2024/IsCallable');
7var Type = require('es-abstract/2024/Type');
8
9var SLOT = require('internal-slot');
10
11module.exports = function GeneratorStart(generator, closure) {
12 SLOT.assert(generator, '[[GeneratorState]]');
13 SLOT.assert(generator, '[[GeneratorContext]]');
14 SLOT.assert(generator, '[[GeneratorBrand]]');
15 SLOT.assert(generator, '[[Sentinel]]'); // our userland slot
16 SLOT.assert(generator, '[[CloseIfAbrupt]]'); // our second userland slot
17
18 if (!IsCallable(closure) || closure.length !== 0) {
19 throw new $TypeError('`closure` must be a function that takes no arguments');
20 }
21
22 var sentinel = SLOT.get(closure, '[[Sentinel]]');
23 if (Type(sentinel) !== 'Object') {
24 throw new $TypeError('`closure.[[Sentinel]]` must be an object');
25 }
26 SLOT.set(generator, '[[GeneratorContext]]', function () { // steps 2-5
27 try {
28 var result = closure();
29 if (result === sentinel) {
30 SLOT.set(generator, '[[GeneratorState]]', 'completed');
31 SLOT.set(generator, '[[GeneratorContext]]', null);
32 return CreateIterResultObject(void undefined, true);
33 }
34 SLOT.set(generator, '[[GeneratorState]]', 'suspendedYield');
35 return CreateIterResultObject(result, false);
36 } catch (e) {
37 SLOT.set(generator, '[[GeneratorState]]', 'completed');
38 SLOT.set(generator, '[[GeneratorContext]]', null);
39 throw e;
40 }
41 });
42
43 SLOT.set(generator, '[[GeneratorState]]', 'suspendedStart'); // step 6
44};
Note: See TracBrowser for help on using the repository browser.