source: imaps-frontend/node_modules/es-iterator-helpers/Iterator.concat/implementation.js

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

Pred finalna verzija

  • Property mode set to 100644
File size: 4.0 KB
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var AdvanceStringIndex = require('es-abstract/2024/AdvanceStringIndex');
6var Call = require('es-abstract/2024/Call');
7var CompletionRecord = require('es-abstract/2024/CompletionRecord');
8var CreateIteratorFromClosure = require('../aos/CreateIteratorFromClosure');
9var GetIteratorDirect = require('../aos/GetIteratorDirect');
10var GetMethod = require('es-abstract/2024/GetMethod');
11var IsArray = require('es-abstract/2024/IsArray');
12var IteratorCloseAll = require('../aos/IteratorCloseAll');
13var IteratorStepValue = require('es-abstract/2024/IteratorStepValue');
14var ThrowCompletion = require('es-abstract/2024/ThrowCompletion');
15var Type = require('es-abstract/2024/Type');
16
17var forEach = require('es-abstract/helpers/forEach');
18var getIteratorMethod = require('es-abstract/helpers/getIteratorMethod');
19
20var callBound = require('call-bind/callBound');
21var $indexOf = callBound('Array.prototype.indexOf');
22var $splice = callBound('Array.prototype.splice');
23
24var iterHelperProto = require('../IteratorHelperPrototype');
25
26var SLOT = require('internal-slot');
27
28module.exports = function concat() {
29 if (this instanceof concat) {
30 throw new $TypeError('`Iterator.concat` is not a constructor');
31 }
32
33 var iterables = []; // step 1
34
35 forEach(arguments, function (item) { // step 2
36 if (Type(item) !== 'Object') {
37 throw new $TypeError('`Iterator.concat` requires all arguments to be objects'); // step 2.1
38 }
39 // var method = GetMethod(item, Symbol.iterator); // step 2.2
40 var method = getIteratorMethod(
41 {
42 AdvanceStringIndex: AdvanceStringIndex,
43 GetMethod: GetMethod,
44 IsArray: IsArray
45 },
46 item
47 );
48 if (typeof method === 'undefined') {
49 throw new $TypeError('`Iterator.concat` requires all arguments to be iterable'); // step 2.3
50 }
51 iterables[iterables.length] = { '[[OpenMethod]]': method, '[[Iterable]]': item }; // step 2.4
52 });
53
54 var openIters = []; // step 3
55 var sentinel = {};
56 var closeIfAbrupt = function (abruptCompletion) {
57 if (!(abruptCompletion instanceof CompletionRecord)) {
58 throw new $TypeError('`abruptCompletion` must be a Completion Record');
59 }
60 if (openIters.length > 0) {
61 IteratorCloseAll(
62 openIters,
63 abruptCompletion
64 );
65 }
66 };
67
68 var index = 0;
69 var closure = function () { // step 4
70 if (index < iterables.length) {
71 // forEach(iterables, function (iterable) { // step 4.a
72 var iteratorRecord;
73 if (openIters.length === 0) {
74 var iterable = iterables[index];
75 var iter = Call(iterable['[[OpenMethod]]'], iterable['[[Iterable]]']); // step 4.a.i
76 if (Type(iter) !== 'Object') {
77 closeIfAbrupt(ThrowCompletion(new $TypeError('???'))); // step 4.a.ii
78 }
79 iteratorRecord = GetIteratorDirect(iter); // step 4.a.iii
80 iteratorRecord.obj = iterable['[[Iterable]]'];
81 openIters[openIters.length] = iteratorRecord; // step 4.a.iv
82 } else {
83 iteratorRecord = openIters[0];
84 }
85
86 // var innerAlive = true; // step 4.a.v
87 // while (innerAlive) { // step 4.a.vi
88 { // eslint-disable-line no-lone-blocks
89 // step 4.a.vi.3.a
90 var innerValue;
91 try {
92 innerValue = IteratorStepValue(iteratorRecord); // step 5.b.ix.4.a
93 } catch (e) {
94 // innerAlive = false;
95 $splice(openIters, $indexOf(openIters, iteratorRecord), 1); // step 4.a.vi.2.a
96 index += 1;
97 closeIfAbrupt(ThrowCompletion(e)); // step 4.a.vi.3.b
98 }
99 if (iteratorRecord['[[Done]]']) {
100 // innerAlive = false;
101 $splice(openIters, $indexOf(openIters, iteratorRecord), 1);
102 index += 1;
103 return closure();
104 }
105 return innerValue; // // step 4.a.vi.3.a
106 }
107 // });
108 }
109
110 // return ReturnCompletion(undefined); // step 4.b
111 return sentinel;
112 };
113 SLOT.set(closure, '[[Sentinel]]', sentinel); // for the userland implementation
114 SLOT.set(closure, '[[CloseIfAbrupt]]', closeIfAbrupt); // for the userland implementation
115
116 var gen = CreateIteratorFromClosure(closure, 'Iterator Helper', iterHelperProto, ['[[UnderlyingIterators]]']); // step 5
117 SLOT.set(gen, '[[UnderlyingIterators]]', []); // step 6
118 return gen; // step 7
119};
Note: See TracBrowser for help on using the repository browser.