_iter-call.js 410 B

12345678910111213
  1. // call something on iterator step with safe closing on error
  2. var anObject = require('./_an-object');
  3. module.exports = function (iterator, fn, value, entries) {
  4. try {
  5. return entries ? fn(anObject(value)[0], value[1]) : fn(value);
  6. // 7.4.6 IteratorClose(iterator, completion)
  7. } catch (e) {
  8. var ret = iterator['return'];
  9. if (ret !== undefined) anObject(ret.call(iterator));
  10. throw e;
  11. }
  12. };