UNPKG

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