source: frontend/node_modules/es-abstract/2017/IteratorClose.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.7 KB
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4var isObject = require('es-object-atoms/isObject');
5
6var Call = require('./Call');
7var CompletionRecord = require('./CompletionRecord');
8var GetMethod = require('./GetMethod');
9var IsCallable = require('./IsCallable');
10
11// https://262.ecma-international.org/6.0/#sec-iteratorclose
12
13module.exports = function IteratorClose(iterator, completion) {
14 if (!isObject(iterator)) {
15 throw new $TypeError('Assertion failed: Type(iterator) is not Object');
16 }
17 if (!IsCallable(completion) && !(completion instanceof CompletionRecord)) {
18 throw new $TypeError('Assertion failed: completion is not a thunk representing a Completion Record, nor a Completion Record instance');
19 }
20 var completionThunk = completion instanceof CompletionRecord ? function () { return completion['?'](); } : completion;
21
22 var iteratorReturn = GetMethod(iterator, 'return');
23
24 if (typeof iteratorReturn === 'undefined') {
25 return completionThunk();
26 }
27
28 var completionRecord;
29 try {
30 var innerResult = Call(iteratorReturn, iterator, []);
31 } catch (e) {
32 // if we hit here, then "e" is the innerResult completion that needs re-throwing
33
34 // if the completion is of type "throw", this will throw.
35 completionThunk();
36 // eslint-disable-next-line no-useless-assignment
37 completionThunk = null; // ensure it's not called twice.
38
39 // if not, then return the innerResult completion
40 throw e;
41 }
42 completionRecord = completionThunk(); // if innerResult worked, then throw if the completion does
43 // eslint-disable-next-line no-useless-assignment
44 completionThunk = null; // ensure it's not called twice.
45
46 if (!isObject(innerResult)) {
47 throw new $TypeError('iterator .return must return an object');
48 }
49
50 return completionRecord;
51};
Note: See TracBrowser for help on using the repository browser.