12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- 'use strict';
- var $TypeError = require('es-errors/type');
- var Call = require('./Call');
- var CompletionRecord = require('./CompletionRecord');
- var GetMethod = require('./GetMethod');
- var IsCallable = require('./IsCallable');
- var Type = require('./Type');
- module.exports = function IteratorClose(iterator, completion) {
- if (Type(iterator) !== 'Object') {
- throw new $TypeError('Assertion failed: Type(iterator) is not Object');
- }
- if (!IsCallable(completion) && !(completion instanceof CompletionRecord)) {
- throw new $TypeError('Assertion failed: completion is not a thunk representing a Completion Record, nor a Completion Record instance');
- }
- var completionThunk = completion instanceof CompletionRecord ? function () { return completion['?'](); } : completion;
- var iteratorReturn = GetMethod(iterator, 'return');
- if (typeof iteratorReturn === 'undefined') {
- return completionThunk();
- }
- var completionRecord;
- try {
- var innerResult = Call(iteratorReturn, iterator, []);
- } catch (e) {
-
-
- completionThunk();
- completionThunk = null;
-
- throw e;
- }
- completionRecord = completionThunk();
- completionThunk = null;
- if (Type(innerResult) !== 'Object') {
- throw new $TypeError('iterator .return must return an object');
- }
- return completionRecord;
- };
|