iterator-close.js 657 B

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