Skip to content
Permalink
9bfb9ba527
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
40 lines (33 sloc) 877 Bytes
'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;
};