iterator-close.js 643 B

1234567891011121314151617181920212223
  1. var call = require('../internals/function-call');
  2. var anObject = require('../internals/an-object');
  3. var getMethod = require('../internals/get-method');
  4. module.exports = function (iterator, kind, value) {
  5. var innerResult, innerError;
  6. anObject(iterator);
  7. try {
  8. innerResult = getMethod(iterator, 'return');
  9. if (!innerResult) {
  10. if (kind === 'throw') throw value;
  11. return value;
  12. }
  13. innerResult = call(innerResult, iterator);
  14. } catch (error) {
  15. innerError = true;
  16. innerResult = error;
  17. }
  18. if (kind === 'throw') throw value;
  19. if (innerError) throw innerResult;
  20. anObject(innerResult);
  21. return value;
  22. };