call-with-safe-iteration-closing.js 380 B

123456789101112
  1. var anObject = require('../internals/an-object');
  2. var iteratorClose = require('../internals/iterator-close');
  3. // call something on iterator step with safe closing on error
  4. module.exports = function (iterator, fn, value, ENTRIES) {
  5. try {
  6. return ENTRIES ? fn(anObject(value)[0], value[1]) : fn(value);
  7. } catch (error) {
  8. iteratorClose(iterator);
  9. throw error;
  10. }
  11. };