[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var GetIntrinsic = require('get-intrinsic');
|
---|
| 4 |
|
---|
| 5 | var $SyntaxError = require('es-errors/syntax');
|
---|
| 6 | var $TypeError = require('es-errors/type');
|
---|
| 7 | var $Promise = GetIntrinsic('%Promise%', true);
|
---|
| 8 |
|
---|
| 9 | var callBound = require('call-bind/callBound');
|
---|
| 10 |
|
---|
| 11 | var CreateIterResultObject = require('./CreateIterResultObject');
|
---|
| 12 | var IteratorComplete = require('./IteratorComplete');
|
---|
| 13 | var IteratorValue = require('./IteratorValue');
|
---|
| 14 | var PromiseResolve = require('./PromiseResolve');
|
---|
| 15 | var Type = require('./Type');
|
---|
| 16 |
|
---|
| 17 | var $then = callBound('Promise.prototype.then', true);
|
---|
| 18 |
|
---|
| 19 | // https://262.ecma-international.org/10.0/#sec-asyncfromsynciteratorcontinuation
|
---|
| 20 |
|
---|
| 21 | module.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 | };
|
---|