source: imaps-frontend/node_modules/es-abstract/2021/AsyncFromSyncIteratorContinuation.js

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.5 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 callBound = require('call-bind/callBound');
10
11var CreateIterResultObject = require('./CreateIterResultObject');
12var IteratorComplete = require('./IteratorComplete');
13var IteratorValue = require('./IteratorValue');
14var PromiseResolve = require('./PromiseResolve');
15var Type = require('./Type');
16
17var $then = callBound('Promise.prototype.then', true);
18
19// https://262.ecma-international.org/10.0/#sec-asyncfromsynciteratorcontinuation
20
21module.exports = function AsyncFromSyncIteratorContinuation(result) {
22 if (Type(result) !== 'Object') {
23 throw new $TypeError('Assertion failed: Type(O) is not Object');
24 }
25
26 if (arguments.length > 1) {
27 throw new $SyntaxError('although AsyncFromSyncIteratorContinuation should take a second argument, it is not used in this implementation');
28 }
29
30 if (!$Promise) {
31 throw new $SyntaxError('This environment does not support Promises.');
32 }
33
34 return new $Promise(function (resolve) {
35 var done = IteratorComplete(result); // step 2
36 var value = IteratorValue(result); // step 4
37 var valueWrapper = PromiseResolve($Promise, value); // step 6
38
39 // eslint-disable-next-line no-shadow
40 var onFulfilled = function (value) { // steps 8-9
41 return CreateIterResultObject(value, done); // step 8.a
42 };
43 resolve($then(valueWrapper, onFulfilled)); // step 11
44 }); // step 12
45};
Note: See TracBrowser for help on using the repository browser.