forked from ibm-developer-skills-network/kduia-shopping-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (33 loc) · 877 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
var SLOT = require('internal-slot');
var $SyntaxError = SyntaxError;
var $StopIteration = typeof StopIteration === 'object' ? StopIteration : null;
module.exports = function getStopIterationIterator(origIterator) {
if (!$StopIteration) {
throw new $SyntaxError('this environment lacks StopIteration');
}
SLOT.set(origIterator, '[[Done]]', false);
var siIterator = {
next: function next() {
var iterator = SLOT.get(this, '[[Iterator]]');
var done = SLOT.get(iterator, '[[Done]]');
try {
return {
done: done,
value: done ? void undefined : iterator.next()
};
} catch (e) {
SLOT.set(iterator, '[[Done]]', true);
if (e !== $StopIteration) {
throw e;
}
return {
done: true,
value: void undefined
};
}
}
};
SLOT.set(siIterator, '[[Iterator]]', origIterator);
return siIterator;
};