source: imaps-frontend/node_modules/es-abstract/2020/AsyncIteratorClose.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[d565449]1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $SyntaxError = require('es-errors/syntax');
6var $TypeError = require('es-errors/type');
7var $Promise = GetIntrinsic('%Promise%', true);
8
9var Call = require('./Call');
10var CompletionRecord = require('./CompletionRecord');
11var GetMethod = require('./GetMethod');
12var Type = require('./Type');
13
14var isIteratorRecord = require('../helpers/records/iterator-record');
15
16var callBound = require('call-bind/callBound');
17
18var $then = callBound('Promise.prototype.then', true);
19
20// https://262.ecma-international.org/9.0/#sec-asynciteratorclose
21
22module.exports = function AsyncIteratorClose(iteratorRecord, completion) {
23 if (!isIteratorRecord(iteratorRecord)) {
24 throw new $TypeError('Assertion failed: `iteratorRecord` must be an Iterator Record'); // step 1
25 }
26
27 if (!(completion instanceof CompletionRecord)) {
28 throw new $TypeError('Assertion failed: completion is not a Completion Record instance'); // step 2
29 }
30
31 if (!$then) {
32 throw new $SyntaxError('This environment does not support Promises.');
33 }
34
35 var iterator = iteratorRecord['[[Iterator]]']; // step 3
36
37 return new $Promise(function (resolve) {
38 var ret = GetMethod(iterator, 'return'); // step 4
39
40 if (typeof ret === 'undefined') {
41 resolve(completion); // step 5
42 } else {
43 resolve($then(
44 new $Promise(function (resolve2) {
45 // process.exit(42);
46 resolve2(Call(ret, iterator, [])); // step 6
47 }),
48 function (innerResult) {
49 if (Type(innerResult) !== 'Object') {
50 throw new $TypeError('`innerResult` must be an Object'); // step 10
51 }
52 return completion;
53 },
54 function (e) {
55 if (completion.type() === 'throw') {
56 completion['?'](); // step 8
57 } else {
58 throw e; // step 9
59 }
60 }
61 ));
62 }
63 });
64};
Note: See TracBrowser for help on using the repository browser.