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

1234567891011
  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, 'throw', error);
  9. }
  10. };