source: imaps-frontend/node_modules/es-iterator-helpers/aos/CreateIteratorFromClosure.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 GeneratorStart = require('./GeneratorStart');
6var IsArray = require('es-abstract/2024/IsArray');
7var IsCallable = require('es-abstract/2024/IsCallable');
8var OrdinaryObjectCreate = require('es-abstract/2024/OrdinaryObjectCreate');
9
10var every = require('es-abstract/helpers/every');
11
12var SLOT = require('internal-slot');
13
14var safeConcat = require('safe-array-concat');
15
16var isString = function isString(slot) {
17 return typeof slot === 'string';
18};
19
20module.exports = function CreateIteratorFromClosure(closure, generatorBrand, proto) {
21 if (!IsCallable(closure)) {
22 throw new $TypeError('`closure` must be a function');
23 }
24 if (typeof generatorBrand !== 'string') {
25 throw new $TypeError('`generatorBrand` must be a string');
26 }
27 var extraSlots = arguments.length > 3 ? arguments[3] : [];
28 if (arguments.length > 3) {
29 if (!IsArray(extraSlots) || !every(extraSlots, isString)) {
30 throw new $TypeError('`extraSlots` must be a List of String internal slot names');
31 }
32 }
33 var internalSlotsList = safeConcat(extraSlots, ['[[GeneratorContext]]', '[[GeneratorBrand]]', '[[GeneratorState]]']); // step 3
34 var generator = OrdinaryObjectCreate(proto, internalSlotsList); // steps 4, 6
35 SLOT.set(generator, '[[GeneratorBrand]]', generatorBrand); // step 5
36
37 SLOT.assert(closure, '[[Sentinel]]'); // our userland slot
38 SLOT.set(generator, '[[Sentinel]]', SLOT.get(closure, '[[Sentinel]]')); // our userland slot
39 SLOT.assert(closure, '[[CloseIfAbrupt]]'); // our second userland slot
40 SLOT.set(generator, '[[CloseIfAbrupt]]', SLOT.get(closure, '[[CloseIfAbrupt]]')); // our second userland slot
41
42 GeneratorStart(generator, closure); // step 13
43
44 return generator; // step 15
45};
Note: See TracBrowser for help on using the repository browser.